Merged in 1.16 (pull request #2)

1.16

Approved-by: Requios
This commit is contained in:
grimm auld
2021-02-02 20:28:16 +00:00
committed by Requios
81 changed files with 7560 additions and 7318 deletions

1
.gitignore vendored
View File

@@ -20,6 +20,7 @@ build
# other
eclipse
run
logs/*
# Files from Forge MDK
forge*changelog.txt

View File

@@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
version = '1.15.2-2.21'
version = '1.16.3-2.21'
group = 'nl.requios.effortlessbuilding' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'effortlessbuilding'
@@ -25,7 +25,8 @@ minecraft {
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: '20200514-1.15.1'
mappings channel: 'snapshot', version: '20201028-1.16.3'
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
@@ -89,7 +90,7 @@ dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.15.2-31.2.0'
minecraft 'net.minecraftforge:forge:1.16.3-34.0.9'
// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"

View File

@@ -10,10 +10,8 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
@@ -42,35 +40,27 @@ import org.apache.logging.log4j.Logger;
// The value here should match an entry in the META-INF/mods.toml file
@Mod(EffortlessBuilding.MODID)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class EffortlessBuilding
{
public class EffortlessBuilding {
public static final String MODID = "effortlessbuilding";
public static final String NAME = "Effortless Building";
public static final String VERSION = "1.15.2-2.21";
public static EffortlessBuilding instance;
public static final Logger logger = LogManager.getLogger();
public static IProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new);
public static final ItemRandomizerBag ITEM_RANDOMIZER_BAG = new ItemRandomizerBag();
public static final ItemReachUpgrade1 ITEM_REACH_UPGRADE_1 = new ItemReachUpgrade1();
public static final ItemReachUpgrade2 ITEM_REACH_UPGRADE_2 = new ItemReachUpgrade2();
public static final ItemReachUpgrade3 ITEM_REACH_UPGRADE_3 = new ItemReachUpgrade3();
public static final Block[] BLOCKS = {
};
public static final Item[] ITEMS = {
ITEM_RANDOMIZER_BAG,
ITEM_REACH_UPGRADE_1,
ITEM_REACH_UPGRADE_2,
ITEM_REACH_UPGRADE_3
};
public static final ContainerType<RandomizerBagContainer> RANDOMIZER_BAG_CONTAINER = register("randomizer_bag", RandomizerBagContainer::new);
public static final ResourceLocation RANDOMIZER_BAG_GUI = new ResourceLocation(EffortlessBuilding.MODID, "randomizer_bag");
public static EffortlessBuilding instance;
public static IProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new);
public EffortlessBuilding() {
instance = this;
@@ -91,9 +81,29 @@ public class EffortlessBuilding
MinecraftForge.EVENT_BUS.register(this);
}
private static <T extends Container> ContainerType<T> register(String key, ContainerType.IFactory<T> factory) {
return Registry.register(Registry.MENU, key, new ContainerType<>(factory));
}
public static void log(String msg) {
logger.info(msg);
}
public static void log(PlayerEntity player, String msg) {
log(player, msg, false);
}
public static void log(PlayerEntity player, String msg, boolean actionBar) {
player.sendStatusMessage(new StringTextComponent(msg), actionBar);
}
//Log with translation supported, call either on client or server (which then sends a message)
public static void logTranslate(PlayerEntity player, String prefix, String translationKey, String suffix, boolean actionBar) {
proxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
}
@SubscribeEvent
public void setup(final FMLCommonSetupEvent event)
{
public void setup(final FMLCommonSetupEvent event) {
CapabilityManager.INSTANCE.register(ModifierCapabilityManager.IModifierCapability.class, new ModifierCapabilityManager.Storage(), ModifierCapabilityManager.ModifierCapability::new);
CapabilityManager.INSTANCE.register(ModeCapabilityManager.IModeCapability.class, new ModeCapabilityManager.Storage(), ModeCapabilityManager.ModeCapability::new);
@@ -131,27 +141,6 @@ public class EffortlessBuilding
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
CommandReach.register(event.getCommandDispatcher());
}
private static <T extends Container> ContainerType<T> register(String key, ContainerType.IFactory<T> factory) {
return Registry.register(Registry.MENU, key, new ContainerType<>(factory));
}
public static void log(String msg){
logger.info(msg);
}
public static void log(PlayerEntity player, String msg){
log(player, msg, false);
}
public static void log(PlayerEntity player, String msg, boolean actionBar){
player.sendStatusMessage(new StringTextComponent(msg), actionBar);
}
//Log with translation supported, call either on client or server (which then sends a message)
public static void logTranslate(PlayerEntity player, String prefix, String translationKey, String suffix, boolean actionBar){
proxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
CommandReach.register(event.getServer().getCommandManager().getDispatcher());
}
}

View File

@@ -8,7 +8,6 @@ import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.BlockEvent;
@@ -32,8 +31,7 @@ import nl.requios.effortlessbuilding.network.RequestLookAtMessage;
import java.util.List;
@Mod.EventBusSubscriber
public class EventHandler
{
public class EventHandler {
@SubscribeEvent
public static void attachCapabilities(AttachCapabilitiesEvent<Entity> event) {

View File

@@ -23,15 +23,13 @@ public class ModClientEventHandler {
public static void onTextureStitch(final TextureStitchEvent.Pre event) {
EffortlessBuilding.log("Stitching textures");
//register icon textures
for (final BuildModes.BuildModeEnum mode : BuildModes.BuildModeEnum.values())
{
for (final BuildModes.BuildModeEnum mode : BuildModes.BuildModeEnum.values()) {
final ResourceLocation spriteLocation = new ResourceLocation(EffortlessBuilding.MODID, "icons/" + mode.name().toLowerCase());
event.addSprite(spriteLocation);
buildModeIcons.put(mode, spriteLocation);
}
for (final ModeOptions.ActionEnum action : ModeOptions.ActionEnum.values())
{
for (final ModeOptions.ActionEnum action : ModeOptions.ActionEnum.values()) {
final ResourceLocation spriteLocation = new ResourceLocation(EffortlessBuilding.MODID, "icons/" + action.name().toLowerCase());
event.addSprite(spriteLocation);
modeOptionIcons.put(action, spriteLocation);

View File

@@ -1,20 +1,11 @@
package nl.requios.effortlessbuilding;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import nl.requios.effortlessbuilding.buildmode.BuildModes;
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
import java.util.HashMap;
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@@ -30,8 +21,7 @@ public class ModEventHandler {
public static void registerItems(RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(EffortlessBuilding.ITEMS);
for (Block block : EffortlessBuilding.BLOCKS)
{
for (Block block : EffortlessBuilding.BLOCKS) {
event.getRegistry().register(new BlockItem(block, new Item.Properties()).setRegistryName(block.getRegistryName()));
}
}

View File

@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.buildmode;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import java.util.Dictionary;
import java.util.Hashtable;
@@ -16,7 +16,7 @@ public abstract class BaseBuildMode implements IBuildMode {
protected Dictionary<UUID, Integer> rightClickServerTable = new Hashtable<>();
protected Dictionary<UUID, BlockPos> firstPosTable = new Hashtable<>();
protected Dictionary<UUID, Direction> sideHitTable = new Hashtable<>();
protected Dictionary<UUID, Vec3d> hitVecTable = new Hashtable<>();
protected Dictionary<UUID, Vector3d> hitVecTable = new Hashtable<>();
@Override
public void initialize(PlayerEntity player) {
@@ -24,7 +24,7 @@ public abstract class BaseBuildMode implements IBuildMode {
rightClickServerTable.put(player.getUniqueID(), 0);
firstPosTable.put(player.getUniqueID(), BlockPos.ZERO);
sideHitTable.put(player.getUniqueID(), Direction.UP);
hitVecTable.put(player.getUniqueID(), Vec3d.ZERO);
hitVecTable.put(player.getUniqueID(), Vector3d.ZERO);
}
@Override
@@ -33,7 +33,7 @@ public abstract class BaseBuildMode implements IBuildMode {
}
@Override
public Vec3d getHitVec(PlayerEntity player) {
public Vector3d getHitVec(PlayerEntity player) {
return hitVecTable.get(player.getUniqueID());
}
}

View File

@@ -5,7 +5,7 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.buildmode.buildmodes.*;
import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
@@ -20,7 +20,7 @@ import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import static nl.requios.effortlessbuilding.buildmode.ModeOptions.*;
import static nl.requios.effortlessbuilding.buildmode.ModeOptions.OptionEnum;
public class BuildModes {
@@ -29,31 +29,6 @@ public class BuildModes {
public static Dictionary<PlayerEntity, Boolean> currentlyBreakingClient = new Hashtable<>();
public static Dictionary<PlayerEntity, Boolean> currentlyBreakingServer = new Hashtable<>();
public enum BuildModeEnum {
NORMAL("effortlessbuilding.mode.normal", new Normal()),
NORMAL_PLUS("effortlessbuilding.mode.normal_plus", new NormalPlus(), OptionEnum.BUILD_SPEED),
LINE("effortlessbuilding.mode.line", new Line() /*, OptionEnum.THICKNESS*/),
WALL("effortlessbuilding.mode.wall", new Wall(), OptionEnum.FILL),
FLOOR("effortlessbuilding.mode.floor", new Floor(), OptionEnum.FILL),
DIAGONAL_LINE("effortlessbuilding.mode.diagonal_line", new DiagonalLine() /*, OptionEnum.THICKNESS*/),
DIAGONAL_WALL("effortlessbuilding.mode.diagonal_wall", new DiagonalWall() /*, OptionEnum.FILL*/),
SLOPE_FLOOR("effortlessbuilding.mode.slope_floor", new SlopeFloor(), OptionEnum.RAISED_EDGE),
CIRCLE("effortlessbuilding.mode.circle", new Circle(), OptionEnum.CIRCLE_START, OptionEnum.FILL),
CYLINDER("effortlessbuilding.mode.cylinder", new Cylinder(), OptionEnum.CIRCLE_START, OptionEnum.FILL),
SPHERE("effortlessbuilding.mode.sphere", new Sphere(), OptionEnum.CIRCLE_START, OptionEnum.FILL),
CUBE("effortlessbuilding.mode.cube", new Cube(), OptionEnum.CUBE_FILL);
public String name;
public IBuildMode instance;
public OptionEnum[] options;
BuildModeEnum(String name, IBuildMode instance, OptionEnum... options) {
this.name = name;
this.instance = instance;
this.options = options;
}
}
//Uses a network message to get the previous raytraceresult from the player
//The server could keep track of all raytraceresults but this might lag with many players
//Raytraceresult is needed for sideHit and hitVec
@@ -115,7 +90,7 @@ public class BuildModes {
Direction sideHit = buildMode.instance.getSideHit(player);
if (sideHit == null) sideHit = message.getSideHit();
Vec3d hitVec = buildMode.instance.getHitVec(player);
Vector3d hitVec = buildMode.instance.getHitVec(player);
if (hitVec == null) hitVec = message.getHitVec();
BuildModifiers.onBlockPlaced(player, coordinates, sideHit, hitVec, message.getPlaceStartPos());
@@ -153,7 +128,7 @@ public class BuildModes {
//Get coordinates
BuildModeEnum buildMode = modeSettings.getBuildMode();
List<BlockPos> coordinates = buildMode.instance.onRightClick(player, startPos, Direction.UP, Vec3d.ZERO, true);
List<BlockPos> coordinates = buildMode.instance.onRightClick(player, startPos, Direction.UP, Vector3d.ZERO, true);
if (coordinates.isEmpty()) {
currentlyBreaking.put(player, true);
@@ -201,37 +176,37 @@ public class BuildModes {
return currentlyBreaking.get(player) != null;
}
//-- Common build mode functionality --//
//Find coordinates on a line bound by a plane
public static Vec3d findXBound(double x, Vec3d start, Vec3d look) {
public static Vector3d findXBound(double x, Vector3d start, Vector3d look) {
//then y and z are
double y = (x - start.x) / look.x * look.y + start.y;
double z = (x - start.x) / look.x * look.z + start.z;
return new Vec3d(x, y, z);
return new Vector3d(x, y, z);
}
public static Vec3d findYBound(double y, Vec3d start, Vec3d look) {
//-- Common build mode functionality --//
public static Vector3d findYBound(double y, Vector3d start, Vector3d look) {
//then x and z are
double x = (y - start.y) / look.y * look.x + start.x;
double z = (y - start.y) / look.y * look.z + start.z;
return new Vec3d(x, y, z);
return new Vector3d(x, y, z);
}
public static Vec3d findZBound(double z, Vec3d start, Vec3d look) {
public static Vector3d findZBound(double z, Vector3d start, Vector3d look) {
//then x and y are
double x = (z - start.z) / look.z * look.x + start.x;
double y = (z - start.z) / look.z * look.y + start.y;
return new Vec3d(x, y, z);
return new Vector3d(x, y, z);
}
//Use this instead of player.getLookVec() in any buildmodes code
public static Vec3d getPlayerLookVec(PlayerEntity player){
Vec3d lookVec = player.getLookVec();
public static Vector3d getPlayerLookVec(PlayerEntity player) {
Vector3d lookVec = player.getLookVec();
double x = lookVec.x;
double y = lookVec.y;
double z = lookVec.z;
@@ -251,10 +226,10 @@ public class BuildModes {
if (Math.abs(z - 1.0) < 0.0001) z = 0.9999;
if (Math.abs(z + 1.0) < 0.0001) z = -0.9999;
return new Vec3d(x, y, z);
return new Vector3d(x, y, z);
}
public static boolean isCriteriaValid(Vec3d start, Vec3d look, int reach, PlayerEntity player, boolean skipRaytrace, Vec3d lineBound, Vec3d planeBound, double distToPlayerSq) {
public static boolean isCriteriaValid(Vector3d start, Vector3d look, int reach, PlayerEntity player, boolean skipRaytrace, Vector3d lineBound, Vector3d planeBound, double distToPlayerSq) {
boolean intersects = false;
if (!skipRaytrace) {
//collision within a 1 block radius to selected is fine
@@ -268,4 +243,29 @@ public class BuildModes {
distToPlayerSq > 2 && distToPlayerSq < reach * reach &&
!intersects;
}
public enum BuildModeEnum {
NORMAL("effortlessbuilding.mode.normal", new Normal()),
NORMAL_PLUS("effortlessbuilding.mode.normal_plus", new NormalPlus(), OptionEnum.BUILD_SPEED),
LINE("effortlessbuilding.mode.line", new Line() /*, OptionEnum.THICKNESS*/),
WALL("effortlessbuilding.mode.wall", new Wall(), OptionEnum.FILL),
FLOOR("effortlessbuilding.mode.floor", new Floor(), OptionEnum.FILL),
DIAGONAL_LINE("effortlessbuilding.mode.diagonal_line", new DiagonalLine() /*, OptionEnum.THICKNESS*/),
DIAGONAL_WALL("effortlessbuilding.mode.diagonal_wall", new DiagonalWall() /*, OptionEnum.FILL*/),
SLOPE_FLOOR("effortlessbuilding.mode.slope_floor", new SlopeFloor(), OptionEnum.RAISED_EDGE),
CIRCLE("effortlessbuilding.mode.circle", new Circle(), OptionEnum.CIRCLE_START, OptionEnum.FILL),
CYLINDER("effortlessbuilding.mode.cylinder", new Cylinder(), OptionEnum.CIRCLE_START, OptionEnum.FILL),
SPHERE("effortlessbuilding.mode.sphere", new Sphere(), OptionEnum.CIRCLE_START, OptionEnum.FILL),
CUBE("effortlessbuilding.mode.cube", new Cube(), OptionEnum.CUBE_FILL);
public String name;
public IBuildMode instance;
public OptionEnum[] options;
BuildModeEnum(String name, IBuildMode instance, OptionEnum... options) {
this.name = name;
this.instance = instance;
this.options = options;
}
}
}

View File

@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.buildmode;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import java.util.List;
@@ -14,12 +14,12 @@ public interface IBuildMode {
//Fired when a block would be placed
//Return a list of coordinates where you want to place blocks
List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vec3d hitVec, boolean skipRaytrace);
List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vector3d hitVec, boolean skipRaytrace);
//Fired continuously for visualization purposes
List<BlockPos> findCoordinates(PlayerEntity player, BlockPos blockPos, boolean skipRaytrace);
Direction getSideHit(PlayerEntity player);
Vec3d getHitVec(PlayerEntity player);
Vector3d getHitVec(PlayerEntity player);
}

View File

@@ -9,57 +9,6 @@ import nl.requios.effortlessbuilding.proxy.ClientProxy;
public class ModeOptions {
public enum ActionEnum {
UNDO("effortlessbuilding.action.undo"),
REDO("effortlessbuilding.action.redo"),
REPLACE("effortlessbuilding.action.replace"),
OPEN_MODIFIER_SETTINGS("effortlessbuilding.action.open_modifier_settings"),
OPEN_PLAYER_SETTINGS("effortlessbuilding.action.open_player_settings"),
NORMAL_SPEED("effortlessbuilding.action.normal_speed"),
FAST_SPEED("effortlessbuilding.action.fast_speed"),
FULL("effortlessbuilding.action.full"),
HOLLOW("effortlessbuilding.action.hollow"),
CUBE_FULL("effortlessbuilding.action.full"),
CUBE_HOLLOW("effortlessbuilding.action.hollow"),
CUBE_SKELETON("effortlessbuilding.action.skeleton"),
SHORT_EDGE("effortlessbuilding.action.short_edge"),
LONG_EDGE("effortlessbuilding.action.long_edge"),
THICKNESS_1("effortlessbuilding.action.thickness_1"),
THICKNESS_3("effortlessbuilding.action.thickness_3"),
THICKNESS_5("effortlessbuilding.action.thickness_5"),
CIRCLE_START_CORNER("effortlessbuilding.action.start_corner"),
CIRCLE_START_CENTER("effortlessbuilding.action.start_center");
public String name;
ActionEnum(String name) {
this.name = name;
}
}
public enum OptionEnum {
BUILD_SPEED("effortlessbuilding.action.build_speed", ActionEnum.NORMAL_SPEED, ActionEnum.FAST_SPEED),
FILL("effortlessbuilding.action.filling", ActionEnum.FULL, ActionEnum.HOLLOW),
CUBE_FILL("effortlessbuilding.action.filling", ActionEnum.CUBE_FULL, ActionEnum.CUBE_HOLLOW, ActionEnum.CUBE_SKELETON),
RAISED_EDGE("effortlessbuilding.action.raised_edge", ActionEnum.SHORT_EDGE, ActionEnum.LONG_EDGE),
LINE_THICKNESS("effortlessbuilding.action.thickness", ActionEnum.THICKNESS_1, ActionEnum.THICKNESS_3, ActionEnum.THICKNESS_5),
CIRCLE_START("effortlessbuilding.action.circle_start", ActionEnum.CIRCLE_START_CORNER, ActionEnum.CIRCLE_START_CENTER);
public String name;
public ActionEnum[] actions;
OptionEnum(String name, ActionEnum... actions){
this.name = name;
this.actions = actions;
}
}
private static ActionEnum buildSpeed = ActionEnum.NORMAL_SPEED;
private static ActionEnum fill = ActionEnum.FULL;
private static ActionEnum cubeFill = ActionEnum.CUBE_FULL;
@@ -188,4 +137,55 @@ public class ModeOptions {
EffortlessBuilding.logTranslate(player, "", action.name, "", true);
}
}
public enum ActionEnum {
UNDO("effortlessbuilding.action.undo"),
REDO("effortlessbuilding.action.redo"),
REPLACE("effortlessbuilding.action.replace"),
OPEN_MODIFIER_SETTINGS("effortlessbuilding.action.open_modifier_settings"),
OPEN_PLAYER_SETTINGS("effortlessbuilding.action.open_player_settings"),
NORMAL_SPEED("effortlessbuilding.action.normal_speed"),
FAST_SPEED("effortlessbuilding.action.fast_speed"),
FULL("effortlessbuilding.action.full"),
HOLLOW("effortlessbuilding.action.hollow"),
CUBE_FULL("effortlessbuilding.action.full"),
CUBE_HOLLOW("effortlessbuilding.action.hollow"),
CUBE_SKELETON("effortlessbuilding.action.skeleton"),
SHORT_EDGE("effortlessbuilding.action.short_edge"),
LONG_EDGE("effortlessbuilding.action.long_edge"),
THICKNESS_1("effortlessbuilding.action.thickness_1"),
THICKNESS_3("effortlessbuilding.action.thickness_3"),
THICKNESS_5("effortlessbuilding.action.thickness_5"),
CIRCLE_START_CORNER("effortlessbuilding.action.start_corner"),
CIRCLE_START_CENTER("effortlessbuilding.action.start_center");
public String name;
ActionEnum(String name) {
this.name = name;
}
}
public enum OptionEnum {
BUILD_SPEED("effortlessbuilding.action.build_speed", ActionEnum.NORMAL_SPEED, ActionEnum.FAST_SPEED),
FILL("effortlessbuilding.action.filling", ActionEnum.FULL, ActionEnum.HOLLOW),
CUBE_FILL("effortlessbuilding.action.filling", ActionEnum.CUBE_FULL, ActionEnum.CUBE_HOLLOW, ActionEnum.CUBE_SKELETON),
RAISED_EDGE("effortlessbuilding.action.raised_edge", ActionEnum.SHORT_EDGE, ActionEnum.LONG_EDGE),
LINE_THICKNESS("effortlessbuilding.action.thickness", ActionEnum.THICKNESS_1, ActionEnum.THICKNESS_3, ActionEnum.THICKNESS_5),
CIRCLE_START("effortlessbuilding.action.circle_start", ActionEnum.CIRCLE_START_CORNER, ActionEnum.CIRCLE_START_CENTER);
public String name;
public ActionEnum[] actions;
OptionEnum(String name, ActionEnum... actions) {
this.name = name;
this.actions = actions;
}
}
}

View File

@@ -65,6 +65,18 @@ public class ModeSettingsManager {
return error;
}
public static void handleNewPlayer(PlayerEntity player) {
//Makes sure player has mode settings (if it doesnt it will create it)
getModeSettings(player);
//Only on server
if (!player.world.isRemote) {
//Send to client
ModeSettingsMessage msg = new ModeSettingsMessage(getModeSettings(player));
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), msg);
}
}
public static class ModeSettings {
private BuildModes.BuildModeEnum buildMode = BuildModes.BuildModeEnum.NORMAL;
@@ -83,16 +95,4 @@ public class ModeSettingsManager {
this.buildMode = buildMode;
}
}
public static void handleNewPlayer(PlayerEntity player){
//Makes sure player has mode settings (if it doesnt it will create it)
getModeSettings(player);
//Only on server
if (!player.world.isRemote) {
//Send to client
ModeSettingsMessage msg = new ModeSettingsMessage(getModeSettings(player));
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), msg);
}
}
}

View File

@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.buildmode;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import java.util.*;
@@ -11,31 +11,48 @@ import java.util.*;
public abstract class ThreeClicksBuildMode extends BaseBuildMode {
protected Dictionary<UUID, BlockPos> secondPosTable = new Hashtable<>();
static class HeightCriteria {
Vec3d planeBound;
Vec3d lineBound;
double distToLineSq;
double distToPlayerSq;
//Finds height after floor has been chosen in buildmodes with 3 clicks
public static BlockPos findHeight(PlayerEntity player, BlockPos secondPos, boolean skipRaytrace) {
Vector3d look = BuildModes.getPlayerLookVec(player);
Vector3d start = new Vector3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
HeightCriteria(Vec3d planeBound, BlockPos secondPos, Vec3d start) {
this.planeBound = planeBound;
this.lineBound = toLongestLine(this.planeBound, secondPos);
this.distToLineSq = this.lineBound.subtract(this.planeBound).lengthSquared();
this.distToPlayerSq = this.planeBound.subtract(start).lengthSquared();
List<HeightCriteria> criteriaList = new ArrayList<>(3);
//X
Vector3d xBound = BuildModes.findXBound(secondPos.getX(), start, look);
criteriaList.add(new HeightCriteria(xBound, secondPos, start));
//Z
Vector3d zBound = BuildModes.findZBound(secondPos.getZ(), start, look);
criteriaList.add(new HeightCriteria(zBound, secondPos, start));
//Remove invalid criteria
int reach = ReachHelper.getPlacementReach(player) * 4; //4 times as much as normal placement reach
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
//If none are valid, return empty list of blocks
if (criteriaList.isEmpty()) return null;
//If only 1 is valid, choose that one
HeightCriteria selected = criteriaList.get(0);
//If multiple are valid, choose based on criteria
if (criteriaList.size() > 1) {
//Select the one that is closest (from wall position to its line counterpart)
for (int i = 1; i < criteriaList.size(); i++) {
HeightCriteria criteria = criteriaList.get(i);
if (criteria.distToLineSq < 2.0 && selected.distToLineSq < 2.0) {
//Both very close to line, choose closest to player
if (criteria.distToPlayerSq < selected.distToPlayerSq)
selected = criteria;
} else {
//Pick closest to line
if (criteria.distToLineSq < selected.distToLineSq)
selected = criteria;
}
//Make it from a plane into a line, on y axis only
private Vec3d toLongestLine(Vec3d boundVec, BlockPos secondPos) {
BlockPos bound = new BlockPos(boundVec);
return new Vec3d(secondPos.getX(), bound.getY(), secondPos.getZ());
}
//check if its not behind the player and its not too close and not too far
//also check if raytrace from player to block does not intersect blocks
public boolean isValid(Vec3d start, Vec3d look, int reach, PlayerEntity player, boolean skipRaytrace) {
return BuildModes.isCriteriaValid(start, look, reach, player, skipRaytrace, lineBound, planeBound, distToPlayerSq);
}
return new BlockPos(selected.lineBound);
}
@Override
@@ -45,7 +62,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
}
@Override
public List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vec3d hitVec, boolean skipRaytrace) {
public List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vector3d hitVec, boolean skipRaytrace) {
List<BlockPos> list = new ArrayList<>();
Dictionary<UUID, Integer> rightClickTable = player.world.isRemote ? rightClickClientTable : rightClickServerTable;
@@ -167,47 +184,30 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
//After first, second and third pos are known, we want all the blocks
protected abstract List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3);
//Finds height after floor has been chosen in buildmodes with 3 clicks
public static BlockPos findHeight(PlayerEntity player, BlockPos secondPos, boolean skipRaytrace) {
Vec3d look = BuildModes.getPlayerLookVec(player);
Vec3d start = new Vec3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
static class HeightCriteria {
Vector3d planeBound;
Vector3d lineBound;
double distToLineSq;
double distToPlayerSq;
List<HeightCriteria> criteriaList = new ArrayList<>(3);
HeightCriteria(Vector3d planeBound, BlockPos secondPos, Vector3d start) {
this.planeBound = planeBound;
this.lineBound = toLongestLine(this.planeBound, secondPos);
this.distToLineSq = this.lineBound.subtract(this.planeBound).lengthSquared();
this.distToPlayerSq = this.planeBound.subtract(start).lengthSquared();
}
//X
Vec3d xBound = BuildModes.findXBound(secondPos.getX(), start, look);
criteriaList.add(new HeightCriteria(xBound, secondPos, start));
//Make it from a plane into a line, on y axis only
private Vector3d toLongestLine(Vector3d boundVec, BlockPos secondPos) {
BlockPos bound = new BlockPos(boundVec);
return new Vector3d(secondPos.getX(), bound.getY(), secondPos.getZ());
}
//Z
Vec3d zBound = BuildModes.findZBound(secondPos.getZ(), start, look);
criteriaList.add(new HeightCriteria(zBound, secondPos, start));
//check if its not behind the player and its not too close and not too far
//also check if raytrace from player to block does not intersect blocks
public boolean isValid(Vector3d start, Vector3d look, int reach, PlayerEntity player, boolean skipRaytrace) {
//Remove invalid criteria
int reach = ReachHelper.getPlacementReach(player) * 4; //4 times as much as normal placement reach
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
//If none are valid, return empty list of blocks
if (criteriaList.isEmpty()) return null;
//If only 1 is valid, choose that one
HeightCriteria selected = criteriaList.get(0);
//If multiple are valid, choose based on criteria
if (criteriaList.size() > 1) {
//Select the one that is closest (from wall position to its line counterpart)
for (int i = 1; i < criteriaList.size(); i++) {
HeightCriteria criteria = criteriaList.get(i);
if (criteria.distToLineSq < 2.0 && selected.distToLineSq < 2.0) {
//Both very close to line, choose closest to player
if (criteria.distToPlayerSq < selected.distToPlayerSq)
selected = criteria;
} else {
//Pick closest to line
if (criteria.distToLineSq < selected.distToLineSq)
selected = criteria;
return BuildModes.isCriteriaValid(start, look, reach, player, skipRaytrace, lineBound, planeBound, distToPlayerSq);
}
}
}
return new BlockPos(selected.lineBound);
}
}

View File

@@ -3,8 +3,7 @@ package nl.requios.effortlessbuilding.buildmode;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import java.util.ArrayList;
@@ -15,7 +14,7 @@ import java.util.UUID;
public abstract class TwoClicksBuildMode extends BaseBuildMode {
@Override
public List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vec3d hitVec, boolean skipRaytrace) {
public List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vector3d hitVec, boolean skipRaytrace) {
List<BlockPos> list = new ArrayList<>();
Dictionary<UUID, Integer> rightClickTable = player.world.isRemote ? rightClickClientTable : rightClickServerTable;

View File

@@ -3,23 +3,14 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
public class Circle extends TwoClicksBuildMode {
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
protected List<BlockPos> getAllBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getCircleBlocks(player, x1, y1, z1, x2, y2, z2);
}
public static List<BlockPos> getCircleBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
List<BlockPos> list = new ArrayList<>();
@@ -85,4 +76,14 @@ public class Circle extends TwoClicksBuildMode {
float part2 = radiusZ * radiusZ * MathHelper.cos(theta) * MathHelper.cos(theta);
return radiusX * radiusZ / MathHelper.sqrt(part1 + part2);
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
protected List<BlockPos> getAllBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getCircleBlocks(player, x1, y1, z1, x2, y2, z2);
}
}

View File

@@ -5,30 +5,11 @@ import net.minecraft.util.math.BlockPos;
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
public class Cube extends ThreeClicksBuildMode {
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
protected BlockPos findThirdPos(PlayerEntity player, BlockPos firstPos, BlockPos secondPos, boolean skipRaytrace) {
return findHeight(player, secondPos, skipRaytrace);
}
@Override
protected List<BlockPos> getIntermediateBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getFloorBlocksUsingCubeFill(player, x1, y1, z1, x2, y2, z2);
}
@Override
protected List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getCubeBlocks(player, x1, y1, z1, x3, y3, z3);
}
public static List<BlockPos> getFloorBlocksUsingCubeFill(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
List<BlockPos> list = new ArrayList<>();
@@ -97,4 +78,24 @@ public class Cube extends ThreeClicksBuildMode {
Line.addZLineBlocks(list, z1, z2, x2, y1);
Line.addZLineBlocks(list, z1, z2, x2, y2);
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
protected BlockPos findThirdPos(PlayerEntity player, BlockPos firstPos, BlockPos secondPos, boolean skipRaytrace) {
return findHeight(player, secondPos, skipRaytrace);
}
@Override
protected List<BlockPos> getIntermediateBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getFloorBlocksUsingCubeFill(player, x1, y1, z1, x2, y2, z2);
}
@Override
protected List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getCubeBlocks(player, x1, y1, z1, x3, y3, z3);
}
}

View File

@@ -9,6 +9,25 @@ import java.util.List;
public class Cylinder extends ThreeClicksBuildMode {
public static List<BlockPos> getCylinderBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
List<BlockPos> list = new ArrayList<>();
//Get circle blocks (using CIRCLE_START and FILL options built-in)
List<BlockPos> circleBlocks = Circle.getCircleBlocks(player, x1, y1, z1, x2, y2, z2);
int lowest = Math.min(y1, y3);
int highest = Math.max(y1, y3);
//Copy circle on y axis
for (int y = lowest; y <= highest; y++) {
for (BlockPos blockPos : circleBlocks) {
list.add(new BlockPos(blockPos.getX(), y, blockPos.getZ()));
}
}
return list;
}
@Override
public BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
@@ -28,23 +47,4 @@ public class Cylinder extends ThreeClicksBuildMode {
public List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getCylinderBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3);
}
public static List<BlockPos> getCylinderBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
List<BlockPos> list = new ArrayList<>();
//Get circle blocks (using CIRCLE_START and FILL options built-in)
List<BlockPos> circleBlocks = Circle.getCircleBlocks(player, x1, y1, z1, x2, y2, z2);
int lowest = Math.min(y1, y3);
int highest = Math.max(y1, y3);
//Copy circle on y axis
for (int y = lowest; y <= highest; y++) {
for (BlockPos blockPos : circleBlocks) {
list.add(new BlockPos(blockPos.getX(), y, blockPos.getZ()));
}
}
return list;
}
}

View File

@@ -2,7 +2,7 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
import java.util.ArrayList;
@@ -10,6 +10,25 @@ import java.util.List;
public class DiagonalLine extends ThreeClicksBuildMode {
//Add diagonal line from first to second
public static List<BlockPos> getDiagonalLineBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, float sampleMultiplier) {
List<BlockPos> list = new ArrayList<>();
Vector3d first = new Vector3d(x1, y1, z1).add(0.5, 0.5, 0.5);
Vector3d second = new Vector3d(x2, y2, z2).add(0.5, 0.5, 0.5);
int iterations = (int) Math.ceil(first.distanceTo(second) * sampleMultiplier);
for (double t = 0; t <= 1.0; t += 1.0 / iterations) {
Vector3d lerp = first.add(second.subtract(first).scale(t));
BlockPos candidate = new BlockPos(lerp);
//Only add if not equal to the last in the list
if (list.isEmpty() || !list.get(list.size() - 1).equals(candidate))
list.add(candidate);
}
return list;
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
@@ -31,23 +50,4 @@ public class DiagonalLine extends ThreeClicksBuildMode {
//Add diagonal line from first to third
return getDiagonalLineBlocks(player, x1, y1, z1, x3, y3, z3, 10);
}
//Add diagonal line from first to second
public static List<BlockPos> getDiagonalLineBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, float sampleMultiplier) {
List<BlockPos> list = new ArrayList<>();
Vec3d first = new Vec3d(x1, y1, z1).add(0.5, 0.5, 0.5);
Vec3d second = new Vec3d(x2, y2, z2).add(0.5, 0.5, 0.5);
int iterations = (int) Math.ceil(first.distanceTo(second) * sampleMultiplier);
for (double t = 0; t <= 1.0; t += 1.0/iterations) {
Vec3d lerp = first.add(second.subtract(first).scale(t));
BlockPos candidate = new BlockPos(lerp);
//Only add if not equal to the last in the list
if (list.isEmpty() || !list.get(list.size() - 1).equals(candidate))
list.add(candidate);
}
return list;
}
}

View File

@@ -9,26 +9,6 @@ import java.util.List;
public class DiagonalWall extends ThreeClicksBuildMode {
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
protected BlockPos findThirdPos(PlayerEntity player, BlockPos firstPos, BlockPos secondPos, boolean skipRaytrace) {
return findHeight(player, secondPos, skipRaytrace);
}
@Override
protected List<BlockPos> getIntermediateBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return DiagonalLine.getDiagonalLineBlocks(player, x1, y1, z1, x2, y2, z2, 1);
}
@Override
protected List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getDiagonalWallBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3);
}
//Add diagonal wall from first to second
public static List<BlockPos> getDiagonalWallBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
List<BlockPos> list = new ArrayList<>();
@@ -48,4 +28,24 @@ public class DiagonalWall extends ThreeClicksBuildMode {
return list;
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
protected BlockPos findThirdPos(PlayerEntity player, BlockPos firstPos, BlockPos secondPos, boolean skipRaytrace) {
return findHeight(player, secondPos, skipRaytrace);
}
@Override
protected List<BlockPos> getIntermediateBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return DiagonalLine.getDiagonalLineBlocks(player, x1, y1, z1, x2, y2, z2, 1);
}
@Override
protected List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getDiagonalWallBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3);
}
}

View File

@@ -2,46 +2,25 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.buildmode.BuildModes;
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
public class Floor extends TwoClicksBuildMode {
static class Criteria {
Vec3d planeBound;
double distToPlayerSq;
Criteria(Vec3d planeBound, Vec3d start) {
this.planeBound = planeBound;
this.distToPlayerSq = this.planeBound.subtract(start).lengthSquared();
}
//check if its not behind the player and its not too close and not too far
//also check if raytrace from player to block does not intersect blocks
public boolean isValid(Vec3d start, Vec3d look, int reach, PlayerEntity player, boolean skipRaytrace) {
return BuildModes.isCriteriaValid(start, look, reach, player, skipRaytrace, planeBound, planeBound, distToPlayerSq);
}
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return findFloor(player, firstPos, skipRaytrace);
}
public static BlockPos findFloor(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
Vec3d look = BuildModes.getPlayerLookVec(player);
Vec3d start = new Vec3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
Vector3d look = BuildModes.getPlayerLookVec(player);
Vector3d start = new Vector3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
List<Criteria> criteriaList = new ArrayList<>(3);
//Y
Vec3d yBound = BuildModes.findYBound(firstPos.getY(), start, look);
Vector3d yBound = BuildModes.findYBound(firstPos.getY(), start, look);
criteriaList.add(new Criteria(yBound, start));
//Remove invalid criteria
@@ -57,11 +36,6 @@ public class Floor extends TwoClicksBuildMode {
return new BlockPos(selected.planeBound);
}
@Override
protected List<BlockPos> getAllBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getFloorBlocks(player, x1, y1, z1, x2, y2, z2);
}
public static List<BlockPos> getFloorBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
List<BlockPos> list = new ArrayList<>();
@@ -90,4 +64,31 @@ public class Floor extends TwoClicksBuildMode {
Line.addZLineBlocks(list, z1, z2, x1, y);
Line.addZLineBlocks(list, z1, z2, x2, y);
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return findFloor(player, firstPos, skipRaytrace);
}
@Override
protected List<BlockPos> getAllBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getFloorBlocks(player, x1, y1, z1, x2, y2, z2);
}
static class Criteria {
Vector3d planeBound;
double distToPlayerSq;
Criteria(Vector3d planeBound, Vector3d start) {
this.planeBound = planeBound;
this.distToPlayerSq = this.planeBound.subtract(start).lengthSquared();
}
//check if its not behind the player and its not too close and not too far
//also check if raytrace from player to block does not intersect blocks
public boolean isValid(Vector3d start, Vector3d look, int reach, PlayerEntity player, boolean skipRaytrace) {
return BuildModes.isCriteriaValid(start, look, reach, player, skipRaytrace, planeBound, planeBound, distToPlayerSq);
}
}
}

View File

@@ -2,8 +2,7 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.buildmode.BuildModes;
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
import nl.requios.effortlessbuilding.helper.ReachHelper;
@@ -13,69 +12,22 @@ import java.util.List;
public class Line extends TwoClicksBuildMode {
static class Criteria {
Vec3d planeBound;
Vec3d lineBound;
double distToLineSq;
double distToPlayerSq;
Criteria(Vec3d planeBound, BlockPos firstPos, Vec3d start) {
this.planeBound = planeBound;
this.lineBound = toLongestLine(this.planeBound, firstPos);
this.distToLineSq = this.lineBound.subtract(this.planeBound).lengthSquared();
this.distToPlayerSq = this.planeBound.subtract(start).lengthSquared();
}
//Make it from a plane into a line
//Select the axis that is longest
private Vec3d toLongestLine(Vec3d boundVec, BlockPos firstPos) {
BlockPos bound = new BlockPos(boundVec);
BlockPos firstToSecond = bound.subtract(firstPos);
firstToSecond = new BlockPos(Math.abs(firstToSecond.getX()), Math.abs(firstToSecond.getY()), Math.abs(firstToSecond.getZ()));
int longest = Math.max(firstToSecond.getX(), Math.max(firstToSecond.getY(), firstToSecond.getZ()));
if (longest == firstToSecond.getX()) {
return new Vec3d(bound.getX(), firstPos.getY(), firstPos.getZ());
}
if (longest == firstToSecond.getY()) {
return new Vec3d(firstPos.getX(), bound.getY(), firstPos.getZ());
}
if (longest == firstToSecond.getZ()) {
return new Vec3d(firstPos.getX(), firstPos.getY(), bound.getZ());
}
return null;
}
//check if its not behind the player and its not too close and not too far
//also check if raytrace from player to block does not intersect blocks
public boolean isValid(Vec3d start, Vec3d look, int reach, PlayerEntity player, boolean skipRaytrace) {
return BuildModes.isCriteriaValid(start, look, reach, player, skipRaytrace, lineBound, planeBound, distToPlayerSq);
}
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return findLine(player, firstPos, skipRaytrace);
}
public static BlockPos findLine(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
Vec3d look = BuildModes.getPlayerLookVec(player);
Vec3d start = new Vec3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
Vector3d look = BuildModes.getPlayerLookVec(player);
Vector3d start = new Vector3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
List<Criteria> criteriaList = new ArrayList<>(3);
//X
Vec3d xBound = BuildModes.findXBound(firstPos.getX(), start, look);
Vector3d xBound = BuildModes.findXBound(firstPos.getX(), start, look);
criteriaList.add(new Criteria(xBound, firstPos, start));
//Y
Vec3d yBound = BuildModes.findYBound(firstPos.getY(), start, look);
Vector3d yBound = BuildModes.findYBound(firstPos.getY(), start, look);
criteriaList.add(new Criteria(yBound, firstPos, start));
//Z
Vec3d zBound = BuildModes.findZBound(firstPos.getZ(), start, look);
Vector3d zBound = BuildModes.findZBound(firstPos.getZ(), start, look);
criteriaList.add(new Criteria(zBound, firstPos, start));
//Remove invalid criteria
@@ -109,11 +61,6 @@ public class Line extends TwoClicksBuildMode {
return new BlockPos(selected.lineBound);
}
@Override
protected List<BlockPos> getAllBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getLineBlocks(player, x1, y1, z1, x2, y2, z2);
}
public static List<BlockPos> getLineBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
List<BlockPos> list = new ArrayList<>();
@@ -145,4 +92,56 @@ public class Line extends TwoClicksBuildMode {
list.add(new BlockPos(x, y, z));
}
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return findLine(player, firstPos, skipRaytrace);
}
@Override
protected List<BlockPos> getAllBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getLineBlocks(player, x1, y1, z1, x2, y2, z2);
}
static class Criteria {
Vector3d planeBound;
Vector3d lineBound;
double distToLineSq;
double distToPlayerSq;
Criteria(Vector3d planeBound, BlockPos firstPos, Vector3d start) {
this.planeBound = planeBound;
this.lineBound = toLongestLine(this.planeBound, firstPos);
this.distToLineSq = this.lineBound.subtract(this.planeBound).lengthSquared();
this.distToPlayerSq = this.planeBound.subtract(start).lengthSquared();
}
//Make it from a plane into a line
//Select the axis that is longest
private Vector3d toLongestLine(Vector3d boundVec, BlockPos firstPos) {
BlockPos bound = new BlockPos(boundVec);
BlockPos firstToSecond = bound.subtract(firstPos);
firstToSecond = new BlockPos(Math.abs(firstToSecond.getX()), Math.abs(firstToSecond.getY()), Math.abs(firstToSecond.getZ()));
int longest = Math.max(firstToSecond.getX(), Math.max(firstToSecond.getY(), firstToSecond.getZ()));
if (longest == firstToSecond.getX()) {
return new Vector3d(bound.getX(), firstPos.getY(), firstPos.getZ());
}
if (longest == firstToSecond.getY()) {
return new Vector3d(firstPos.getX(), bound.getY(), firstPos.getZ());
}
if (longest == firstToSecond.getZ()) {
return new Vector3d(firstPos.getX(), firstPos.getY(), bound.getZ());
}
return null;
}
//check if its not behind the player and its not too close and not too far
//also check if raytrace from player to block does not intersect blocks
public boolean isValid(Vector3d start, Vector3d look, int reach, PlayerEntity player, boolean skipRaytrace) {
return BuildModes.isCriteriaValid(start, look, reach, player, skipRaytrace, lineBound, planeBound, distToPlayerSq);
}
}
}

View File

@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.buildmode.IBuildMode;
import java.util.ArrayList;
@@ -16,7 +16,7 @@ public class Normal implements IBuildMode {
}
@Override
public List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vec3d hitVec, boolean skipRaytrace) {
public List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vector3d hitVec, boolean skipRaytrace) {
List<BlockPos> list = new ArrayList<>();
if (blockPos != null) list.add(blockPos);
return list;
@@ -35,7 +35,7 @@ public class Normal implements IBuildMode {
}
@Override
public Vec3d getHitVec(PlayerEntity player) {
public Vector3d getHitVec(PlayerEntity player) {
return null;
}
}

View File

@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.buildmode.IBuildMode;
import java.util.ArrayList;
@@ -16,7 +16,7 @@ public class NormalPlus implements IBuildMode {
}
@Override
public List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vec3d hitVec, boolean skipRaytrace) {
public List<BlockPos> onRightClick(PlayerEntity player, BlockPos blockPos, Direction sideHit, Vector3d hitVec, boolean skipRaytrace) {
List<BlockPos> list = new ArrayList<>();
if (blockPos != null) list.add(blockPos);
return list;
@@ -35,7 +35,7 @@ public class NormalPlus implements IBuildMode {
}
@Override
public Vec3d getHitVec(PlayerEntity player) {
public Vector3d getHitVec(PlayerEntity player) {
return null;
}
}

View File

@@ -11,26 +11,6 @@ import java.util.List;
public class SlopeFloor extends ThreeClicksBuildMode {
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
protected BlockPos findThirdPos(PlayerEntity player, BlockPos firstPos, BlockPos secondPos, boolean skipRaytrace) {
return findHeight(player, secondPos, skipRaytrace);
}
@Override
protected List<BlockPos> getIntermediateBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return Floor.getFloorBlocks(player, x1, y1, z1, x2, y2, z2);
}
@Override
protected List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getSlopeFloorBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3);
}
//Add slope floor from first to second
public static List<BlockPos> getSlopeFloorBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
List<BlockPos> list = new ArrayList<>();
@@ -92,4 +72,24 @@ public class SlopeFloor extends ThreeClicksBuildMode {
return list;
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
protected BlockPos findThirdPos(PlayerEntity player, BlockPos firstPos, BlockPos secondPos, boolean skipRaytrace) {
return findHeight(player, secondPos, skipRaytrace);
}
@Override
protected List<BlockPos> getIntermediateBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return Floor.getFloorBlocks(player, x1, y1, z1, x2, y2, z2);
}
@Override
protected List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getSlopeFloorBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3);
}
}

View File

@@ -11,26 +11,6 @@ import java.util.List;
public class Sphere extends ThreeClicksBuildMode {
@Override
public BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
public BlockPos findThirdPos(PlayerEntity player, BlockPos firstPos, BlockPos secondPos, boolean skipRaytrace) {
return findHeight(player, secondPos, skipRaytrace);
}
@Override
public List<BlockPos> getIntermediateBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return Circle.getCircleBlocks(player, x1, y1, z1, x2, y2, z2);
}
@Override
public List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getSphereBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3);
}
public static List<BlockPos> getSphereBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
List<BlockPos> list = new ArrayList<>();
@@ -107,4 +87,24 @@ public class Sphere extends ThreeClicksBuildMode {
return Circle.calculateEllipseRadius(centerX, centerY, radiusXZ, radiusY, x, y);
}
@Override
public BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return Floor.findFloor(player, firstPos, skipRaytrace);
}
@Override
public BlockPos findThirdPos(PlayerEntity player, BlockPos firstPos, BlockPos secondPos, boolean skipRaytrace) {
return findHeight(player, secondPos, skipRaytrace);
}
@Override
public List<BlockPos> getIntermediateBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return Circle.getCircleBlocks(player, x1, y1, z1, x2, y2, z2);
}
@Override
public List<BlockPos> getFinalBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
return getSphereBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3);
}
}

View File

@@ -2,53 +2,29 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import nl.requios.effortlessbuilding.buildmode.BuildModes;
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
public class Wall extends TwoClicksBuildMode {
static class Criteria {
Vec3d planeBound;
double distToPlayerSq;
double angle;
Criteria(Vec3d planeBound, BlockPos firstPos, Vec3d start, Vec3d look) {
this.planeBound = planeBound;
this.distToPlayerSq = this.planeBound.subtract(start).lengthSquared();
Vec3d wall = this.planeBound.subtract(new Vec3d(firstPos));
this.angle = wall.x * look.x + wall.z * look.z; //dot product ignoring y (looking up/down should not affect this angle)
}
//check if its not behind the player and its not too close and not too far
//also check if raytrace from player to block does not intersect blocks
public boolean isValid(Vec3d start, Vec3d look, int reach, PlayerEntity player, boolean skipRaytrace) {
return BuildModes.isCriteriaValid(start, look, reach, player, skipRaytrace, planeBound, planeBound, distToPlayerSq);
}
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return findWall(player, firstPos, skipRaytrace);
}
public static BlockPos findWall(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
Vec3d look = BuildModes.getPlayerLookVec(player);
Vec3d start = new Vec3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
Vector3d look = BuildModes.getPlayerLookVec(player);
Vector3d start = new Vector3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
List<Criteria> criteriaList = new ArrayList<>(3);
//X
Vec3d xBound = BuildModes.findXBound(firstPos.getX(), start, look);
Vector3d xBound = BuildModes.findXBound(firstPos.getX(), start, look);
criteriaList.add(new Criteria(xBound, firstPos, start, look));
//Z
Vec3d zBound = BuildModes.findZBound(firstPos.getZ(), start, look);
Vector3d zBound = BuildModes.findZBound(firstPos.getZ(), start, look);
criteriaList.add(new Criteria(zBound, firstPos, start, look));
//Remove invalid criteria
@@ -75,11 +51,6 @@ public class Wall extends TwoClicksBuildMode {
return new BlockPos(selected.planeBound);
}
@Override
protected List<BlockPos> getAllBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getWallBlocks(player, x1, y1, z1, x2, y2, z2);
}
public static List<BlockPos> getWallBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
List<BlockPos> list = new ArrayList<>();
@@ -131,4 +102,34 @@ public class Wall extends TwoClicksBuildMode {
Line.addYLineBlocks(list, y1, y2, x1, z);
Line.addYLineBlocks(list, y1, y2, x2, z);
}
@Override
protected BlockPos findSecondPos(PlayerEntity player, BlockPos firstPos, boolean skipRaytrace) {
return findWall(player, firstPos, skipRaytrace);
}
@Override
protected List<BlockPos> getAllBlocks(PlayerEntity player, int x1, int y1, int z1, int x2, int y2, int z2) {
return getWallBlocks(player, x1, y1, z1, x2, y2, z2);
}
static class Criteria {
Vector3d planeBound;
double distToPlayerSq;
double angle;
Criteria(Vector3d planeBound, BlockPos firstPos, Vector3d start, Vector3d look) {
this.planeBound = planeBound;
this.distToPlayerSq = this.planeBound.subtract(start).lengthSquared();
Vector3d wall = this.planeBound.subtract(Vector3d.copy(firstPos));
this.angle = wall.x * look.x + wall.z * look.z; //dot product ignoring y (looking up/down should not affect this angle)
}
//check if its not behind the player and its not too close and not too far
//also check if raytrace from player to block does not intersect blocks
public boolean isValid(Vector3d start, Vector3d look, int reach, PlayerEntity player, boolean skipRaytrace) {
return BuildModes.isCriteriaValid(start, look, reach, player, skipRaytrace, planeBound, planeBound, distToPlayerSq);
}
}
}

View File

@@ -6,8 +6,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector3i;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
@@ -16,6 +16,64 @@ import java.util.List;
public class Array {
public static List<BlockPos> findCoordinates(PlayerEntity player, BlockPos startPos) {
List<BlockPos> coordinates = new ArrayList<>();
//find arraysettings for the player
ArraySettings a = ModifierSettingsManager.getModifierSettings(player).getArraySettings();
if (!isEnabled(a)) return coordinates;
BlockPos pos = startPos;
Vector3i offset = new Vector3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
for (int i = 0; i < a.count; i++) {
pos = pos.add(offset);
coordinates.add(pos);
}
return coordinates;
}
public static List<BlockState> findBlockStates(PlayerEntity player, BlockPos startPos, BlockState blockState, ItemStack itemStack, List<ItemStack> itemStacks) {
List<BlockState> blockStates = new ArrayList<>();
//find arraysettings for the player that placed the block
ArraySettings a = ModifierSettingsManager.getModifierSettings(player).getArraySettings();
if (!isEnabled(a)) return blockStates;
BlockPos pos = startPos;
Vector3i offset = new Vector3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
//Randomizer bag synergy
IItemHandler bagInventory = null;
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemRandomizerBag) {
bagInventory = ItemRandomizerBag.getBagInventory(itemStack);
}
for (int i = 0; i < a.count; i++) {
pos = pos.add(offset);
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
blockState = BuildModifiers
.getBlockStateFromItem(itemStack, player, startPos, Direction.UP, new Vector3d(0, 0, 0), Hand.MAIN_HAND);
}
//blockState = blockState.getBlock().getStateForPlacement(player.world, pos, )
blockStates.add(blockState);
itemStacks.add(itemStack);
}
return blockStates;
}
public static boolean isEnabled(ArraySettings a) {
if (a == null || !a.enabled) return false;
return a.offset.getX() != 0 || a.offset.getY() != 0 || a.offset.getZ() != 0;
}
public static class ArraySettings {
public boolean enabled = false;
public BlockPos offset = BlockPos.ZERO;
@@ -41,64 +99,4 @@ public class Array {
}
}
public static List<BlockPos> findCoordinates(PlayerEntity player, BlockPos startPos) {
List<BlockPos> coordinates = new ArrayList<>();
//find arraysettings for the player
ArraySettings a = ModifierSettingsManager.getModifierSettings(player).getArraySettings();
if (!isEnabled(a)) return coordinates;
BlockPos pos = startPos;
Vec3i offset = new Vec3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
for (int i = 0; i < a.count; i++) {
pos = pos.add(offset);
coordinates.add(pos);
}
return coordinates;
}
public static List<BlockState> findBlockStates(PlayerEntity player, BlockPos startPos, BlockState blockState, ItemStack itemStack, List<ItemStack> itemStacks) {
List<BlockState> blockStates = new ArrayList<>();
//find arraysettings for the player that placed the block
ArraySettings a = ModifierSettingsManager.getModifierSettings(player).getArraySettings();
if (!isEnabled(a)) return blockStates;
BlockPos pos = startPos;
Vec3i offset = new Vec3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
//Randomizer bag synergy
IItemHandler bagInventory = null;
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemRandomizerBag) {
bagInventory = ItemRandomizerBag.getBagInventory(itemStack);
}
for (int i = 0; i < a.count; i++) {
pos = pos.add(offset);
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
blockState = BuildModifiers
.getBlockStateFromItem(itemStack, player, startPos, Direction.UP, new Vec3d(0, 0, 0), Hand.MAIN_HAND);
}
//blockState = blockState.getBlock().getStateForPlacement(player.world, pos, )
blockStates.add(blockState);
itemStacks.add(itemStack);
}
return blockStates;
}
public static boolean isEnabled(ArraySettings a) {
if (a == null || !a.enabled) return false;
if (a.offset.getX() == 0 && a.offset.getY() == 0 && a.offset.getZ() == 0) return false;
return true;
}
}

View File

@@ -2,19 +2,19 @@ package nl.requios.effortlessbuilding.buildmodifier;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import java.util.List;
public class BlockSet {
private List<BlockPos> coordinates;
private List<BlockState> previousBlockStates;
private List<BlockState> newBlockStates;
private Vec3d hitVec;
private BlockPos firstPos;
private BlockPos secondPos;
private final List<BlockPos> coordinates;
private final List<BlockState> previousBlockStates;
private final List<BlockState> newBlockStates;
private final Vector3d hitVec;
private final BlockPos firstPos;
private final BlockPos secondPos;
public BlockSet(List<BlockPos> coordinates, List<BlockState> previousBlockStates, List<BlockState> newBlockStates, Vec3d hitVec,
public BlockSet(List<BlockPos> coordinates, List<BlockState> previousBlockStates, List<BlockState> newBlockStates, Vector3d hitVec,
BlockPos firstPos, BlockPos secondPos) {
this.coordinates = coordinates;
this.previousBlockStates = previousBlockStates;
@@ -36,7 +36,7 @@ public class BlockSet {
return newBlockStates;
}
public Vec3d getHitVec() {
public Vector3d getHitVec() {
return hitVec;
}

View File

@@ -2,8 +2,8 @@ package nl.requios.effortlessbuilding.buildmodifier;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
@@ -12,7 +12,7 @@ import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
import nl.requios.effortlessbuilding.helper.InventoryHelper;
@@ -20,17 +20,20 @@ import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.render.BlockPreviewRenderer;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class BuildModifiers {
//Called from BuildModes
public static void onBlockPlaced(PlayerEntity player, List<BlockPos> startCoordinates, Direction sideHit, Vec3d hitVec, boolean placeStartPos) {
public static void onBlockPlaced(PlayerEntity player, List<BlockPos> startCoordinates, Direction sideHit, Vector3d hitVec, boolean placeStartPos) {
World world = player.world;
ItemRandomizerBag.renewRandomness();
//Format hitvec to 0.x
hitVec = new Vec3d(Math.abs(hitVec.x - ((int) hitVec.x)), Math.abs(hitVec.y - ((int) hitVec.y)), Math.abs(hitVec.z - ((int) hitVec.z)));
hitVec = new Vector3d(Math.abs(hitVec.x - ((int) hitVec.x)), Math.abs(hitVec.y - ((int) hitVec.y)), Math.abs(hitVec.z - ((int) hitVec.z)));
//find coordinates and blockstates
List<BlockPos> coordinates = findCoordinates(player, startCoordinates);
@@ -143,7 +146,7 @@ public class BuildModifiers {
//add to undo stack
BlockPos firstPos = startCoordinates.get(0);
BlockPos secondPos = startCoordinates.get(startCoordinates.size() - 1);
Vec3d hitVec = new Vec3d(0.5, 0.5, 0.5);
Vector3d hitVec = new Vector3d(0.5, 0.5, 0.5);
UndoRedo.addUndo(player, new BlockSet(coordinates, previousBlockStates, newBlockStates, hitVec, firstPos, secondPos));
}
@@ -170,10 +173,10 @@ public class BuildModifiers {
}
public static List<BlockPos> findCoordinates(PlayerEntity player, BlockPos blockPos) {
return findCoordinates(player, new ArrayList<>(Arrays.asList(blockPos)));
return findCoordinates(player, new ArrayList<>(Collections.singletonList(blockPos)));
}
public static List<BlockState> findBlockStates(PlayerEntity player, List<BlockPos> posList, Vec3d hitVec, Direction facing, List<ItemStack> itemStacks) {
public static List<BlockState> findBlockStates(PlayerEntity player, List<BlockPos> posList, Vector3d hitVec, Direction facing, List<ItemStack> itemStacks) {
List<BlockState> blockStates = new ArrayList<>();
itemStacks.clear();
@@ -236,7 +239,7 @@ public class BuildModifiers {
modifierSettings.doQuickReplace();
}
public static BlockState getBlockStateFromItem(ItemStack itemStack, PlayerEntity player, BlockPos blockPos, Direction facing, Vec3d hitVec, Hand hand) {
public static BlockState getBlockStateFromItem(ItemStack itemStack, PlayerEntity player, BlockPos blockPos, Direction facing, Vector3d hitVec, Hand hand) {
return Block.getBlockFromItem(itemStack.getItem()).getStateForPlacement(new BlockItemUseContext(new ItemUseContext(player, hand, new BlockRayTraceResult(hitVec, facing, blockPos, false))));
}

View File

@@ -1,10 +1,6 @@
package nl.requios.effortlessbuilding.buildmodifier;
import net.minecraft.block.*;
import net.minecraft.block.StairsBlock;
import net.minecraft.block.DirectionalBlock;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.properties.Half;
@@ -12,7 +8,7 @@ import net.minecraft.state.properties.SlabType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
@@ -21,32 +17,6 @@ import java.util.List;
public class Mirror {
public static class MirrorSettings {
public boolean enabled = false;
public Vec3d position = new Vec3d(0.5, 64.5, 0.5);
public boolean mirrorX = true, mirrorY = false, mirrorZ = false;
public int radius = 10;
public boolean drawLines = true, drawPlanes = true;
public MirrorSettings() {
}
public MirrorSettings(boolean mirrorEnabled, Vec3d position, boolean mirrorX, boolean mirrorY, boolean mirrorZ, int radius, boolean drawLines, boolean drawPlanes) {
this.enabled = mirrorEnabled;
this.position = position;
this.mirrorX = mirrorX;
this.mirrorY = mirrorY;
this.mirrorZ = mirrorZ;
this.radius = radius;
this.drawLines = drawLines;
this.drawPlanes = drawPlanes;
}
public int getReach() {
return radius * 2; //Change ModifierSettings#setReachUpgrade too
}
}
public static List<BlockPos> findCoordinates(PlayerEntity player, BlockPos startPos) {
List<BlockPos> coordinates = new ArrayList<>();
@@ -100,9 +70,12 @@ public class Mirror {
bagInventory = ItemRandomizerBag.getBagInventory(itemStack);
}
if (m.mirrorX) blockStateMirrorX(player, m, startPos, blockState, bagInventory, itemStack, Hand.MAIN_HAND, blockStates, itemStacks);
if (m.mirrorY) blockStateMirrorY(player, m, startPos, blockState, bagInventory, itemStack, Hand.MAIN_HAND, blockStates, itemStacks);
if (m.mirrorZ) blockStateMirrorZ(player, m, startPos, blockState, bagInventory, itemStack, Hand.MAIN_HAND, blockStates, itemStacks);
if (m.mirrorX)
blockStateMirrorX(player, m, startPos, blockState, bagInventory, itemStack, Hand.MAIN_HAND, blockStates, itemStacks);
if (m.mirrorY)
blockStateMirrorY(player, m, startPos, blockState, bagInventory, itemStack, Hand.MAIN_HAND, blockStates, itemStacks);
if (m.mirrorZ)
blockStateMirrorZ(player, m, startPos, blockState, bagInventory, itemStack, Hand.MAIN_HAND, blockStates, itemStacks);
return blockStates;
}
@@ -116,7 +89,7 @@ public class Mirror {
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vec3d(0, 0, 0), hand);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vector3d(0, 0, 0), hand);
}
//Find blockstate
@@ -126,8 +99,10 @@ public class Mirror {
blockStates.add(newBlockState);
itemStacks.add(itemStack);
if (m.mirrorY) blockStateMirrorY(player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand, blockStates, itemStacks);
if (m.mirrorZ) blockStateMirrorZ(player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand, blockStates, itemStacks);
if (m.mirrorY)
blockStateMirrorY(player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand, blockStates, itemStacks);
if (m.mirrorZ)
blockStateMirrorZ(player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand, blockStates, itemStacks);
}
private static void blockStateMirrorY(PlayerEntity player, MirrorSettings m, BlockPos oldBlockPos, BlockState oldBlockState,
@@ -139,7 +114,7 @@ public class Mirror {
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vec3d(0, 0, 0), hand);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vector3d(0, 0, 0), hand);
}
//Find blockstate
@@ -149,7 +124,8 @@ public class Mirror {
blockStates.add(newBlockState);
itemStacks.add(itemStack);
if (m.mirrorZ) blockStateMirrorZ(player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand, blockStates, itemStacks);
if (m.mirrorZ)
blockStateMirrorZ(player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand, blockStates, itemStacks);
}
private static void blockStateMirrorZ(PlayerEntity player, MirrorSettings m, BlockPos oldBlockPos, BlockState oldBlockState,
@@ -161,7 +137,7 @@ public class Mirror {
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vec3d(0, 0, 0), hand);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vector3d(0, 0, 0), hand);
}
//Find blockstate
@@ -176,12 +152,9 @@ public class Mirror {
if (m == null || !m.enabled || (!m.mirrorX && !m.mirrorY && !m.mirrorZ)) return false;
//within mirror distance
if (startPos.getX() + 0.5 < m.position.x - m.radius || startPos.getX() + 0.5 > m.position.x + m.radius ||
startPos.getY() + 0.5 < m.position.y - m.radius || startPos.getY() + 0.5 > m.position.y + m.radius ||
startPos.getZ() + 0.5 < m.position.z - m.radius || startPos.getZ() + 0.5 > m.position.z + m.radius)
return false;
return true;
return !(startPos.getX() + 0.5 < m.position.x - m.radius) && !(startPos.getX() + 0.5 > m.position.x + m.radius) &&
!(startPos.getY() + 0.5 < m.position.y - m.radius) && !(startPos.getY() + 0.5 > m.position.y + m.radius) &&
!(startPos.getZ() + 0.5 < m.position.z - m.radius) && !(startPos.getZ() + 0.5 > m.position.z + m.radius);
}
private static BlockState getVerticalMirror(BlockState blockState) {
@@ -225,4 +198,30 @@ public class Mirror {
return blockState;
}
public static class MirrorSettings {
public boolean enabled = false;
public Vector3d position = new Vector3d(0.5, 64.5, 0.5);
public boolean mirrorX = true, mirrorY = false, mirrorZ = false;
public int radius = 10;
public boolean drawLines = true, drawPlanes = true;
public MirrorSettings() {
}
public MirrorSettings(boolean mirrorEnabled, Vector3d position, boolean mirrorX, boolean mirrorY, boolean mirrorZ, int radius, boolean drawLines, boolean drawPlanes) {
this.enabled = mirrorEnabled;
this.position = position;
this.mirrorX = mirrorX;
this.mirrorY = mirrorY;
this.mirrorZ = mirrorZ;
this.radius = radius;
this.drawLines = drawLines;
this.drawPlanes = drawPlanes;
}
public int getReach() {
return radius * 2; //Change ModifierSettings#setReachUpgrade too
}
}
}

View File

@@ -110,6 +110,18 @@ public class ModifierSettingsManager {
return error;
}
public static void handleNewPlayer(PlayerEntity player) {
//Makes sure player has modifier settings (if it doesnt it will create it)
getModifierSettings(player);
//Only on server
if (!player.world.isRemote) {
//Send to client
ModifierSettingsMessage msg = new ModifierSettingsMessage(getModifierSettings(player));
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), msg);
}
}
public static class ModifierSettings {
private Mirror.MirrorSettings mirrorSettings;
private Array.ArraySettings arraySettings;
@@ -179,10 +191,18 @@ public class ModifierSettingsManager {
//Set mirror radius to max
int reach = 10;
switch (reachUpgrade) {
case 0: reach = BuildConfig.reach.maxReachLevel0.get(); break;
case 1: reach = BuildConfig.reach.maxReachLevel1.get(); break;
case 2: reach = BuildConfig.reach.maxReachLevel2.get(); break;
case 3: reach = BuildConfig.reach.maxReachLevel3.get(); break;
case 0:
reach = BuildConfig.reach.maxReachLevel0.get();
break;
case 1:
reach = BuildConfig.reach.maxReachLevel1.get();
break;
case 2:
reach = BuildConfig.reach.maxReachLevel2.get();
break;
case 3:
reach = BuildConfig.reach.maxReachLevel3.get();
break;
}
if (this.mirrorSettings != null)
@@ -191,17 +211,5 @@ public class ModifierSettingsManager {
this.radialMirrorSettings.radius = reach / 2;
}
}
public static void handleNewPlayer(PlayerEntity player){
//Makes sure player has modifier settings (if it doesnt it will create it)
getModifierSettings(player);
//Only on server
if (!player.world.isRemote) {
//Send to client
ModifierSettingsMessage msg = new ModifierSettingsMessage(getModifierSettings(player));
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), msg);
}
}
}

View File

@@ -9,7 +9,7 @@ import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
@@ -18,32 +18,6 @@ import java.util.List;
public class RadialMirror {
public static class RadialMirrorSettings {
public boolean enabled = false;
public Vec3d position = new Vec3d(0.5, 64.5, 0.5);
public int slices = 4;
public boolean alternate = false;
public int radius = 20;
public boolean drawLines = true, drawPlanes = false;
public RadialMirrorSettings() {
}
public RadialMirrorSettings(boolean enabled, Vec3d position, int slices, boolean alternate, int radius, boolean drawLines, boolean drawPlanes) {
this.enabled = enabled;
this.position = position;
this.slices = slices;
this.alternate = alternate;
this.radius = radius;
this.drawLines = drawLines;
this.drawPlanes = drawPlanes;
}
public int getReach() {
return radius * 2;
}
}
public static List<BlockPos> findCoordinates(PlayerEntity player, BlockPos startPos) {
List<BlockPos> coordinates = new ArrayList<>();
@@ -54,8 +28,8 @@ public class RadialMirror {
//get angle between slices
double sliceAngle = 2 * Math.PI / r.slices;
Vec3d startVec = new Vec3d(startPos.getX() + 0.5f, startPos.getY() + 0.5f, startPos.getZ() + 0.5f);
Vec3d relStartVec = startVec.subtract(r.position);
Vector3d startVec = new Vector3d(startPos.getX() + 0.5f, startPos.getY() + 0.5f, startPos.getZ() + 0.5f);
Vector3d relStartVec = startVec.subtract(r.position);
double startAngleToCenter = MathHelper.atan2(relStartVec.x, relStartVec.z);
if (startAngleToCenter < 0) startAngleToCenter += Math.PI;
@@ -69,7 +43,7 @@ public class RadialMirror {
curAngle = curAngle - startAngleInSlice + (sliceAngle - startAngleInSlice);
}
Vec3d relNewVec = relStartVec.rotateYaw((float) curAngle);
Vector3d relNewVec = relStartVec.rotateYaw((float) curAngle);
BlockPos newBlockPos = new BlockPos(r.position.add(relNewVec));
if (!coordinates.contains(newBlockPos) && !newBlockPos.equals(startPos)) coordinates.add(newBlockPos);
}
@@ -89,8 +63,8 @@ public class RadialMirror {
//get angle between slices
double sliceAngle = 2 * Math.PI / r.slices;
Vec3d startVec = new Vec3d(startPos.getX() + 0.5f, startPos.getY() + 0.5f, startPos.getZ() + 0.5f);
Vec3d relStartVec = startVec.subtract(r.position);
Vector3d startVec = new Vector3d(startPos.getX() + 0.5f, startPos.getY() + 0.5f, startPos.getZ() + 0.5f);
Vector3d relStartVec = startVec.subtract(r.position);
double startAngleToCenter = MathHelper.atan2(relStartVec.x, relStartVec.z);
double startAngleToCenterMod = startAngleToCenter < 0 ? startAngleToCenter + Math.PI : startAngleToCenter;
@@ -115,7 +89,7 @@ public class RadialMirror {
curAngle = curAngle - startAngleInSlice + (sliceAngle - startAngleInSlice);
}
Vec3d relNewVec = relStartVec.rotateYaw((float) curAngle);
Vector3d relNewVec = relStartVec.rotateYaw((float) curAngle);
BlockPos newBlockPos = new BlockPos(r.position.add(relNewVec));
if (coordinates.contains(newBlockPos) || newBlockPos.equals(startPos)) continue; //filter out duplicates
coordinates.add(newBlockPos);
@@ -124,7 +98,7 @@ public class RadialMirror {
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
newBlockState = BuildModifiers
.getBlockStateFromItem(itemStack, player, startPos, Direction.UP, new Vec3d(0, 0, 0), Hand.MAIN_HAND);
.getBlockStateFromItem(itemStack, player, startPos, Direction.UP, new Vector3d(0, 0, 0), Hand.MAIN_HAND);
newBlockState = rotateOriginalBlockState(startAngleToCenter, newBlockState);
}
@@ -153,7 +127,7 @@ public class RadialMirror {
return newBlockState;
}
private static BlockState rotateBlockState(Vec3d relVec, BlockState blockState, boolean alternate) {
private static BlockState rotateBlockState(Vector3d relVec, BlockState blockState, boolean alternate) {
BlockState newBlockState;
double angleToCenter = MathHelper.atan2(relVec.x, relVec.z); //between -PI and PI
@@ -185,11 +159,34 @@ public class RadialMirror {
public static boolean isEnabled(RadialMirrorSettings r, BlockPos startPos) {
if (r == null || !r.enabled) return false;
if (new Vec3d(startPos.getX() + 0.5, startPos.getY() + 0.5, startPos.getZ() + 0.5).subtract(r.position).lengthSquared() >
r.radius * r.radius)
return false;
return !(new Vector3d(startPos.getX() + 0.5, startPos.getY() + 0.5, startPos.getZ() + 0.5).subtract(r.position).lengthSquared() >
r.radius * r.radius);
}
return true;
public static class RadialMirrorSettings {
public boolean enabled = false;
public Vector3d position = new Vector3d(0.5, 64.5, 0.5);
public int slices = 4;
public boolean alternate = false;
public int radius = 20;
public boolean drawLines = true, drawPlanes = false;
public RadialMirrorSettings() {
}
public RadialMirrorSettings(boolean enabled, Vector3d position, int slices, boolean alternate, int radius, boolean drawLines, boolean drawPlanes) {
this.enabled = enabled;
this.position = position;
this.slices = slices;
this.alternate = alternate;
this.radius = radius;
this.drawLines = drawLines;
this.drawPlanes = drawPlanes;
}
public int getReach() {
return radius * 2;
}
}
}

View File

@@ -5,14 +5,11 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootParameterSet;
import nl.requios.effortlessbuilding.BuildConfig;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.helper.FixedStack;
@@ -26,10 +23,10 @@ public class UndoRedo {
//Undo and redo stacks per player
//Gets added to twice in singleplayer (server and client) if not careful. So separate stacks.
private static Map<UUID, FixedStack<BlockSet>> undoStacksClient = new HashMap<>();
private static Map<UUID, FixedStack<BlockSet>> undoStacksServer = new HashMap<>();
private static Map<UUID, FixedStack<BlockSet>> redoStacksClient = new HashMap<>();
private static Map<UUID, FixedStack<BlockSet>> redoStacksServer = new HashMap<>();
private static final Map<UUID, FixedStack<BlockSet>> undoStacksClient = new HashMap<>();
private static final Map<UUID, FixedStack<BlockSet>> undoStacksServer = new HashMap<>();
private static final Map<UUID, FixedStack<BlockSet>> redoStacksClient = new HashMap<>();
private static final Map<UUID, FixedStack<BlockSet>> redoStacksServer = new HashMap<>();
//add to undo stack
public static void addUndo(PlayerEntity player, BlockSet blockSet) {
@@ -85,7 +82,7 @@ public class UndoRedo {
List<BlockPos> coordinates = blockSet.getCoordinates();
List<BlockState> previousBlockStates = blockSet.getPreviousBlockStates();
List<BlockState> newBlockStates = blockSet.getNewBlockStates();
Vec3d hitVec = blockSet.getHitVec();
Vector3d hitVec = blockSet.getHitVec();
//Find up to date itemstacks in player inventory
List<ItemStack> itemStacks = findItemStacksInInventory(player, previousBlockStates);
@@ -145,7 +142,7 @@ public class UndoRedo {
List<BlockPos> coordinates = blockSet.getCoordinates();
List<BlockState> previousBlockStates = blockSet.getPreviousBlockStates();
List<BlockState> newBlockStates = blockSet.getNewBlockStates();
Vec3d hitVec = blockSet.getHitVec();
Vector3d hitVec = blockSet.getHitVec();
//Find up to date itemstacks in player inventory
List<ItemStack> itemStacks = findItemStacksInInventory(player, newBlockStates);
@@ -223,8 +220,7 @@ public class UndoRedo {
//then anything it drops
if (itemStack.isEmpty()) {
//Cannot check drops on clientside because loot tables are server only
if (!player.world.isRemote)
{
if (!player.world.isRemote) {
List<ItemStack> itemsDropped = Block.getDrops(blockState, (ServerWorld) player.world, BlockPos.ZERO, null);
for (ItemStack itemStackDropped : itemsDropped) {
if (itemStackDropped.getItem() instanceof BlockItem) {

View File

@@ -23,6 +23,16 @@ public class ModeCapabilityManager {
@CapabilityInject(IModeCapability.class)
public final static Capability<IModeCapability> modeCapability = null;
// Allows for the capability to persist after death.
@SubscribeEvent
public static void clonePlayer(PlayerEvent.Clone event) {
LazyOptional<IModeCapability> original = event.getOriginal().getCapability(modeCapability, null);
LazyOptional<IModeCapability> clone = event.getEntity().getCapability(modeCapability, null);
clone.ifPresent(cloneModeCapability ->
original.ifPresent(originalModeCapability ->
cloneModeCapability.setModeData(originalModeCapability.getModeData())));
}
public interface IModeCapability {
ModeSettings getModeData();
@@ -90,14 +100,4 @@ public class ModeCapabilityManager {
}
}
// Allows for the capability to persist after death.
@SubscribeEvent
public static void clonePlayer(PlayerEvent.Clone event) {
LazyOptional<IModeCapability> original = event.getOriginal().getCapability(modeCapability, null);
LazyOptional<IModeCapability> clone = event.getEntity().getCapability(modeCapability, null);
clone.ifPresent(cloneModeCapability ->
original.ifPresent(originalModeCapability ->
cloneModeCapability.setModeData(originalModeCapability.getModeData())));
}
}

View File

@@ -4,7 +4,7 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
@@ -19,7 +19,7 @@ import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager.*;
import static nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager.ModifierSettings;
@Mod.EventBusSubscriber
public class ModifierCapabilityManager {
@@ -27,6 +27,16 @@ public class ModifierCapabilityManager {
@CapabilityInject(IModifierCapability.class)
public final static Capability<IModifierCapability> modifierCapability = null;
// Allows for the capability to persist after death.
@SubscribeEvent
public static void clonePlayer(PlayerEvent.Clone event) {
LazyOptional<IModifierCapability> original = event.getOriginal().getCapability(modifierCapability, null);
LazyOptional<IModifierCapability> clone = event.getEntity().getCapability(modifierCapability, null);
clone.ifPresent(cloneModifierCapability ->
original.ifPresent(originalModifierCapability ->
cloneModifierCapability.setModifierData(originalModifierCapability.getModifierData())));
}
public interface IModifierCapability {
ModifierSettings getModifierData();
@@ -103,7 +113,7 @@ public class ModifierCapabilityManager {
//MIRROR
boolean mirrorEnabled = compound.getBoolean("mirrorEnabled");
Vec3d mirrorPosition = new Vec3d(
Vector3d mirrorPosition = new Vector3d(
compound.getDouble("mirrorPosX"),
compound.getDouble("mirrorPosY"),
compound.getDouble("mirrorPosZ"));
@@ -130,7 +140,7 @@ public class ModifierCapabilityManager {
//RADIAL MIRROR
boolean radialMirrorEnabled = compound.getBoolean("radialMirrorEnabled");
Vec3d radialMirrorPosition = new Vec3d(
Vector3d radialMirrorPosition = new Vector3d(
compound.getDouble("radialMirrorPosX"),
compound.getDouble("radialMirrorPosY"),
compound.getDouble("radialMirrorPosZ"));
@@ -168,15 +178,4 @@ public class ModifierCapabilityManager {
}
}
// Allows for the capability to persist after death.
@SubscribeEvent
public static void clonePlayer(PlayerEvent.Clone event) {
LazyOptional<IModifierCapability> original = event.getOriginal().getCapability(modifierCapability, null);
LazyOptional<IModifierCapability> clone = event.getEntity().getCapability(modifierCapability, null);
clone.ifPresent(cloneModifierCapability ->
original.ifPresent(originalModifierCapability ->
cloneModifierCapability.setModifierData(originalModifierCapability.getModifierData())));
}
}

View File

@@ -29,7 +29,7 @@ public class CommandReach {
//Send to client
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new ModifierSettingsMessage(modifierSettings));
player.sendMessage(new StringTextComponent("Reach level of " + player.getName().getString() + " set to " + modifierSettings.getReachUpgrade()));
player.sendMessage(new StringTextComponent("Reach level of " + player.getName().getString() + " set to " + modifierSettings.getReachUpgrade()), player.getUniqueID());
return 1;
}

View File

@@ -40,12 +40,10 @@ public class CompatHelper {
Item item = stack.getItem();
if (item instanceof BlockItem)
return true;
if ((item instanceof ItemRandomizerBag))
return true;
return item instanceof ItemRandomizerBag;
//TODO 1.13 compatibility
// if (item == dankNullItem)
// return true;
return false;
}
// Get the block to be placed by this proxy. For the /dank/null, it's the slot stack

View File

@@ -2,8 +2,6 @@ package nl.requios.effortlessbuilding.gui;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
@@ -17,10 +15,9 @@ import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
public class RandomizerBagContainer extends Container {
private final IItemHandler bagInventory;
private static final int INV_START = ItemRandomizerBag.INV_SIZE, INV_END = INV_START + 26,
HOTBAR_START = INV_END + 1, HOTBAR_END = HOTBAR_START + 8;
private final IItemHandler bagInventory;
public RandomizerBagContainer(int containerId, PlayerInventory playerInventory) {
this(containerId, playerInventory, new ItemStackHandler(ItemRandomizerBag.INV_SIZE));
@@ -54,8 +51,7 @@ public class RandomizerBagContainer extends Container {
}
@Override
public Slot getSlot(int parSlotIndex)
{
public Slot getSlot(int parSlotIndex) {
if (parSlotIndex >= inventorySlots.size())
parSlotIndex = inventorySlots.size() - 1;
return super.getSlot(parSlotIndex);
@@ -127,11 +123,9 @@ public class RandomizerBagContainer extends Container {
* Callback for when the crafting gui is closed.
*/
@Override
public void onContainerClosed(PlayerEntity player)
{
public void onContainerClosed(PlayerEntity player) {
super.onContainerClosed(player);
if(!player.world.isRemote)
{
if (!player.world.isRemote) {
detectAndSendChanges();
}
}

View File

@@ -1,18 +1,19 @@
package nl.requios.effortlessbuilding.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import javax.annotation.ParametersAreNonnullByDefault;
@OnlyIn(Dist.CLIENT)
@ParametersAreNonnullByDefault
public class RandomizerBagScreen extends ContainerScreen<RandomizerBagContainer> {
private static final ResourceLocation guiTextures =
new ResourceLocation(EffortlessBuilding.MODID, "textures/gui/container/randomizerbag.png");
@@ -23,24 +24,24 @@ public class RandomizerBagScreen extends ContainerScreen<RandomizerBagContainer>
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
renderBackground();
super.render(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
renderBackground(ms);
super.render(ms, mouseX, mouseY, partialTicks);
this.renderHoveredTooltip(ms, mouseX, mouseY);
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
font.drawString(this.title.getFormattedText(), 8, 6, 0x404040);
font.drawString(playerInventory.getDisplayName().getFormattedText(), 8, ySize - 96 + 2, 0x404040);
protected void drawGuiContainerForegroundLayer(MatrixStack ms, int mouseX, int mouseY) {
font.func_243246_a(ms, this.title, 8, 6, 0x404040);
font.func_243246_a(ms, playerInventory.getDisplayName(), 8, ySize - 96 + 2, 0x404040);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
protected void drawGuiContainerBackgroundLayer(MatrixStack ms, float partialTicks, int mouseX, int mouseY) {
RenderSystem.color3f(1.0F, 1.0F, 1.0F);
minecraft.getTextureManager().bindTexture(guiTextures);
int marginHorizontal = (width - xSize) / 2;
int marginVertical = (height - ySize) / 2;
blit(marginHorizontal, marginVertical, 0, 0, xSize, ySize);
blit(ms, marginHorizontal, marginVertical, 0, 0, xSize, ySize);
}
}

View File

@@ -1,12 +1,11 @@
package nl.requios.effortlessbuilding.gui.buildmode;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SimpleSound;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.screen.LanguageScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.widget.list.ExtendedList;
@@ -16,6 +15,7 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -23,26 +23,18 @@ import net.minecraftforge.fml.client.gui.widget.ExtendedButton;
import net.minecraftforge.fml.client.gui.widget.Slider;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class PlayerSettingsGui extends Screen {
protected int left, right, top, bottom;
protected boolean showShaderList = false;
private Button shaderTypeButton;
private ShaderTypeList shaderTypeList;
private Button closeButton;
protected boolean showShaderList = false;
public enum ShaderType {
DISSOLVE_BLUE("Dissolve Blue"),
DISSOLVE_ORANGE("Dissolve Orange");
public String name;
ShaderType(String name) {
this.name = name;
}
}
public PlayerSettingsGui() {
super(new TranslationTextComponent("effortlessbuilding.screen.player_settings"));
}
@@ -58,21 +50,19 @@ public class PlayerSettingsGui extends Screen {
shaderTypeList = new ShaderTypeList(this.minecraft);
this.children.add(shaderTypeList);
//TODO set selected name
String currentShaderName = ShaderType.DISSOLVE_BLUE.name;
ITextComponent currentShaderName = ShaderType.DISSOLVE_BLUE.name;
shaderTypeButton = new ExtendedButton(right - 180, yy, 180, 20, currentShaderName, (button) -> {
showShaderList = !showShaderList;
});
addButton(shaderTypeButton);
yy += 50;
Slider slider = new Slider(right - 200, yy, 200, 20, "", "", 0.5, 2.0, 1.0, true, true, (button) -> {
Slider slider = new Slider(right - 200, yy, 200, 20, StringTextComponent.EMPTY, StringTextComponent.EMPTY, 0.5, 2.0, 1.0, true, true, (button) -> {
});
addButton(slider);
closeButton = new ExtendedButton(left + 50, bottom - 20, 180, 20, "Done", (button) -> {
this.minecraft.player.closeScreen();
});
closeButton = new ExtendedButton(left + 50, bottom - 20, 180, 20, new StringTextComponent("Done"), (button) -> this.minecraft.player.closeScreen());
addButton(closeButton);
}
@@ -82,19 +72,19 @@ public class PlayerSettingsGui extends Screen {
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
this.renderBackground();
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(ms);
int yy = top;
font.drawString("Shader type", left, yy + 5, 0xFFFFFF);
font.drawString(ms, "Shader type", left, yy + 5, 0xFFFFFF);
yy += 50;
font.drawString("Shader speed", left, yy + 5, 0xFFFFFF);
font.drawString(ms, "Shader speed", left, yy + 5, 0xFFFFFF);
super.render(mouseX, mouseY, partialTicks);
super.render(ms, mouseX, mouseY, partialTicks);
if (showShaderList)
this.shaderTypeList.render(mouseX, mouseY, partialTicks);
this.shaderTypeList.render(ms, mouseX, mouseY, partialTicks);
}
@Override
@@ -108,9 +98,24 @@ public class PlayerSettingsGui extends Screen {
}
@Override
public void removed() {
public void onClose() {
ShaderTypeList.ShaderTypeEntry selectedShader = shaderTypeList.getSelected();
//TODO save
//TODO save and remove
}
public enum ShaderType {
DISSOLVE_BLUE("Dissolve Blue"),
DISSOLVE_ORANGE("Dissolve Orange");
public ITextComponent name;
ShaderType(ITextComponent name) {
this.name = name;
}
ShaderType(String name) {
this.name = new StringTextComponent(name);
}
}
//Inspired by LanguageScreen
@@ -181,7 +186,7 @@ public class PlayerSettingsGui extends Screen {
}
protected boolean isFocused() {
return PlayerSettingsGui.this.getFocused() == this;
return PlayerSettingsGui.this.getListener() == this;
}
@Override
@@ -189,33 +194,10 @@ public class PlayerSettingsGui extends Screen {
return right - 6;
}
@OnlyIn(Dist.CLIENT)
public class ShaderTypeEntry extends ExtendedList.AbstractListEntry<ShaderTypeEntry> {
private final ShaderType shaderType;
public ShaderTypeEntry(ShaderType shaderType) {
this.shaderType = shaderType;
}
public void render(int itemIndex, int rowTop, int rowLeft, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean hovered, float partialTicks) {
if (rowTop + 10 > ShaderTypeList.this.y0 && rowTop + rowHeight - 5 < ShaderTypeList.this.y1)
drawString(font, shaderType.name, ShaderTypeList.this.x0 + 8, rowTop + 4, 0xFFFFFF);
}
@Override
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) {
if (p_mouseClicked_5_ == 0) {
setSelected(this);
return true;
} else {
return false;
}
}
}
//From AbstractList, disabled parts
public void render(int p_render_1_, int p_render_2_, float p_render_3_) {
this.renderBackground();
@Override
public void render(MatrixStack ms, int p_render_1_, int p_render_2_, float p_render_3_) {
this.renderBackground(ms);
int i = this.getScrollbarPosition();
int j = i + 6;
Tessellator tessellator = Tessellator.getInstance();
@@ -226,18 +208,18 @@ public class PlayerSettingsGui extends Screen {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
bufferbuilder.pos((double)this.x0, (double)this.y1, 0.0D).color(20, 20, 20, 180).endVertex();
bufferbuilder.pos((double)this.x1, (double)this.y1, 0.0D).color(20, 20, 20, 180).endVertex();
bufferbuilder.pos((double)this.x1, (double)this.y0, 0.0D).color(20, 20, 20, 180).endVertex();
bufferbuilder.pos((double)this.x0, (double)this.y0, 0.0D).color(20, 20, 20, 180).endVertex();
bufferbuilder.pos(this.x0, this.y1, 0.0D).color(20, 20, 20, 180).endVertex();
bufferbuilder.pos(this.x1, this.y1, 0.0D).color(20, 20, 20, 180).endVertex();
bufferbuilder.pos(this.x1, this.y0, 0.0D).color(20, 20, 20, 180).endVertex();
bufferbuilder.pos(this.x0, this.y0, 0.0D).color(20, 20, 20, 180).endVertex();
tessellator.draw();
int k = this.getRowLeft();
int l = this.y0 + 4 - (int) this.getScrollAmount();
if (this.renderHeader) {
this.renderHeader(k, l, tessellator);
this.renderHeader(ms, k, l, tessellator);
}
this.renderList(k, l, p_render_1_, p_render_2_, p_render_3_);
this.renderList(ms, k, l, p_render_1_, p_render_2_, p_render_3_);
RenderSystem.disableDepthTest();
// this.renderHoleBackground(0, this.y0, 255, 255);
// this.renderHoleBackground(this.y1, this.height, 255, 255);
@@ -271,22 +253,22 @@ public class PlayerSettingsGui extends Screen {
}
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)this.y1, 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)j, (double)this.y1, 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)j, (double)this.y0, 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)i, (double)this.y0, 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos(i, this.y1, 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos(j, this.y1, 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos(j, this.y0, 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos(i, this.y0, 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0F, 1.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0F, 1.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j, (double)l1, 0.0D).tex(1.0F, 0.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)i, (double)l1, 0.0D).tex(0.0F, 0.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos(i, l1 + k1, 0.0D).tex(0.0F, 1.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos(j, l1 + k1, 0.0D).tex(1.0F, 1.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos(j, l1, 0.0D).tex(1.0F, 0.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos(i, l1, 0.0D).tex(0.0F, 0.0F).color(128, 128, 128, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0F, 1.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0F, 1.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0F, 0.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)i, (double)l1, 0.0D).tex(0.0F, 0.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos(i, l1 + k1 - 1, 0.0D).tex(0.0F, 1.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos(j - 1, l1 + k1 - 1, 0.0D).tex(1.0F, 1.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos(j - 1, l1, 0.0D).tex(1.0F, 0.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos(i, l1, 0.0D).tex(0.0F, 0.0F).color(192, 192, 192, 255).endVertex();
tessellator.draw();
}
@@ -300,5 +282,30 @@ public class PlayerSettingsGui extends Screen {
private int getMaxScroll() {
return Math.max(0, this.getMaxPosition() - (this.y1 - this.y0 - 4));
}
@OnlyIn(Dist.CLIENT)
public class ShaderTypeEntry extends ExtendedList.AbstractListEntry<ShaderTypeEntry> {
private final ShaderType shaderType;
public ShaderTypeEntry(ShaderType shaderType) {
this.shaderType = shaderType;
}
@Override
public void render(MatrixStack ms, int itemIndex, int rowTop, int rowLeft, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean hovered, float partialTicks) {
if (rowTop + 10 > ShaderTypeList.this.y0 && rowTop + rowHeight - 5 < ShaderTypeList.this.y1)
drawString(ms, font, shaderType.name, ShaderTypeList.this.x0 + 8, rowTop + 4, 0xFFFFFF);
}
@Override
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) {
if (p_mouseClicked_5_ == 0) {
setSelected(this);
return true;
} else {
return false;
}
}
}
}
}

View File

@@ -1,50 +1,51 @@
package nl.requios.effortlessbuilding.gui.buildmode;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Stopwatch;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.ModClientEventHandler;
import nl.requios.effortlessbuilding.ModEventHandler;
import nl.requios.effortlessbuilding.buildmode.ModeSettingsManager;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import org.apache.commons.lang3.text.WordUtils;
import org.lwjgl.opengl.GL11;
import com.google.common.base.Stopwatch;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import static nl.requios.effortlessbuilding.buildmode.BuildModes.*;
import static nl.requios.effortlessbuilding.buildmode.BuildModes.BuildModeEnum;
import static nl.requios.effortlessbuilding.buildmode.ModeOptions.*;
/**
* From Chisels and Bits by AlgorithmX2
* https://github.com/AlgorithmX2/Chisels-and-Bits/blob/1.12/src/main/java/mod/chiselsandbits/client/gui/ChiselsAndBitsMenu.java
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class RadialMenu extends Screen {
private final float TIME_SCALE = 0.01f;
public static final RadialMenu instance = new RadialMenu();
private float visibility = 0.0f;
private Stopwatch lastChange = Stopwatch.createStarted();
private final float TIME_SCALE = 0.01f;
public BuildModeEnum switchTo = null;
public ActionEnum doAction = null;
public boolean actionUsed = false;
private float visibility = 0.0f;
private Stopwatch lastChange = Stopwatch.createStarted();
public RadialMenu() {
super(new TranslationTextComponent("effortlessbuilding.screen.radial_menu"));
@@ -79,44 +80,8 @@ public class RadialMenu extends Screen {
height = scaledHeight;
}
private static class MenuButton {
public double x1, x2;
public double y1, y2;
public boolean highlighted;
public final ActionEnum action;
public String name;
public Direction textSide;
public MenuButton(final String name, final ActionEnum action, final double x, final double y,
final Direction textSide) {
this.name = I18n.format(name);
this.action = action;
x1 = x - 10;
x2 = x + 10;
y1 = y - 10;
y2 = y + 10;
this.textSide = textSide;
}
}
static class MenuRegion {
public final BuildModeEnum mode;
public double x1, x2;
public double y1, y2;
public boolean highlighted;
public MenuRegion(final BuildModeEnum mode) {
this.mode = mode;
}
}
@Override
public void render(final int mouseX, final int mouseY, final float partialTicks) {
public void render(MatrixStack ms, final int mouseX, final int mouseY, final float partialTicks) {
if (!isVisible()) return;
BuildModeEnum currentBuildMode = ModeSettingsManager.getModeSettings(Minecraft.getInstance().player).getBuildMode();
@@ -127,7 +92,7 @@ public class RadialMenu extends Screen {
final int startColor = (int) (visibility * 98) << 24;
final int endColor = (int) (visibility * 128) << 24;
fillGradient(0, 0, width, height, startColor, endColor);
fillGradient(ms, 0, 0, width, height, startColor, endColor);
RenderSystem.disableTexture();
RenderSystem.enableBlend();
@@ -364,11 +329,11 @@ public class RadialMenu extends Screen {
//Draw option strings
for (int i = 0; i < currentBuildMode.options.length; i++) {
OptionEnum option = options[i];
font.drawStringWithShadow(I18n.format(option.name), (int) (middleX + buttonDistance - 9), (int) middleY - 37 + i * 39, 0xeeeeeeff);
font.drawStringWithShadow(ms, I18n.format(option.name), (int) (middleX + buttonDistance - 9), (int) middleY - 37 + i * 39, 0xeeeeeeff);
}
String credits = "Effortless Building";
font.drawStringWithShadow(credits, width - font.getStringWidth(credits) - 4, height - 10, 0x88888888);
font.drawStringWithShadow(ms, credits, width - font.getStringWidth(credits) - 4, height - 10, 0x88888888);
//Draw buildmode text
for (final MenuRegion menuRegion : modes) {
@@ -387,7 +352,7 @@ public class RadialMenu extends Screen {
fixed_x -= font.getStringWidth(text) / 2;
}
font.drawStringWithShadow(text, (int) middleX + fixed_x, (int) middleY + fixed_y, 0xffffffff);
font.drawStringWithShadow(ms, text, (int) middleX + fixed_x, (int) middleY + fixed_y, 0xffffffff);
}
}
@@ -396,57 +361,58 @@ public class RadialMenu extends Screen {
if (button.highlighted) {
String text = TextFormatting.AQUA + button.name;
int wrap = 120;
String keybind = "";
String keybind = ""; // FIXME
String keybindFormatted = "";
//Add keybind in brackets
if (button.action == ActionEnum.UNDO) {
keybind = ClientProxy.keyBindings[4].getLocalizedName();
keybind = I18n.format(ClientProxy.keyBindings[4].getTranslationKey());
}
if (button.action == ActionEnum.REDO) {
keybind = ClientProxy.keyBindings[5].getLocalizedName();
keybind = I18n.format(ClientProxy.keyBindings[5].getTranslationKey());
}
if (button.action == ActionEnum.REPLACE) {
keybind = ClientProxy.keyBindings[1].getLocalizedName();
keybind = I18n.format(ClientProxy.keyBindings[1].getTranslationKey());
}
if (button.action == ActionEnum.OPEN_MODIFIER_SETTINGS) {
keybind = ClientProxy.keyBindings[0].getLocalizedName();
keybind = I18n.format(ClientProxy.keyBindings[0].getTranslationKey());
}
if (currentBuildMode.options.length > 0) {
//Add (ctrl) to first two actions of first option
if (button.action == currentBuildMode.options[0].actions[0]
|| button.action == currentBuildMode.options[0].actions[1]) {
keybind = ClientProxy.keyBindings[6].getLocalizedName();
keybind = I18n.format(ClientProxy.keyBindings[6].getTranslationKey());
if (keybind.equals("Left Control")) keybind = "Ctrl";
}
}
if (!keybind.isEmpty()) keybindFormatted = TextFormatting.GRAY + "(" + WordUtils.capitalizeFully(keybind) + ")";
if (!keybind.isEmpty())
keybindFormatted = TextFormatting.GRAY + "(" + WordUtils.capitalizeFully(keybind) + ")";
if (button.textSide == Direction.WEST) {
font.drawSplitString( text, (int) (middleX + button.x1 - 8 ) - font.getStringWidth(text),
(int) (middleY + button.y1 + 6), wrap, 0xffffffff);
font.drawString(ms, text, (int) (middleX + button.x1 - 8) - font.getStringWidth(text),
(int) (middleY + button.y1 + 6), 0xffffffff);
} else if (button.textSide == Direction.EAST) {
font.drawSplitString(text, (int) (middleX + button.x2 + 8),
(int) (middleY + button.y1 + 6 ), wrap, 0xffffffff);
font.drawString(ms, text, (int) (middleX + button.x2 + 8),
(int) (middleY + button.y1 + 6), 0xffffffff);
} else if (button.textSide == Direction.UP || button.textSide == Direction.NORTH) {
font.drawSplitString( keybindFormatted, (int) (middleX + (button.x1 + button.x2) * 0.5 - font.getStringWidth(keybindFormatted) * 0.5),
(int) (middleY + button.y1 - 26), wrap,0xffffffff);
font.drawString(ms, keybindFormatted, (int) (middleX + (button.x1 + button.x2) * 0.5 - font.getStringWidth(keybindFormatted) * 0.5),
(int) (middleY + button.y1 - 26), 0xffffffff);
font.drawSplitString( text, (int) (middleX + (button.x1 + button.x2) * 0.5 - font.getStringWidth(text) * 0.5),
(int) (middleY + button.y1 - 14), wrap,0xffffffff);
font.drawString(ms, text, (int) (middleX + (button.x1 + button.x2) * 0.5 - font.getStringWidth(text) * 0.5),
(int) (middleY + button.y1 - 14), 0xffffffff);
} else if (button.textSide == Direction.DOWN || button.textSide == Direction.SOUTH) {
font.drawSplitString(text, (int) (middleX + (button.x1 + button.x2) * 0.5 - font.getStringWidth(text) * 0.5),
(int) (middleY + button.y1 + 26), wrap, 0xffffffff);
font.drawString(ms, text, (int) (middleX + (button.x1 + button.x2) * 0.5 - font.getStringWidth(text) * 0.5),
(int) (middleY + button.y1 + 26), 0xffffffff);
font.drawSplitString(keybindFormatted, (int) (middleX + (button.x1 + button.x2) * 0.5 - font.getStringWidth(keybindFormatted) * 0.5),
(int) (middleY + button.y1 + 38), wrap, 0xffffffff);
font.drawString(ms, keybindFormatted, (int) (middleX + (button.x1 + button.x2) * 0.5 - font.getStringWidth(keybindFormatted) * 0.5),
(int) (middleY + button.y1 + 38), 0xffffffff);
}
@@ -488,5 +454,40 @@ public class RadialMenu extends Screen {
return super.mouseClicked(mouseX, mouseY, mouseButton);
}
private static class MenuButton {
public final ActionEnum action;
public double x1, x2;
public double y1, y2;
public boolean highlighted;
public String name;
public Direction textSide;
public MenuButton(final String name, final ActionEnum action, final double x, final double y,
final Direction textSide) {
this.name = I18n.format(name);
this.action = action;
x1 = x - 10;
x2 = x + 10;
y1 = y - 10;
y2 = y + 10;
this.textSide = textSide;
}
}
static class MenuRegion {
public final BuildModeEnum mode;
public double x1, x2;
public double y1, y2;
public boolean highlighted;
public MenuRegion(final BuildModeEnum mode) {
this.mode = mode;
}
}
}

View File

@@ -1,9 +1,10 @@
package nl.requios.effortlessbuilding.gui.buildmodifier;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -48,23 +49,23 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry {
y = top + 20;
textArrayOffsetX = new GuiNumberField(font, buttons, left + 70, y, 50, 18);
textArrayOffsetX.setNumber(0);
textArrayOffsetX.setTooltip("How much each copy is shifted.");
textArrayOffsetX.setTooltip(new StringTextComponent("How much each copy is shifted."));
arrayNumberFieldList.add(textArrayOffsetX);
textArrayOffsetY = new GuiNumberField(font, buttons, left + 140, y, 50, 18);
textArrayOffsetY.setNumber(0);
textArrayOffsetY.setTooltip("How much each copy is shifted.");
textArrayOffsetY.setTooltip(new StringTextComponent("How much each copy is shifted."));
arrayNumberFieldList.add(textArrayOffsetY);
textArrayOffsetZ = new GuiNumberField(font, buttons, left + 210, y, 50, 18);
textArrayOffsetZ.setNumber(0);
textArrayOffsetZ.setTooltip("How much each copy is shifted.");
textArrayOffsetZ.setTooltip(new StringTextComponent("How much each copy is shifted."));
arrayNumberFieldList.add(textArrayOffsetZ);
y = top + 50;
textArrayCount = new GuiNumberField(font, buttons, left + 55, y, 50, 18);
textArrayCount.setNumber(5);
textArrayCount.setTooltip("How many copies should be made.");
textArrayCount.setTooltip(new StringTextComponent("How many copies should be made."));
arrayNumberFieldList.add(textArrayCount);
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(mc.player);
@@ -85,48 +86,47 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry {
}
@Override
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
public void drawEntry(MatrixStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
boolean isSelected, float partialTicks) {
int yy = y;
int offset = 8;
buttonArrayEnabled.render(mouseX, mouseY, partialTicks);
buttonArrayEnabled.render(ms, mouseX, mouseY, partialTicks);
if (buttonArrayEnabled.isChecked()) {
buttonArrayEnabled.y = yy;
font.drawString("Array enabled", left + offset, yy + 2, 0xFFFFFF);
font.drawString(ms, "Array enabled", left + offset, yy + 2, 0xFFFFFF);
yy = y + 20;
font.drawString("Offset", left + offset, yy + 5, 0xFFFFFF);
font.drawString("X", left + 50 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Offset", left + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "X", left + 50 + offset, yy + 5, 0xFFFFFF);
textArrayOffsetX.y = yy;
font.drawString("Y", left + 120 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Y", left + 120 + offset, yy + 5, 0xFFFFFF);
textArrayOffsetY.y = yy;
font.drawString("Z", left + 190 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Z", left + 190 + offset, yy + 5, 0xFFFFFF);
textArrayOffsetZ.y = yy;
yy = y + 50;
font.drawString("Count", left + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Count", left + offset, yy + 5, 0xFFFFFF);
textArrayCount.y = yy;
int currentReach = Math.max(-1, getArrayReach());
int maxReach = ReachHelper.getMaxReach(mc.player);
TextFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? TextFormatting.GRAY : TextFormatting.RED;
String reachText = "Reach: " + reachColor + currentReach + TextFormatting.GRAY + "/" + TextFormatting.GRAY + maxReach;
font.drawString(reachText, left + 176 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, reachText, left + 176 + offset, yy + 5, 0xFFFFFF);
arrayNumberFieldList.forEach(numberField -> numberField.drawNumberField(mouseX, mouseY, partialTicks));
arrayNumberFieldList.forEach(numberField -> numberField.drawNumberField(ms, mouseX, mouseY, partialTicks));
} else {
buttonArrayEnabled.y = yy;
font.drawString("Array disabled", left + offset, yy + 2, 0x999999);
font.drawString(ms, "Array disabled", left + offset, yy + 2, 0x999999);
}
}
public void drawTooltip(Screen guiScreen, int mouseX, int mouseY) {
public void drawTooltip(MatrixStack ms, Screen guiScreen, int mouseX, int mouseY) {
//Draw tooltips last
if (buttonArrayEnabled.isChecked())
{
arrayNumberFieldList.forEach(numberField -> numberField.drawTooltip(scrollPane.parent, mouseX, mouseY));
if (buttonArrayEnabled.isChecked()) {
arrayNumberFieldList.forEach(numberField -> numberField.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
}
}
@@ -183,8 +183,7 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry {
}
private int getArrayReach() {
try
{
try {
//find largest offset
double x = Math.abs(textArrayOffsetX.getNumber());
double y = Math.abs(textArrayOffsetY.getNumber());

View File

@@ -1,10 +1,12 @@
package nl.requios.effortlessbuilding.gui.buildmodifier;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -55,17 +57,17 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
textMirrorPosX = new GuiNumberField(font, buttonList, left + 58, y, 62, 18);
textMirrorPosX.setNumber(0);
textMirrorPosX.setTooltip(
Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
Arrays.asList(new StringTextComponent("The position of the mirror."), new StringTextComponent("For odd numbered builds add 0.5.").mergeStyle(TextFormatting.GRAY)));
mirrorNumberFieldList.add(textMirrorPosX);
textMirrorPosY = new GuiNumberField(font, buttonList, left + 138, y, 62, 18);
textMirrorPosY.setNumber(64);
textMirrorPosY.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
textMirrorPosY.setTooltip(Arrays.asList(new StringTextComponent("The position of the mirror."), new StringTextComponent("For odd numbered builds add 0.5.").mergeStyle(TextFormatting.GRAY)));
mirrorNumberFieldList.add(textMirrorPosY);
textMirrorPosZ = new GuiNumberField(font, buttonList, left + 218, y, 62, 18);
textMirrorPosZ.setNumber(0);
textMirrorPosZ.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
textMirrorPosZ.setTooltip(Arrays.asList(new StringTextComponent("The position of the mirror."), new StringTextComponent("For odd numbered builds add 0.5.").mergeStyle(TextFormatting.GRAY)));
mirrorNumberFieldList.add(textMirrorPosZ);
y = top + 50;
@@ -82,53 +84,53 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
textMirrorRadius = new GuiNumberField(font, buttonList, left + 218, y, 62, 18);
textMirrorRadius.setNumber(50);
//TODO change to diameter (remove /2)
textMirrorRadius.setTooltip(Arrays.asList("How far the mirror reaches in any direction.",
TextFormatting.GRAY + "Max: " + TextFormatting.GOLD + ReachHelper.getMaxReach(mc.player) / 2,
TextFormatting.GRAY + "Upgradeable in survival with reach upgrades."));
textMirrorRadius.setTooltip(Arrays.asList(new StringTextComponent("How far the mirror reaches in any direction."),
new StringTextComponent("Max: ").mergeStyle(TextFormatting.GRAY).append(new StringTextComponent(String.valueOf(ReachHelper.getMaxReach(mc.player) / 2)).mergeStyle(TextFormatting.GOLD)),
new StringTextComponent("Upgradeable in survival with reach upgrades.").mergeStyle(TextFormatting.GRAY)));
mirrorNumberFieldList.add(textMirrorRadius);
y = top + 72;
buttonCurrentPosition = new GuiIconButton(left + 5, y, 0, 0, BUILDING_ICONS, button -> {
Vec3d pos = new Vec3d(Math.floor(mc.player.getPosX()) + 0.5, Math.floor(mc.player.getPosY()) + 0.5, Math.floor(mc.player.getPosZ()) + 0.5);
Vector3d pos = new Vector3d(Math.floor(mc.player.getPosX()) + 0.5, Math.floor(mc.player.getPosY()) + 0.5, Math.floor(mc.player.getPosZ()) + 0.5);
textMirrorPosX.setNumber(pos.x);
textMirrorPosY.setNumber(pos.y);
textMirrorPosZ.setNumber(pos.z);
});
buttonCurrentPosition.setTooltip("Set mirror position to current player position");
buttonCurrentPosition.setTooltip(new StringTextComponent("Set mirror position to current player position"));
mirrorIconButtonList.add(buttonCurrentPosition);
buttonToggleOdd = new GuiIconButton(left + 35, y, 0, 20, BUILDING_ICONS, button -> {
toggleOdd = !toggleOdd;
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
if (toggleOdd) {
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to corner of block", "for even numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set mirror position to corner of block"), new StringTextComponent("for even numbered builds")));
textMirrorPosX.setNumber(textMirrorPosX.getNumber() + 0.5);
textMirrorPosY.setNumber(textMirrorPosY.getNumber() + 0.5);
textMirrorPosZ.setNumber(textMirrorPosZ.getNumber() + 0.5);
} else {
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set mirror position to middle of block"), new StringTextComponent("for odd numbered builds")));
textMirrorPosX.setNumber(Math.floor(textMirrorPosX.getNumber()));
textMirrorPosY.setNumber(Math.floor(textMirrorPosY.getNumber()));
textMirrorPosZ.setNumber(Math.floor(textMirrorPosZ.getNumber()));
}
});
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set mirror position to middle of block"), new StringTextComponent("for odd numbered builds")));
mirrorIconButtonList.add(buttonToggleOdd);
buttonDrawLines = new GuiIconButton(left + 65, y, 0, 40, BUILDING_ICONS, button -> {
drawLines = !drawLines;
buttonDrawLines.setUseAlternateIcon(drawLines);
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
buttonDrawLines.setTooltip(new StringTextComponent(drawLines ? "Hide lines" : "Show lines"));
});
buttonDrawLines.setTooltip("Show lines");
buttonDrawLines.setTooltip(new StringTextComponent("Show lines"));
mirrorIconButtonList.add(buttonDrawLines);
buttonDrawPlanes = new GuiIconButton(left + 95, y, 0, 60, BUILDING_ICONS, button -> {
drawPlanes = !drawPlanes;
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
buttonDrawPlanes.setTooltip(new StringTextComponent(drawPlanes ? "Hide area" : "Show area"));
});
buttonDrawPlanes.setTooltip("Show area");
buttonDrawPlanes.setTooltip(new StringTextComponent("Show area"));
mirrorIconButtonList.add(buttonDrawPlanes);
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(mc.player);
@@ -146,14 +148,14 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
drawPlanes = m.drawPlanes;
buttonDrawLines.setUseAlternateIcon(drawLines);
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
buttonDrawLines.setTooltip(new StringTextComponent(drawLines ? "Hide lines" : "Show lines"));
buttonDrawPlanes.setTooltip(new StringTextComponent(drawPlanes ? "Hide area" : "Show area"));
if (textMirrorPosX.getNumber() == Math.floor(textMirrorPosX.getNumber())) {
toggleOdd = false;
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set mirror position to middle of block"), new StringTextComponent("for odd numbered builds")));
} else {
toggleOdd = true;
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to corner of block", "for even numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set mirror position to corner of block"), new StringTextComponent("for even numbered builds")));
}
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
}
@@ -171,32 +173,32 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
}
@Override
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
public void drawEntry(MatrixStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
boolean isSelected, float partialTicks) {
int yy = y;
int offset = 8;
buttonMirrorEnabled.render(mouseX, mouseY, partialTicks);
buttonMirrorEnabled.render(ms, mouseX, mouseY, partialTicks);
if (buttonMirrorEnabled.isChecked()) {
buttonMirrorEnabled.y = yy;
font.drawString("Mirror enabled", left + offset, yy + 2, 0xFFFFFF);
font.drawString(ms, "Mirror enabled", left + offset, yy + 2, 0xFFFFFF);
yy = y + 18;
font.drawString("Position", left + offset, yy + 5, 0xFFFFFF);
font.drawString("X", left + 40 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Position", left + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "X", left + 40 + offset, yy + 5, 0xFFFFFF);
textMirrorPosX.y = yy;
font.drawString("Y", left + 120 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Y", left + 120 + offset, yy + 5, 0xFFFFFF);
textMirrorPosY.y = yy;
font.drawString("Z", left + 200 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Z", left + 200 + offset, yy + 5, 0xFFFFFF);
textMirrorPosZ.y = yy;
yy = y + 50;
font.drawString("Direction", left + offset, yy + 2, 0xFFFFFF);
font.drawString(ms, "Direction", left + offset, yy + 2, 0xFFFFFF);
buttonMirrorX.y = yy;
buttonMirrorY.y = yy;
buttonMirrorZ.y = yy;
font.drawString("Radius", left + 176 + offset, yy + 2, 0xFFFFFF);
font.drawString(ms, "Radius", left + 176 + offset, yy + 2, 0xFFFFFF);
textMirrorRadius.y = yy - 3;
yy = y + 72;
@@ -205,22 +207,21 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
buttonDrawLines.y = yy;
buttonDrawPlanes.y = yy;
mirrorButtonList.forEach(button -> button.render(mouseX, mouseY, partialTicks));
mirrorIconButtonList.forEach(button -> button.render(mouseX, mouseY, partialTicks));
mirrorNumberFieldList.forEach(numberField -> numberField.drawNumberField(mouseX, mouseY, partialTicks));
mirrorButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
mirrorIconButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
mirrorNumberFieldList.forEach(numberField -> numberField.drawNumberField(ms, mouseX, mouseY, partialTicks));
} else {
buttonMirrorEnabled.y = yy;
font.drawString("Mirror disabled", left + offset, yy + 2, 0x999999);
font.drawString(ms, "Mirror disabled", left + offset, yy + 2, 0x999999);
}
}
public void drawTooltip(Screen guiScreen, int mouseX, int mouseY) {
public void drawTooltip(MatrixStack ms, Screen guiScreen, int mouseX, int mouseY) {
//Draw tooltips last
if (buttonMirrorEnabled.isChecked())
{
mirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(scrollPane.parent, mouseX, mouseY));
mirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(scrollPane.parent, mouseX, mouseY));
if (buttonMirrorEnabled.isChecked()) {
mirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
mirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
}
}
@@ -250,9 +251,9 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
public Mirror.MirrorSettings getMirrorSettings() {
boolean mirrorEnabled = buttonMirrorEnabled.isChecked();
Vec3d mirrorPos = new Vec3d(0, 64, 0);
Vector3d mirrorPos = new Vector3d(0, 64, 0);
try {
mirrorPos = new Vec3d(textMirrorPosX.getNumber(), textMirrorPosY.getNumber(), textMirrorPosZ.getNumber());
mirrorPos = new Vector3d(textMirrorPosX.getNumber(), textMirrorPosY.getNumber(), textMirrorPosZ.getNumber());
} catch (NumberFormatException | NullPointerException ex) {
EffortlessBuilding.log(mc.player, "Mirror position not a valid number.");
}

View File

@@ -1,9 +1,10 @@
package nl.requios.effortlessbuilding.gui.buildmodifier;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -49,7 +50,7 @@ public class ModifierSettingsGui extends Screen {
//Close button
int y = height - 26;
buttonClose = new Button(width / 2 - 100, y, 200, 20, "Close", (button) -> {
buttonClose = new Button(width / 2 - 100, y, 200, 20, new StringTextComponent("Close"), (button) -> {
Minecraft.getInstance().player.closeScreen();
});
buttons.add(buttonClose);
@@ -66,14 +67,14 @@ public class ModifierSettingsGui extends Screen {
@Override
//Set colors using GL11, use the fontObj field to display text
//Use drawTexturedModalRect() to transfers areas of a texture resource to the screen
public void render(int mouseX, int mouseY, float partialTicks) {
this.renderBackground();
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(ms);
scrollPane.render(mouseX, mouseY, partialTicks);
scrollPane.render(ms, mouseX, mouseY, partialTicks);
buttonClose.render(mouseX, mouseY, partialTicks);
buttonClose.render(ms, mouseX, mouseY, partialTicks);
scrollPane.drawTooltip(this, mouseX, mouseY);
scrollPane.drawTooltip(ms, this, mouseX, mouseY);
}
@@ -96,8 +97,7 @@ public class ModifierSettingsGui extends Screen {
@Override
public boolean mouseReleased(double mouseX, double mouseY, int state) {
if (state != 0 || !scrollPane.mouseReleased(mouseX, mouseY, state))
{
if (state != 0 || !scrollPane.mouseReleased(mouseX, mouseY, state)) {
return super.mouseReleased(mouseX, mouseY, state);
}
return false;
@@ -114,7 +114,7 @@ public class ModifierSettingsGui extends Screen {
}
@Override
public void removed() {
public void onClose() {
scrollPane.onGuiClosed();
//save everything

View File

@@ -1,10 +1,12 @@
package nl.requios.effortlessbuilding.gui.buildmodifier;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -55,75 +57,75 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
textRadialMirrorPosX = new GuiNumberField(font, buttonList, left + 58, y, 62, 18);
textRadialMirrorPosX.setNumber(0);
textRadialMirrorPosX.setTooltip(
Arrays.asList("The position of the radial mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
Arrays.asList(new StringTextComponent("The position of the radial mirror."), new StringTextComponent("For odd numbered builds add 0.5.").mergeStyle(TextFormatting.GRAY)));
radialMirrorNumberFieldList.add(textRadialMirrorPosX);
textRadialMirrorPosY = new GuiNumberField(font, buttonList, left + 138, y, 62, 18);
textRadialMirrorPosY.setNumber(64);
textRadialMirrorPosY.setTooltip(Arrays.asList("The position of the radial mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
textRadialMirrorPosY.setTooltip(Arrays.asList(new StringTextComponent("The position of the radial mirror."), new StringTextComponent("For odd numbered builds add 0.5.").mergeStyle(TextFormatting.GRAY)));
radialMirrorNumberFieldList.add(textRadialMirrorPosY);
textRadialMirrorPosZ = new GuiNumberField(font, buttonList, left + 218, y, 62, 18);
textRadialMirrorPosZ.setNumber(0);
textRadialMirrorPosZ.setTooltip(Arrays.asList("The position of the radial mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
textRadialMirrorPosZ.setTooltip(Arrays.asList(new StringTextComponent("The position of the radial mirror."), new StringTextComponent("For odd numbered builds add 0.5.").mergeStyle(TextFormatting.GRAY)));
radialMirrorNumberFieldList.add(textRadialMirrorPosZ);
y = top + 47;
textRadialMirrorSlices = new GuiNumberField(font, buttonList, left + 55, y, 50, 18);
textRadialMirrorSlices.setNumber(4);
textRadialMirrorSlices.setTooltip(Arrays.asList("The number of repeating slices.", TextFormatting.GRAY + "Minimally 2."));
textRadialMirrorSlices.setTooltip(Arrays.asList(new StringTextComponent("The number of repeating slices."), new StringTextComponent("Minimally 2.").mergeStyle(TextFormatting.GRAY)));
radialMirrorNumberFieldList.add(textRadialMirrorSlices);
textRadialMirrorRadius = new GuiNumberField(font, buttonList, left + 218, y, 62, 18);
textRadialMirrorRadius.setNumber(50);
//TODO change to diameter (remove /2)
textRadialMirrorRadius.setTooltip(Arrays.asList("How far the radial mirror reaches from its center position.",
TextFormatting.GRAY + "Max: " + TextFormatting.GOLD + ReachHelper.getMaxReach(mc.player) / 2,
TextFormatting.GRAY + "Upgradeable in survival with reach upgrades."));
textRadialMirrorRadius.setTooltip(Arrays.asList(new StringTextComponent("How far the radial mirror reaches from its center position."),
new StringTextComponent("Max: ").mergeStyle(TextFormatting.GRAY).append(new StringTextComponent(String.valueOf(ReachHelper.getMaxReach(mc.player) / 2)).mergeStyle(TextFormatting.GOLD)),
new StringTextComponent("Upgradeable in survival with reach upgrades.").mergeStyle(TextFormatting.GRAY)));
radialMirrorNumberFieldList.add(textRadialMirrorRadius);
y = top + 72;
buttonCurrentPosition = new GuiIconButton(left + 5, y, 0, 0, BUILDING_ICONS, button -> {
Vec3d pos = new Vec3d(Math.floor(mc.player.getPosX()) + 0.5, Math.floor(mc.player.getPosY()) + 0.5, Math.floor(mc.player.getPosZ()) + 0.5);
Vector3d pos = new Vector3d(Math.floor(mc.player.getPosX()) + 0.5, Math.floor(mc.player.getPosY()) + 0.5, Math.floor(mc.player.getPosZ()) + 0.5);
textRadialMirrorPosX.setNumber(pos.x);
textRadialMirrorPosY.setNumber(pos.y);
textRadialMirrorPosZ.setNumber(pos.z);
});
buttonCurrentPosition.setTooltip("Set radial mirror position to current player position");
buttonCurrentPosition.setTooltip(new StringTextComponent("Set radial mirror position to current player position"));
radialMirrorIconButtonList.add(buttonCurrentPosition);
buttonToggleOdd = new GuiIconButton(left + 35, y, 0, 20, BUILDING_ICONS, button -> {
toggleOdd = !toggleOdd;
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
if (toggleOdd) {
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to corner of block", "for even numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set mirror position to corner of block"), new StringTextComponent("for even numbered builds")));
textRadialMirrorPosX.setNumber(textRadialMirrorPosX.getNumber() + 0.5);
textRadialMirrorPosY.setNumber(textRadialMirrorPosY.getNumber() + 0.5);
textRadialMirrorPosZ.setNumber(textRadialMirrorPosZ.getNumber() + 0.5);
} else {
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set mirror position to middle of block"), new StringTextComponent("for odd numbered builds")));
textRadialMirrorPosX.setNumber(Math.floor(textRadialMirrorPosX.getNumber()));
textRadialMirrorPosY.setNumber(Math.floor(textRadialMirrorPosY.getNumber()));
textRadialMirrorPosZ.setNumber(Math.floor(textRadialMirrorPosZ.getNumber()));
}
});
buttonToggleOdd.setTooltip(Arrays.asList("Set radial mirror position to middle of block", "for odd numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set radial mirror position to middle of block"), new StringTextComponent("for odd numbered builds")));
radialMirrorIconButtonList.add(buttonToggleOdd);
buttonDrawLines = new GuiIconButton(left + 65, y, 0, 40, BUILDING_ICONS, button -> {
drawLines = !drawLines;
buttonDrawLines.setUseAlternateIcon(drawLines);
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
buttonDrawLines.setTooltip(new StringTextComponent(drawLines ? "Hide lines" : "Show lines"));
});
buttonDrawLines.setTooltip("Show lines");
buttonDrawLines.setTooltip(new StringTextComponent("Show lines"));
radialMirrorIconButtonList.add(buttonDrawLines);
buttonDrawPlanes = new GuiIconButton(left + 95, y, 0, 60, BUILDING_ICONS, button -> {
drawPlanes = !drawPlanes;
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
buttonDrawPlanes.setTooltip(new StringTextComponent(drawPlanes ? "Hide area" : "Show area"));
});
buttonDrawPlanes.setTooltip("Show area");
buttonDrawPlanes.setTooltip(new StringTextComponent("Show area"));
radialMirrorIconButtonList.add(buttonDrawPlanes);
y = top + 76;
@@ -144,14 +146,14 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
drawPlanes = r.drawPlanes;
buttonDrawLines.setUseAlternateIcon(drawLines);
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
buttonDrawLines.setTooltip(new StringTextComponent(drawLines ? "Hide lines" : "Show lines"));
buttonDrawPlanes.setTooltip(new StringTextComponent(drawPlanes ? "Hide area" : "Show area"));
if (textRadialMirrorPosX.getNumber() == Math.floor(textRadialMirrorPosX.getNumber())) {
toggleOdd = false;
buttonToggleOdd.setTooltip(Arrays.asList("Set radial mirror position to middle of block", "for odd numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set radial mirror position to middle of block"), new StringTextComponent("for odd numbered builds")));
} else {
toggleOdd = true;
buttonToggleOdd.setTooltip(Arrays.asList("Set radial mirror position to corner of block", "for even numbered builds"));
buttonToggleOdd.setTooltip(Arrays.asList(new StringTextComponent("Set radial mirror position to corner of block"), new StringTextComponent("for even numbered builds")));
}
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
}
@@ -168,30 +170,30 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
@Override
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
public void drawEntry(MatrixStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
boolean isSelected, float partialTicks) {
int yy = y;
int offset = 8;
buttonRadialMirrorEnabled.render(mouseX, mouseY, partialTicks);
buttonRadialMirrorEnabled.render(ms, mouseX, mouseY, partialTicks);
if (buttonRadialMirrorEnabled.isChecked()) {
buttonRadialMirrorEnabled.y = yy;
font.drawString("Radial mirror enabled", left + offset, yy + 2, 0xFFFFFF);
font.drawString(ms, "Radial mirror enabled", left + offset, yy + 2, 0xFFFFFF);
yy = y + 18;
font.drawString("Position", left + offset, yy + 5, 0xFFFFFF);
font.drawString("X", left + 40 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Position", left + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "X", left + 40 + offset, yy + 5, 0xFFFFFF);
textRadialMirrorPosX.y = yy;
font.drawString("Y", left + 120 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Y", left + 120 + offset, yy + 5, 0xFFFFFF);
textRadialMirrorPosY.y = yy;
font.drawString("Z", left + 200 + offset, yy + 5, 0xFFFFFF);
font.drawString(ms, "Z", left + 200 + offset, yy + 5, 0xFFFFFF);
textRadialMirrorPosZ.y = yy;
yy = y + 50;
font.drawString("Slices", left + offset, yy + 2, 0xFFFFFF);
font.drawString(ms, "Slices", left + offset, yy + 2, 0xFFFFFF);
textRadialMirrorSlices.y = yy - 3;
font.drawString("Radius", left + 176 + offset, yy + 2, 0xFFFFFF);
font.drawString(ms, "Radius", left + 176 + offset, yy + 2, 0xFFFFFF);
textRadialMirrorRadius.y = yy - 3;
yy = y + 72;
@@ -203,23 +205,22 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
yy = y + 76;
buttonRadialMirrorAlternate.y = yy;
radialMirrorButtonList.forEach(button -> button.render(mouseX, mouseY, partialTicks));
radialMirrorIconButtonList.forEach(button -> button.render(mouseX, mouseY, partialTicks));
radialMirrorButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
radialMirrorIconButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
radialMirrorNumberFieldList
.forEach(numberField -> numberField.drawNumberField(mouseX, mouseY, partialTicks));
.forEach(numberField -> numberField.drawNumberField(ms, mouseX, mouseY, partialTicks));
} else {
buttonRadialMirrorEnabled.y = yy;
font.drawString("Radial mirror disabled", left + offset, yy + 2, 0x999999);
font.drawString(ms, "Radial mirror disabled", left + offset, yy + 2, 0x999999);
}
}
public void drawTooltip(Screen guiScreen, int mouseX, int mouseY) {
public void drawTooltip(MatrixStack ms, Screen guiScreen, int mouseX, int mouseY) {
//Draw tooltips last
if (buttonRadialMirrorEnabled.isChecked())
{
radialMirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(scrollPane.parent, mouseX, mouseY));
radialMirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(scrollPane.parent, mouseX, mouseY));
if (buttonRadialMirrorEnabled.isChecked()) {
radialMirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
radialMirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
}
}
@@ -249,9 +250,9 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
public RadialMirror.RadialMirrorSettings getRadialMirrorSettings() {
boolean radialMirrorEnabled = buttonRadialMirrorEnabled.isChecked();
Vec3d radialMirrorPos = new Vec3d(0, 64, 0);
Vector3d radialMirrorPos = new Vector3d(0, 64, 0);
try {
radialMirrorPos = new Vec3d(textRadialMirrorPosX.getNumber(), textRadialMirrorPosY.getNumber(), textRadialMirrorPosZ
radialMirrorPos = new Vector3d(textRadialMirrorPosX.getNumber(), textRadialMirrorPosY.getNumber(), textRadialMirrorPosZ
.getNumber());
} catch (NumberFormatException | NullPointerException ex) {
EffortlessBuilding.log(mc.player, "Radial mirror position not a valid number.");

View File

@@ -1,20 +1,24 @@
package nl.requios.effortlessbuilding.gui.elements;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.fml.client.gui.GuiUtils;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* This class provides a checkbox style control.
*/
public class GuiCheckBoxFixed extends Button
{
@ParametersAreNonnullByDefault
public class GuiCheckBoxFixed extends Button {
private final int boxWidth;
private boolean isChecked;
private int boxWidth;
public GuiCheckBoxFixed(int xPos, int yPos, String displayString, boolean isChecked)
{
super(xPos, yPos, Minecraft.getInstance().fontRenderer.getStringWidth(displayString) + 2 + 11, 11, displayString, b -> {});
public GuiCheckBoxFixed(int xPos, int yPos, String displayString, boolean isChecked) {
super(xPos, yPos, Minecraft.getInstance().fontRenderer.getStringWidth(displayString) + 2 + 11, 11, new StringTextComponent(displayString), b -> {
});
this.isChecked = isChecked;
this.boxWidth = 11;
this.height = 11;
@@ -22,45 +26,37 @@ public class GuiCheckBoxFixed extends Button
}
@Override
public void renderButton(int mouseX, int mouseY, float partial)
{
if (this.visible)
{
public void renderButton(MatrixStack ms, int mouseX, int mouseY, float partial) {
if (this.visible) {
Minecraft mc = Minecraft.getInstance();
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.boxWidth && mouseY < this.y + this.height;
GuiUtils.drawContinuousTexturedBox(WIDGETS_LOCATION, this.x, this.y, 0, 46, this.boxWidth, this.height, 200, 20, 2, 3, 2, 2, this.getBlitOffset());
this.renderBg(mc, mouseX, mouseY);
this.renderBg(ms, mc, mouseX, mouseY);
int color = 14737632;
if (packedFGColor != 0)
{
if (packedFGColor != 0) {
color = packedFGColor;
}
else if (!this.active)
{
} else if (!this.active) {
color = 10526880;
}
if (this.isChecked)
this.drawCenteredString(mc.fontRenderer, "x", this.x + this.boxWidth / 2 + 1, this.y + 1, 14737632);
drawCenteredString(ms, mc.fontRenderer, "x", this.x + this.boxWidth / 2 + 1, this.y + 1, 14737632);
this.drawString(mc.fontRenderer, getMessage(), this.x + this.boxWidth + 2, this.y + 2, color);
drawString(ms, mc.fontRenderer, getMessage(), this.x + this.boxWidth + 2, this.y + 2, color);
}
}
@Override
public void onPress()
{
public void onPress() {
this.isChecked = !this.isChecked;
}
public boolean isChecked()
{
public boolean isChecked() {
return this.isChecked;
}
public void setIsChecked(boolean isChecked)
{
public void setIsChecked(boolean isChecked) {
this.isChecked = isChecked;
}
}

View File

@@ -1,10 +1,10 @@
package nl.requios.effortlessbuilding.gui.elements;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -39,7 +39,7 @@ public abstract class GuiCollapsibleScrollEntry implements GuiScrollPane.IScroll
}
@Override
public void drawTooltip(Screen guiScreen, int mouseX, int mouseY) {
public void drawTooltip(MatrixStack ms, Screen guiScreen, int mouseX, int mouseY) {
}
@Override

View File

@@ -1,22 +1,27 @@
package nl.requios.effortlessbuilding.gui.elements;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@OnlyIn(Dist.CLIENT)
@ParametersAreNonnullByDefault
public class GuiIconButton extends Button {
private final ResourceLocation resourceLocation;
private final int iconX, iconY, iconWidth, iconHeight, iconAltX, iconAltY;
List<String> tooltip = new ArrayList<>();
List<ITextComponent> tooltip = new ArrayList<>();
private boolean useAltIcon = false;
public GuiIconButton(int x, int y, int iconX, int iconY, ResourceLocation resourceLocation, Button.IPressable onPress) {
@@ -24,7 +29,7 @@ public class GuiIconButton extends Button {
}
public GuiIconButton(int x, int y, int width, int height, int iconX, int iconY, int iconWidth, int iconHeight, int iconAltX, int iconAltY, ResourceLocation resourceLocation, Button.IPressable onPress) {
super(x, y, width, height, "", onPress);
super(x, y, width, height, StringTextComponent.EMPTY, onPress);
this.iconX = iconX;
this.iconY = iconY;
this.iconWidth = iconWidth;
@@ -34,11 +39,11 @@ public class GuiIconButton extends Button {
this.resourceLocation = resourceLocation;
}
public void setTooltip(String tooltip) {
setTooltip(Arrays.asList(tooltip));
public void setTooltip(ITextComponent tooltip) {
setTooltip(Collections.singletonList(tooltip));
}
public void setTooltip(List<String> tooltip) {
public void setTooltip(List<ITextComponent> tooltip) {
this.tooltip = tooltip;
}
@@ -47,33 +52,29 @@ public class GuiIconButton extends Button {
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
super.render(mouseX, mouseY, partialTicks);
if (this.visible)
{
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
super.render(ms, mouseX, mouseY, partialTicks);
if (this.visible) {
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
Minecraft.getInstance().getTextureManager().bindTexture(this.resourceLocation);
int currentIconX = this.iconX;
int currentIconY = this.iconY;
if (useAltIcon)
{
if (useAltIcon) {
currentIconX += iconAltX;
currentIconY += iconAltY;
}
//Draws a textured rectangle at the current z-value. Used to be drawTexturedModalRect in Gui.
this.blit(this.x, this.y, currentIconX, currentIconY, this.iconWidth, this.iconHeight);
this.blit(ms, this.x, this.y, currentIconX, currentIconY, this.iconWidth, this.iconHeight);
}
}
public void drawTooltip(Screen screen, int mouseX, int mouseY) {
public void drawTooltip(MatrixStack ms, Screen screen, int mouseX, int mouseY) {
boolean flag = mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + height;
if (flag) {
List<String> textLines = new ArrayList<>();
textLines.addAll(tooltip);
screen.renderTooltip(textLines, mouseX - 10, mouseY + 25);
screen.func_243308_b(ms, tooltip, mouseX - 10, mouseY + 25);
}
}
}

View File

@@ -1,21 +1,29 @@
package nl.requios.effortlessbuilding.gui.elements;
import net.minecraft.client.gui.*;
import com.mojang.blaze3d.matrix.MatrixStack;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.ParametersAreNonnullByDefault;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@OnlyIn(Dist.CLIENT)
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class GuiNumberField extends AbstractGui {
public int x, y, width, height;
@@ -24,7 +32,7 @@ public class GuiNumberField extends AbstractGui {
protected TextFieldWidget textField;
protected Button minusButton, plusButton;
List<String> tooltip = new ArrayList<>();
List<ITextComponent> tooltip = new ArrayList<>();
public GuiNumberField(FontRenderer font, List<Widget> buttonList, int x, int y, int width, int height) {
this.x = x;
@@ -32,15 +40,15 @@ public class GuiNumberField extends AbstractGui {
this.width = width;
this.height = height;
textField = new TextFieldWidget(font, x + buttonWidth + 1, y + 1, width - 2 * buttonWidth - 2, height - 2, "");
minusButton = new Button(x, y - 1, buttonWidth, height + 2, "-", button -> {
textField = new TextFieldWidget(font, x + buttonWidth + 1, y + 1, width - 2 * buttonWidth - 2, height - 2, StringTextComponent.EMPTY);
minusButton = new Button(x, y - 1, buttonWidth, height + 2, new StringTextComponent("-"), button -> {
float valueChanged = 1f;
if (Screen.hasControlDown()) valueChanged = 5f;
if (Screen.hasShiftDown()) valueChanged = 10f;
setNumber(getNumber() - valueChanged);
});
plusButton = new Button(x + width - buttonWidth, y - 1, buttonWidth, height + 2, "+", button -> {
plusButton = new Button(x + width - buttonWidth, y - 1, buttonWidth, height + 2, new StringTextComponent("+"), button -> {
float valueChanged = 1f;
if (Screen.hasControlDown()) valueChanged = 5f;
if (Screen.hasShiftDown()) valueChanged = 10f;
@@ -52,10 +60,6 @@ public class GuiNumberField extends AbstractGui {
buttonList.add(plusButton);
}
public void setNumber(double number) {
textField.setText(DecimalFormat.getInstance().format(number));
}
public double getNumber() {
if (textField.getText().isEmpty()) return 0;
try {
@@ -65,11 +69,15 @@ public class GuiNumberField extends AbstractGui {
}
}
public void setTooltip(String tooltip) {
setTooltip(Arrays.asList(tooltip));
public void setNumber(double number) {
textField.setText(DecimalFormat.getInstance().format(number));
}
public void setTooltip(List<String> tooltip) {
public void setTooltip(ITextComponent tooltip) {
setTooltip(Collections.singletonList(tooltip));
}
public void setTooltip(List<ITextComponent> tooltip) {
this.tooltip = tooltip;
}
@@ -89,40 +97,46 @@ public class GuiNumberField extends AbstractGui {
return result;
}
public void drawNumberField(int mouseX, int mouseY, float partialTicks) {
public void drawNumberField(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
textField.y = y + 1;
minusButton.y = y - 1;
plusButton.y = y - 1;
textField.render(mouseX, mouseY, partialTicks);
minusButton.render(mouseX, mouseY, partialTicks);
plusButton.render(mouseX, mouseY, partialTicks);
textField.render(ms, mouseX, mouseY, partialTicks);
minusButton.render(ms, mouseX, mouseY, partialTicks);
plusButton.render(ms, mouseX, mouseY, partialTicks);
}
public void drawTooltip(Screen screen, int mouseX, int mouseY) {
public void drawTooltip(MatrixStack ms, Screen screen, int mouseX, int mouseY) {
boolean insideTextField = mouseX >= x + buttonWidth && mouseX < x + width - buttonWidth && mouseY >= y && mouseY < y + height;
boolean insideMinusButton = mouseX >= x && mouseX < x + buttonWidth && mouseY >= y && mouseY < y + height;
boolean insidePlusButton = mouseX >= x + width - buttonWidth && mouseX < x + width && mouseY >= y && mouseY < y + height;
List<String> textLines = new ArrayList<>();
// List<String> textLines = new ArrayList<>();
List<ITextComponent> textLines = new ArrayList<>();
if (insideTextField) {
if (!tooltip.isEmpty())
textLines.addAll(tooltip);
// textLines.add(TextFormatting.GRAY + "Tip: try scrolling.");
}
if (insideMinusButton) {
textLines.add("Hold " + TextFormatting.AQUA + "shift " + TextFormatting.RESET + "for " + TextFormatting.RED + "10");
textLines.add("Hold " + TextFormatting.AQUA + "ctrl " + TextFormatting.RESET + "for " + TextFormatting.RED + "5");
textLines.add(new StringTextComponent("Hold ").append(new StringTextComponent("shift ").mergeStyle(TextFormatting.AQUA)).appendString("for ")
.append(new StringTextComponent("10").mergeStyle(TextFormatting.RED)));
textLines.add(new StringTextComponent("Hold ").append(new StringTextComponent("ctrl ").mergeStyle(TextFormatting.AQUA)).appendString("for ")
.append(new StringTextComponent("5").mergeStyle(TextFormatting.RED)));
}
if (insidePlusButton) {
textLines.add("Hold " + TextFormatting.AQUA + "shift " + TextFormatting.RESET + "for " + TextFormatting.DARK_GREEN + "10");
textLines.add("Hold " + TextFormatting.AQUA + "ctrl " + TextFormatting.RESET + "for " + TextFormatting.DARK_GREEN + "5");
textLines.add(new StringTextComponent("Hold ").append(new StringTextComponent("shift ").mergeStyle(TextFormatting.DARK_GREEN)).appendString("for ")
.append(new StringTextComponent("10").mergeStyle(TextFormatting.RED)));
textLines.add(new StringTextComponent("Hold ").append(new StringTextComponent("ctrl ").mergeStyle(TextFormatting.DARK_GREEN)).appendString("for ")
.append(new StringTextComponent("5").mergeStyle(TextFormatting.RED)));
}
screen.renderTooltip(textLines, mouseX - 10, mouseY + 25);
screen.func_243308_b(ms, textLines, mouseX - 10, mouseY + 25);
}

View File

@@ -1,9 +1,12 @@
package nl.requios.effortlessbuilding.gui.elements;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.renderer.BufferBuilder;
@@ -14,15 +17,18 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
@OnlyIn(Dist.CLIENT)
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class GuiScrollPane extends SlotGui {
public Screen parent;
public FontRenderer font;
private List<IScrollEntry> listEntries;
private final List<IScrollEntry> listEntries;
private float scrollMultiplier = 1f;
private int mouseX;
@@ -68,8 +74,7 @@ public class GuiScrollPane extends SlotGui {
//Removed background
@Override
public void render(int mouseXIn, int mouseYIn, float partialTicks)
{
public void render(MatrixStack ms, int mouseXIn, int mouseYIn, float partialTicks) {
if (this.visible) {
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
@@ -88,7 +93,7 @@ public class GuiScrollPane extends SlotGui {
}
//All entries
this.renderList(insideLeft, insideTop, mouseXIn, mouseYIn, partialTicks);
this.renderList(ms, insideLeft, insideTop, mouseXIn, mouseYIn, partialTicks);
RenderSystem.disableDepthTest();
//Dirt overlays on top and bottom
@@ -128,22 +133,22 @@ public class GuiScrollPane extends SlotGui {
}
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double) scrollbarLeft, (double) this.y1, 0.0F).tex(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double) scrollbarRight, (double) this.y1, 0.0F).tex(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double) scrollbarRight, (double) this.y0, 0.0F).tex(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) this.y0, 0.0F).tex(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos(scrollbarLeft, this.y1, 0.0F).tex(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos(scrollbarRight, this.y1, 0.0F).tex(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos(scrollbarRight, this.y0, 0.0F).tex(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos(scrollbarLeft, this.y0, 0.0F).tex(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double) scrollbarLeft, (double) (l1 + k1), 0.0F).tex(0.0F, 1.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double) scrollbarRight, (double) (l1 + k1), 0.0F).tex(1.0F, 1.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double) scrollbarRight, (double) l1, 0.0F).tex(1.0F, 0.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) l1, 0.0F).tex(0.0F, 0.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos(scrollbarLeft, l1 + k1, 0.0F).tex(0.0F, 1.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos(scrollbarRight, l1 + k1, 0.0F).tex(1.0F, 1.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos(scrollbarRight, l1, 0.0F).tex(1.0F, 0.0F).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos(scrollbarLeft, l1, 0.0F).tex(0.0F, 0.0F).color(128, 128, 128, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double) scrollbarLeft, (double) (l1 + k1 - 1), 0.0F).tex(0.0F, 1.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double) (scrollbarRight - 1), (double) (l1 + k1 - 1), 0.0F).tex(1.0F, 1.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double) (scrollbarRight - 1), (double) l1, 0.0F).tex(1.0F, 0.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) l1, 0.0F).tex(0.0F, 0.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos(scrollbarLeft, l1 + k1 - 1, 0.0F).tex(0.0F, 1.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos(scrollbarRight - 1, l1 + k1 - 1, 0.0F).tex(1.0F, 1.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos(scrollbarRight - 1, l1, 0.0F).tex(1.0F, 0.0F).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos(scrollbarLeft, l1, 0.0F).tex(0.0F, 0.0F).color(192, 192, 192, 255).endVertex();
tessellator.draw();
}
@@ -173,8 +178,8 @@ public class GuiScrollPane extends SlotGui {
}
@Override
protected void renderItem(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks) {
this.getListEntry(slotIndex).drawEntry(slotIndex, xPos, yPos, this.getRowWidth(), heightIn, mouseXIn, mouseYIn,
protected void renderItem(MatrixStack ms, int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks) {
this.getListEntry(slotIndex).drawEntry(ms, slotIndex, xPos, yPos, this.getRowWidth(), heightIn, mouseXIn, mouseYIn,
this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == slotIndex, partialTicks);
}
@@ -204,6 +209,11 @@ public class GuiScrollPane extends SlotGui {
return -1;
}
@Override
public List<? extends IGuiEventListener> getEventListeners() {
return null;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
int selectedSlot = this.getSlotIndexFromScreenCoords(mouseX, mouseY);
@@ -238,8 +248,7 @@ public class GuiScrollPane extends SlotGui {
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
for (int i = 0; i < this.getItemCount(); ++i)
{
for (int i = 0; i < this.getItemCount(); ++i) {
double relativeX = getRelativeMouseX(mouseX);
double relativeY = getRelativeMouseY(mouseY, i);
this.getListEntry(i).mouseReleased(i, (int) mouseX, (int) mouseY, button, (int) relativeX, (int) relativeY);
@@ -323,8 +332,7 @@ public class GuiScrollPane extends SlotGui {
//Draw in center if it fits
@Override
protected void renderList(int insideLeft, int insideTop, int mouseXIn, int mouseYIn, float partialTicks)
{
protected void renderList(MatrixStack ms, int insideLeft, int insideTop, int mouseXIn, int mouseYIn, float partialTicks) {
int itemCount = this.getItemCount();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
@@ -340,13 +348,11 @@ public class GuiScrollPane extends SlotGui {
}
//Draw all entries
for (int i = 0; i < itemCount; ++i)
{
for (int i = 0; i < itemCount; ++i) {
int entryHeight = listEntries.get(i).getHeight();
int entryHeight2 = entryHeight - 4;
if (y > this.y1 || y + entryHeight2 < this.y0)
{
if (y > this.y1 || y + entryHeight2 < this.y0) {
this.updateItemPosition(i, insideLeft, y, partialTicks);
}
@@ -357,22 +363,22 @@ public class GuiScrollPane extends SlotGui {
float f = this.isFocused() ? 1.0F : 0.5F;
RenderSystem.color4f(f, f, f, 1.0F);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.pos((double)i1, (double)(y + entryHeight2 + 2), 0.0D).endVertex();
bufferbuilder.pos((double)j1, (double)(y + entryHeight2 + 2), 0.0D).endVertex();
bufferbuilder.pos((double)j1, (double)(y - 2), 0.0D).endVertex();
bufferbuilder.pos((double)i1, (double)(y - 2), 0.0D).endVertex();
bufferbuilder.pos(i1, y + entryHeight2 + 2, 0.0D).endVertex();
bufferbuilder.pos(j1, y + entryHeight2 + 2, 0.0D).endVertex();
bufferbuilder.pos(j1, y - 2, 0.0D).endVertex();
bufferbuilder.pos(i1, y - 2, 0.0D).endVertex();
tessellator.draw();
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 1.0F);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.pos((double)(i1 + 1), (double)(y + entryHeight2 + 1), 0.0D).endVertex();
bufferbuilder.pos((double)(j1 - 1), (double)(y + entryHeight2 + 1), 0.0D).endVertex();
bufferbuilder.pos((double)(j1 - 1), (double)(y - 1), 0.0D).endVertex();
bufferbuilder.pos((double)(i1 + 1), (double)(y - 1), 0.0D).endVertex();
bufferbuilder.pos(i1 + 1, y + entryHeight2 + 1, 0.0D).endVertex();
bufferbuilder.pos(j1 - 1, y + entryHeight2 + 1, 0.0D).endVertex();
bufferbuilder.pos(j1 - 1, y - 1, 0.0D).endVertex();
bufferbuilder.pos(i1 + 1, y - 1, 0.0D).endVertex();
tessellator.draw();
RenderSystem.enableTexture();
}
this.renderItem(i, insideLeft, y, entryHeight2, mouseXIn, mouseYIn, partialTicks);
this.renderItem(ms, i, insideLeft, y, entryHeight2, mouseXIn, mouseYIn, partialTicks);
y += entryHeight;
}
}
@@ -409,9 +415,9 @@ public class GuiScrollPane extends SlotGui {
entry.updateScreen();
}
public void drawTooltip(Screen guiScreen, int mouseX, int mouseY) {
public void drawTooltip(MatrixStack ms, Screen guiScreen, int mouseX, int mouseY) {
for (IScrollEntry entry : this.listEntries)
entry.drawTooltip(guiScreen, mouseX, mouseY);
entry.drawTooltip(ms, guiScreen, mouseX, mouseY);
}
@Override
@@ -440,7 +446,7 @@ public class GuiScrollPane extends SlotGui {
void updateScreen();
void drawTooltip(Screen guiScreen, int mouseX, int mouseY);
void drawTooltip(MatrixStack ms, Screen guiScreen, int mouseX, int mouseY);
boolean charTyped(char eventChar, int eventKey);
@@ -450,7 +456,7 @@ public class GuiScrollPane extends SlotGui {
void updatePosition(int slotIndex, int x, int y, float partialTicks);
void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks);
void drawEntry(MatrixStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks);
/**
* Called when the mouse is clicked within this entry. Returning true means that something within this entry was

View File

@@ -0,0 +1,263 @@
package nl.requios.effortlessbuilding.gui.elements;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FocusableGui;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.IRenderable;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Collections;
import java.util.List;
@OnlyIn(Dist.CLIENT)
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SuppressWarnings("deprecation")
public abstract class SlotGui extends FocusableGui implements IRenderable {
protected final Minecraft minecraft;
protected final int itemHeight;
protected int width;
protected int height;
protected int y0;
protected int y1;
protected int x1;
protected int x0;
protected int yDrag = -2;
protected double yo;
protected boolean visible = true;
protected boolean renderSelection = true;
protected boolean renderHeader;
protected int headerHeight;
private boolean scrolling;
public SlotGui(Minecraft mcIn, int width, int height, int topIn, int bottomIn, int slotHeightIn) {
this.minecraft = mcIn;
this.width = width;
this.height = height;
this.y0 = topIn;
this.y1 = bottomIn;
this.itemHeight = slotHeightIn;
this.x0 = 0;
this.x1 = width;
}
public boolean isVisible() {
return this.visible;
}
protected abstract int getItemCount();
public List<? extends IGuiEventListener> children() {
return Collections.emptyList();
}
protected boolean selectItem(int p_selectItem_1_, int p_selectItem_2_, double p_selectItem_3_, double p_selectItem_5_) {
return true;
}
protected abstract boolean isSelectedItem(int p_isSelectedItem_1_);
protected int getMaxPosition() {
return this.getItemCount() * this.itemHeight + this.headerHeight;
}
protected abstract void renderBackground();
protected void updateItemPosition(int p_updateItemPosition_1_, int p_updateItemPosition_2_, int p_updateItemPosition_3_, float p_updateItemPosition_4_) {
}
protected abstract void renderItem(MatrixStack ms, int p_renderItem_1_, int p_renderItem_2_, int p_renderItem_3_, int p_renderItem_4_, int p_renderItem_5_, int p_renderItem_6_, float p_renderItem_7_);
protected void renderHeader(int p_renderHeader_1_, int p_renderHeader_2_, Tessellator p_renderHeader_3_) {
}
protected void clickedHeader(int p_clickedHeader_1_, int p_clickedHeader_2_) {
}
public int getItemAtPosition(double p_getItemAtPosition_1_, double p_getItemAtPosition_3_) {
int i = this.x0 + this.width / 2 - this.getRowWidth() / 2;
int j = this.x0 + this.width / 2 + this.getRowWidth() / 2;
int k = MathHelper.floor(p_getItemAtPosition_3_ - (double) this.y0) - this.headerHeight + (int) this.yo - 4;
int l = k / this.itemHeight;
return p_getItemAtPosition_1_ < (double) this.getScrollbarPosition() && p_getItemAtPosition_1_ >= (double) i && p_getItemAtPosition_1_ <= (double) j && l >= 0 && k >= 0 && l < this.getItemCount() ? l : -1;
}
protected void capYPosition() {
this.yo = MathHelper.clamp(this.yo, 0.0D, this.getMaxScroll());
}
public int getMaxScroll() {
return Math.max(0, this.getMaxPosition() - (this.y1 - this.y0 - 4));
}
public int getScroll() {
return (int) this.yo;
}
public boolean isMouseInList(double p_isMouseInList_1_, double p_isMouseInList_3_) {
return p_isMouseInList_3_ >= (double) this.y0 && p_isMouseInList_3_ <= (double) this.y1 && p_isMouseInList_1_ >= (double) this.x0 && p_isMouseInList_1_ <= (double) this.x1;
}
public abstract void render(MatrixStack ms, int p_render_1_, int p_render_2_, float p_render_3_);
protected void updateScrollingState(double p_updateScrollingState_1_, double p_updateScrollingState_3_, int p_updateScrollingState_5_) {
this.scrolling = p_updateScrollingState_5_ == 0 && p_updateScrollingState_1_ >= (double) this.getScrollbarPosition() && p_updateScrollingState_1_ < (double) (this.getScrollbarPosition() + 6);
}
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) {
this.updateScrollingState(p_mouseClicked_1_, p_mouseClicked_3_, p_mouseClicked_5_);
if (this.isVisible() && this.isMouseInList(p_mouseClicked_1_, p_mouseClicked_3_)) {
int i = this.getItemAtPosition(p_mouseClicked_1_, p_mouseClicked_3_);
if (i == -1 && p_mouseClicked_5_ == 0) {
this.clickedHeader((int) (p_mouseClicked_1_ - (double) (this.x0 + this.width / 2 - this.getRowWidth() / 2)), (int) (p_mouseClicked_3_ - (double) this.y0) + (int) this.yo - 4);
return true;
} else if (i != -1 && this.selectItem(i, p_mouseClicked_5_, p_mouseClicked_1_, p_mouseClicked_3_)) {
if (this.children().size() > i) {
this.setListener(this.children().get(i));
}
this.setDragging(true);
return true;
} else {
return this.scrolling;
}
} else {
return false;
}
}
public boolean mouseReleased(double p_mouseReleased_1_, double p_mouseReleased_3_, int p_mouseReleased_5_) {
if (this.getListener() != null) {
this.getListener().mouseReleased(p_mouseReleased_1_, p_mouseReleased_3_, p_mouseReleased_5_);
}
return false;
}
public boolean mouseDragged(double p_mouseDragged_1_, double p_mouseDragged_3_, int p_mouseDragged_5_, double p_mouseDragged_6_, double p_mouseDragged_8_) {
if (super.mouseDragged(p_mouseDragged_1_, p_mouseDragged_3_, p_mouseDragged_5_, p_mouseDragged_6_, p_mouseDragged_8_)) {
return true;
} else if (this.isVisible() && p_mouseDragged_5_ == 0 && this.scrolling) {
if (p_mouseDragged_3_ < (double) this.y0) {
this.yo = 0.0D;
} else if (p_mouseDragged_3_ > (double) this.y1) {
this.yo = this.getMaxScroll();
} else {
double d0 = this.getMaxScroll();
if (d0 < 1.0D) {
d0 = 1.0D;
}
int i = (int) ((float) ((this.y1 - this.y0) * (this.y1 - this.y0)) / (float) this.getMaxPosition());
i = MathHelper.clamp(i, 32, this.y1 - this.y0 - 8);
double d1 = d0 / (double) (this.y1 - this.y0 - i);
if (d1 < 1.0D) {
d1 = 1.0D;
}
this.yo += p_mouseDragged_8_ * d1;
this.capYPosition();
}
return true;
} else {
return false;
}
}
public boolean mouseScrolled(double p_mouseScrolled_1_, double p_mouseScrolled_3_, double p_mouseScrolled_5_) {
if (!this.isVisible()) {
return false;
} else {
this.yo -= p_mouseScrolled_5_ * (double) this.itemHeight / 2.0D;
return true;
}
}
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
if (!this.isVisible()) {
return false;
} else if (super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_)) {
return true;
} else if (p_keyPressed_1_ == 264) {
this.moveSelection(1);
return true;
} else if (p_keyPressed_1_ == 265) {
this.moveSelection(-1);
return true;
} else {
return false;
}
}
protected void moveSelection(int p_moveSelection_1_) {
}
public boolean charTyped(char p_charTyped_1_, int p_charTyped_2_) {
return this.isVisible() && super.charTyped(p_charTyped_1_, p_charTyped_2_);
}
public boolean isMouseOver(double p_isMouseOver_1_, double p_isMouseOver_3_) {
return this.isMouseInList(p_isMouseOver_1_, p_isMouseOver_3_);
}
public int getRowWidth() {
return 220;
}
protected void renderList(MatrixStack ms, int p_renderList_1_, int p_renderList_2_, int p_renderList_3_, int p_renderList_4_, float p_renderList_5_) {
int i = this.getItemCount();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
for (int j = 0; j < i; ++j) {
int k = p_renderList_2_ + j * this.itemHeight + this.headerHeight;
int l = this.itemHeight - 4;
if (k > this.y1 || k + l < this.y0) {
this.updateItemPosition(j, p_renderList_1_, k, p_renderList_5_);
}
if (this.renderSelection && this.isSelectedItem(j)) {
int i1 = this.x0 + this.width / 2 - this.getRowWidth() / 2;
int j1 = this.x0 + this.width / 2 + this.getRowWidth() / 2;
RenderSystem.disableTexture();
float f = this.isFocused() ? 1.0F : 0.5F;
RenderSystem.color4f(f, f, f, 1.0F);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.pos(i1, k + l + 2, 0.0D).endVertex();
bufferbuilder.pos(j1, k + l + 2, 0.0D).endVertex();
bufferbuilder.pos(j1, k - 2, 0.0D).endVertex();
bufferbuilder.pos(i1, k - 2, 0.0D).endVertex();
tessellator.draw();
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 1.0F);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.pos(i1 + 1, k + l + 1, 0.0D).endVertex();
bufferbuilder.pos(j1 - 1, k + l + 1, 0.0D).endVertex();
bufferbuilder.pos(j1 - 1, k - 1, 0.0D).endVertex();
bufferbuilder.pos(i1 + 1, k - 1, 0.0D).endVertex();
tessellator.draw();
RenderSystem.enableTexture();
}
this.renderItem(ms, j, p_renderList_1_, k, l, p_renderList_3_, p_renderList_4_, p_renderList_5_);
}
}
protected boolean isFocused() {
return false;
}
protected int getScrollbarPosition() {
return this.width / 2 + 124;
}
}

View File

@@ -1,11 +1,9 @@
package nl.requios.effortlessbuilding.helper;
import nl.requios.effortlessbuilding.EffortlessBuilding;
//Stack with fixed size. Removes (overwrites) oldest element on push.
public class FixedStack<T> {
private T[] stack;
private int size;
private final T[] stack;
private final int size;
private int top;
private int filled = 0; //how many valid items are in the stack

View File

@@ -14,10 +14,14 @@ public class ReachHelper {
//Check buildsettings for reachUpgrade
int reachUpgrade = ModifierSettingsManager.getModifierSettings(player).getReachUpgrade();
switch (reachUpgrade) {
case 0: return BuildConfig.reach.maxReachLevel0.get();
case 1: return BuildConfig.reach.maxReachLevel1.get();
case 2: return BuildConfig.reach.maxReachLevel2.get();
case 3: return BuildConfig.reach.maxReachLevel3.get();
case 0:
return BuildConfig.reach.maxReachLevel0.get();
case 1:
return BuildConfig.reach.maxReachLevel1.get();
case 2:
return BuildConfig.reach.maxReachLevel2.get();
case 3:
return BuildConfig.reach.maxReachLevel3.get();
}
return BuildConfig.reach.maxReachLevel0.get();
}

View File

@@ -2,22 +2,19 @@ package nl.requios.effortlessbuilding.helper;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.*;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.util.*;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.CachedBlockInfo;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;
import nl.requios.effortlessbuilding.BuildConfig;
@@ -33,7 +30,7 @@ public class SurvivalHelper {
//Checks if area is loaded, if player has the right permissions, if existing block can be replaced (drops it if so) and consumes an item from the stack.
//Based on ItemBlock#onItemUse
public static boolean placeBlock(World world, PlayerEntity player, BlockPos pos, BlockState blockState,
ItemStack origstack, Direction facing, Vec3d hitVec, boolean skipPlaceCheck,
ItemStack origstack, Direction facing, Vector3d hitVec, boolean skipPlaceCheck,
boolean skipCollisionCheck, boolean playSound) {
if (!world.isBlockPresent(pos)) return false;
ItemStack itemstack = origstack;
@@ -173,6 +170,7 @@ public class SurvivalHelper {
/**
* Check if player can place a block.
* Turn randomizer bag into itemstack inside before.
*
* @param world
* @param player
* @param pos
@@ -206,28 +204,29 @@ public class SurvivalHelper {
BlockState state = world.getBlockState(pos);
switch (BuildConfig.survivalBalancers.quickReplaceMiningLevel.get()) {
case -1: return state.getMaterial().isToolNotRequired();
case 0: return state.getBlock().getHarvestLevel(state) <= 0;
case 1: return state.getBlock().getHarvestLevel(state) <= 1;
case 2: return state.getBlock().getHarvestLevel(state) <= 2;
case 3: return state.getBlock().getHarvestLevel(state) <= 3;
case -1:
return !state.getRequiresTool();
case 0:
return state.getBlock().getHarvestLevel(state) <= 0;
case 1:
return state.getBlock().getHarvestLevel(state) <= 1;
case 2:
return state.getBlock().getHarvestLevel(state) <= 2;
case 3:
return state.getBlock().getHarvestLevel(state) <= 3;
}
return false;
}
//From EntityPlayer#canPlayerEdit
private static boolean canPlayerEdit(PlayerEntity player, World world, BlockPos pos, ItemStack stack)
{
private static boolean canPlayerEdit(PlayerEntity player, World world, BlockPos pos, ItemStack stack) {
if (!world.isBlockModifiable(player, pos)) return false;
if (player.abilities.allowEdit)
{
if (player.abilities.allowEdit) {
//True in creative and survival mode
return true;
}
else
{
} else {
//Adventure mode
CachedBlockInfo blockworldstate = new CachedBlockInfo(world, pos, false);
return stack.canPlaceOn(world.getTags(), blockworldstate);
@@ -236,13 +235,11 @@ public class SurvivalHelper {
}
//From World#mayPlace
private static boolean mayPlace(World world, Block blockIn, BlockState newBlockState, BlockPos pos, boolean skipCollisionCheck, Direction sidePlacedOn, @Nullable Entity placer)
{
private static boolean mayPlace(World world, Block blockIn, BlockState newBlockState, BlockPos pos, boolean skipCollisionCheck, Direction sidePlacedOn, @Nullable Entity placer) {
BlockState iblockstate1 = world.getBlockState(pos);
VoxelShape voxelShape = skipCollisionCheck ? null : blockIn.getDefaultState().getCollisionShape(world, pos);
if (voxelShape != null && !world.checkNoEntityCollision(placer, voxelShape))
{
if (voxelShape != null && !world.checkNoEntityCollision(placer, voxelShape)) {
return false;
}
@@ -258,8 +255,7 @@ public class SurvivalHelper {
}
//TODO 1.14 check what Material.CIRCUITS has become
if (iblockstate1.getMaterial() == Material.REDSTONE_LIGHT && blockIn == Blocks.ANVIL)
{
if (iblockstate1.getMaterial() == Material.REDSTONE_LIGHT && blockIn == Blocks.ANVIL) {
return true;
}
@@ -273,7 +269,6 @@ public class SurvivalHelper {
}
//Can break using held tool? (or in creative)
public static boolean canBreak(World world, PlayerEntity player, BlockPos pos) {
BlockState blockState = world.getBlockState(pos);
@@ -285,8 +280,7 @@ public class SurvivalHelper {
}
//From ForgeHooks#canHarvestBlock
public static boolean canHarvestBlock(@Nonnull Block block, @Nonnull PlayerEntity player, @Nonnull World world, @Nonnull BlockPos pos)
{
public static boolean canHarvestBlock(@Nonnull Block block, @Nonnull PlayerEntity player, @Nonnull World world, @Nonnull BlockPos pos) {
BlockState state = world.getBlockState(pos);
//Dont break bedrock
@@ -294,24 +288,21 @@ public class SurvivalHelper {
return false;
}
if (state.getMaterial().isToolNotRequired())
{
if (!state.getRequiresTool()) {
return true;
}
ItemStack stack = player.getHeldItemMainhand();
ToolType tool = block.getHarvestTool(state);
if (stack.isEmpty() || tool == null)
{
return player.canHarvestBlock(state);
if (stack.isEmpty() || tool == null) {
return player.func_234569_d_(state);
}
if (stack.getDamage() >= stack.getMaxDamage()) return false;
int toolLevel = stack.getItem().getHarvestLevel(stack, tool, player, state);
if (toolLevel < 0)
{
return player.canHarvestBlock(state);
if (toolLevel < 0) {
return player.func_234569_d_(state);
}
return toolLevel >= block.getHarvestLevel(state);
@@ -324,7 +315,8 @@ public class SurvivalHelper {
if (CompatHelper.isItemBlockProxy(itemstack))
itemstack = CompatHelper.getItemBlockFromStack(itemstack);
if (itemstack.isEmpty() || !(itemstack.getItem() instanceof BlockItem) || !(((BlockItem) itemstack.getItem()).getBlock() instanceof SlabBlock)) return false;
if (itemstack.isEmpty() || !(itemstack.getItem() instanceof BlockItem) || !(((BlockItem) itemstack.getItem()).getBlock() instanceof SlabBlock))
return false;
SlabBlock heldSlab = (SlabBlock) ((BlockItem) itemstack.getItem()).getBlock();
if (placedBlockState.getBlock() == heldSlab) {

View File

@@ -1,21 +1,24 @@
package nl.requios.effortlessbuilding.item;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.*;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
@@ -34,16 +37,19 @@ import nl.requios.effortlessbuilding.gui.RandomizerBagContainer;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Random;
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class ItemRandomizerBag extends Item {
public static final int INV_SIZE = 5;
private static long currentSeed = 1337;
private static Random rand = new Random(currentSeed);
private static final Random rand = new Random(currentSeed);
public ItemRandomizerBag() {
super(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(1));
@@ -51,89 +57,6 @@ public class ItemRandomizerBag extends Item {
this.setRegistryName(EffortlessBuilding.MODID, "randomizer_bag");
}
@Override
public ActionResultType onItemUse(ItemUseContext ctx) {
PlayerEntity player = ctx.getPlayer();
World world = ctx.getWorld();
BlockPos pos = ctx.getPos();
Direction facing = ctx.getFace();
ItemStack item = ctx.getItem();
Vec3d hitVec = ctx.getHitVec();
if (player == null) return ActionResultType.FAIL;
if (ctx.func_225518_g_()) { //ctx.isPlacerSneaking()
if (world.isRemote) return ActionResultType.SUCCESS;
//Open inventory
NetworkHooks.openGui((ServerPlayerEntity) player, new ContainerProvider(item));
} else {
if (world.isRemote) return ActionResultType.SUCCESS;
//Only place manually if in normal vanilla mode
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
if (buildMode != BuildModes.BuildModeEnum.NORMAL || modifierSettings.doQuickReplace()) {
return ActionResultType.FAIL;
}
//Use item
//Get bag inventory
//TODO offhand support
ItemStack bag = player.getHeldItem(Hand.MAIN_HAND);
IItemHandler bagInventory = getBagInventory(bag);
if (bagInventory == null)
return ActionResultType.FAIL;
ItemStack toPlace = pickRandomStack(bagInventory);
if (toPlace.isEmpty()) return ActionResultType.FAIL;
//Previously: use onItemUse to place block (no synergy)
//bag.setItemDamage(toPlace.getMetadata());
//toPlace.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
//TODO replaceable
if (!world.getBlockState(pos).getBlock().getMaterial(world.getBlockState(pos)).isReplaceable()) {
pos = pos.offset(facing);
}
BlockItemUseContext blockItemUseContext = new BlockItemUseContext(new ItemUseContext(player, Hand.MAIN_HAND, new BlockRayTraceResult(hitVec, facing, pos, false)));
BlockState blockState = Block.getBlockFromItem(toPlace.getItem()).getStateForPlacement(blockItemUseContext);
SurvivalHelper.placeBlock(world, player, pos, blockState, toPlace, facing, hitVec, false, false, true);
//Synergy
//Works without calling
// BlockSnapshot blockSnapshot = new BlockSnapshot(player.world, pos, blockState);
// BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, blockState, player, hand);
// Mirror.onBlockPlaced(placeEvent);
// Array.onBlockPlaced(placeEvent);
}
return ActionResultType.SUCCESS;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
ItemStack bag = player.getHeldItem(hand);
if (player.isSneaking()) {
if (world.isRemote) return new ActionResult<>(ActionResultType.SUCCESS, bag);
//Open inventory
NetworkHooks.openGui((ServerPlayerEntity) player, new ContainerProvider(bag));
} else {
//Use item
//Get bag inventory
IItemHandler bagInventory = getBagInventory(bag);
if (bagInventory == null)
return new ActionResult<>(ActionResultType.FAIL, bag);
ItemStack toUse = pickRandomStack(bagInventory);
if (toUse.isEmpty()) return new ActionResult<>(ActionResultType.FAIL, bag);
return toUse.useItemRightClick(world, player, hand);
}
return new ActionResult<>(ActionResultType.PASS, bag);
}
/**
* Get the inventory of a randomizer bag by checking the capability.
*
@@ -189,6 +112,98 @@ public class ItemRandomizerBag extends Item {
return ItemStack.EMPTY;
}
public static void resetRandomness() {
rand.setSeed(currentSeed);
}
public static void renewRandomness() {
currentSeed = Calendar.getInstance().getTimeInMillis();
rand.setSeed(currentSeed);
}
@Override
public ActionResultType onItemUse(ItemUseContext ctx) {
PlayerEntity player = ctx.getPlayer();
World world = ctx.getWorld();
BlockPos pos = ctx.getPos();
Direction facing = ctx.getFace();
ItemStack item = ctx.getItem();
Vector3d hitVec = ctx.getHitVec();
if (player == null) return ActionResultType.FAIL;
if (ctx.getPlayer() != null && ctx.getPlayer().isSneaking()) { //ctx.isPlacerSneaking()
if (world.isRemote) return ActionResultType.SUCCESS;
//Open inventory
NetworkHooks.openGui((ServerPlayerEntity) player, new ContainerProvider(item));
} else {
if (world.isRemote) return ActionResultType.SUCCESS;
//Only place manually if in normal vanilla mode
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
if (buildMode != BuildModes.BuildModeEnum.NORMAL || modifierSettings.doQuickReplace()) {
return ActionResultType.FAIL;
}
//Use item
//Get bag inventory
//TODO offhand support
ItemStack bag = player.getHeldItem(Hand.MAIN_HAND);
IItemHandler bagInventory = getBagInventory(bag);
if (bagInventory == null)
return ActionResultType.FAIL;
ItemStack toPlace = pickRandomStack(bagInventory);
if (toPlace.isEmpty()) return ActionResultType.FAIL;
//Previously: use onItemUse to place block (no synergy)
//bag.setItemDamage(toPlace.getMetadata());
//toPlace.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
//TODO replaceable
if (!world.getBlockState(pos).getBlock().isReplaceable(world.getBlockState(pos), Fluids.EMPTY)) {
pos = pos.offset(facing);
}
BlockItemUseContext blockItemUseContext = new BlockItemUseContext(new ItemUseContext(player, Hand.MAIN_HAND, new BlockRayTraceResult(hitVec, facing, pos, false)));
BlockState blockState = Block.getBlockFromItem(toPlace.getItem()).getStateForPlacement(blockItemUseContext);
SurvivalHelper.placeBlock(world, player, pos, blockState, toPlace, facing, hitVec, false, false, true);
//Synergy
//Works without calling
// BlockSnapshot blockSnapshot = new BlockSnapshot(player.world, pos, blockState);
// BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, blockState, player, hand);
// Mirror.onBlockPlaced(placeEvent);
// Array.onBlockPlaced(placeEvent);
}
return ActionResultType.SUCCESS;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
ItemStack bag = player.getHeldItem(hand);
if (player.isSneaking()) {
if (world.isRemote) return new ActionResult<>(ActionResultType.SUCCESS, bag);
//Open inventory
NetworkHooks.openGui((ServerPlayerEntity) player, new ContainerProvider(bag));
} else {
//Use item
//Get bag inventory
IItemHandler bagInventory = getBagInventory(bag);
if (bagInventory == null)
return new ActionResult<>(ActionResultType.FAIL, bag);
ItemStack toUse = pickRandomStack(bagInventory);
if (toUse.isEmpty()) return new ActionResult<>(ActionResultType.FAIL, bag);
return toUse.useItemRightClick(world, player, hand);
}
return new ActionResult<>(ActionResultType.PASS, bag);
}
@Override
public int getUseDuration(ItemStack p_77626_1_) {
return 1;
@@ -214,18 +229,9 @@ public class ItemRandomizerBag extends Item {
return this.getRegistryName().toString();
}
public static void resetRandomness() {
rand.setSeed(currentSeed);
}
public static void renewRandomness() {
currentSeed = Calendar.getInstance().getTimeInMillis();
rand.setSeed(currentSeed);
}
public static class ContainerProvider implements INamedContainerProvider {
private ItemStack bag;
private final ItemStack bag;
public ContainerProvider(ItemStack bag) {
this.bag = bag;

View File

@@ -1,5 +1,6 @@
package nl.requios.effortlessbuilding.item;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
@@ -16,8 +17,11 @@ import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ItemReachUpgrade1 extends Item {
public ItemReachUpgrade1() {
@@ -44,7 +48,8 @@ public class ItemReachUpgrade1 extends Item {
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("entity.player.levelup"));
player.playSound(soundEvent, 1f, 1f);
} else if (currentLevel > 0) {
if (world.isRemote) EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + ReachHelper
if (world.isRemote)
EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + ReachHelper
.getMaxReach(player) + ".");
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));

View File

@@ -1,5 +1,6 @@
package nl.requios.effortlessbuilding.item;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
@@ -16,8 +17,11 @@ import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ItemReachUpgrade2 extends Item {
public ItemReachUpgrade2() {
@@ -48,7 +52,8 @@ public class ItemReachUpgrade2 extends Item {
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));
player.playSound(soundEvent, 1f, 1f);
} else if (currentLevel > 1) {
if (world.isRemote) EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + ReachHelper
if (world.isRemote)
EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + ReachHelper
.getMaxReach(player) + ".");
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));

View File

@@ -1,5 +1,6 @@
package nl.requios.effortlessbuilding.item;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
@@ -16,8 +17,11 @@ import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ItemReachUpgrade3 extends Item {
public ItemReachUpgrade3() {
@@ -51,7 +55,8 @@ public class ItemReachUpgrade3 extends Item {
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));
player.playSound(soundEvent, 1f, 1f);
} else if (currentLevel > 2) {
if (world.isRemote) EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + ReachHelper
if (world.isRemote)
EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + ReachHelper
.getMaxReach(player) + ".");
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));

View File

@@ -5,7 +5,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.network.NetworkEvent;
import nl.requios.effortlessbuilding.EffortlessBuilding;
@@ -19,9 +19,9 @@ import java.util.function.Supplier;
* Sends a message to the client asking to add a block to the undo stack.
*/
public class AddUndoMessage {
private BlockPos coordinate;
private BlockState previousBlockState;
private BlockState newBlockState;
private final BlockPos coordinate;
private final BlockState previousBlockState;
private final BlockState newBlockState;
public AddUndoMessage() {
coordinate = BlockPos.ZERO;
@@ -35,18 +35,6 @@ public class AddUndoMessage {
this.newBlockState = newBlockState;
}
public BlockPos getCoordinate() {
return coordinate;
}
public BlockState getPreviousBlockState() {
return previousBlockState;
}
public BlockState getNewBlockState() {
return newBlockState;
}
public static void encode(AddUndoMessage message, PacketBuffer buf) {
buf.writeInt(message.coordinate.getX());
buf.writeInt(message.coordinate.getY());
@@ -62,10 +50,20 @@ public class AddUndoMessage {
return new AddUndoMessage(coordinate, previousBlockState, newBlockState);
}
public static class Handler
{
public static void handle(AddUndoMessage message, Supplier<NetworkEvent.Context> ctx)
{
public BlockPos getCoordinate() {
return coordinate;
}
public BlockState getPreviousBlockState() {
return previousBlockState;
}
public BlockState getNewBlockState() {
return newBlockState;
}
public static class Handler {
public static void handle(AddUndoMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
//Received clientside
@@ -74,10 +72,16 @@ public class AddUndoMessage {
//Add to undo stack clientside
//Only the appropriate player that needs to add this to the undo stack gets this message
UndoRedo.addUndo(player, new BlockSet(
new ArrayList<BlockPos>() {{add(message.getCoordinate());}},
new ArrayList<BlockState>() {{add(message.getPreviousBlockState());}},
new ArrayList<BlockState>() {{add(message.getNewBlockState());}},
new Vec3d(0,0,0),
new ArrayList<BlockPos>() {{
add(message.getCoordinate());
}},
new ArrayList<BlockState>() {{
add(message.getPreviousBlockState());
}},
new ArrayList<BlockState>() {{
add(message.getNewBlockState());
}},
new Vector3d(0, 0, 0),
message.getCoordinate(), message.getCoordinate()));
}
});

View File

@@ -5,10 +5,9 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.network.NetworkEvent;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.buildmode.BuildModes;
import java.util.function.Supplier;
@@ -18,16 +17,16 @@ import java.util.function.Supplier;
*/
public class BlockBrokenMessage {
private boolean blockHit;
private BlockPos blockPos;
private Direction sideHit;
private Vec3d hitVec;
private final boolean blockHit;
private final BlockPos blockPos;
private final Direction sideHit;
private final Vector3d hitVec;
public BlockBrokenMessage() {
this.blockHit = false;
this.blockPos = BlockPos.ZERO;
this.sideHit = Direction.UP;
this.hitVec = new Vec3d(0, 0, 0);
this.hitVec = new Vector3d(0, 0, 0);
}
public BlockBrokenMessage(BlockRayTraceResult result) {
@@ -37,29 +36,13 @@ public class BlockBrokenMessage {
this.hitVec = result.getHitVec();
}
public BlockBrokenMessage(boolean blockHit, BlockPos blockPos, Direction sideHit, Vec3d hitVec) {
public BlockBrokenMessage(boolean blockHit, BlockPos blockPos, Direction sideHit, Vector3d hitVec) {
this.blockHit = blockHit;
this.blockPos = blockPos;
this.sideHit = sideHit;
this.hitVec = hitVec;
}
public boolean isBlockHit() {
return blockHit;
}
public BlockPos getBlockPos() {
return blockPos;
}
public Direction getSideHit() {
return sideHit;
}
public Vec3d getHitVec() {
return hitVec;
}
public static void encode(BlockBrokenMessage message, PacketBuffer buf) {
buf.writeBoolean(message.blockHit);
buf.writeInt(message.blockPos.getX());
@@ -75,14 +58,28 @@ public class BlockBrokenMessage {
boolean blockHit = buf.readBoolean();
BlockPos blockPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
Direction sideHit = Direction.byIndex(buf.readInt());
Vec3d hitVec = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
Vector3d hitVec = new Vector3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
return new BlockBrokenMessage(blockHit, blockPos, sideHit, hitVec);
}
public static class Handler
{
public static void handle(BlockBrokenMessage message, Supplier<NetworkEvent.Context> ctx)
{
public boolean isBlockHit() {
return blockHit;
}
public BlockPos getBlockPos() {
return blockPos;
}
public Direction getSideHit() {
return sideHit;
}
public Vector3d getHitVec() {
return hitVec;
}
public static class Handler {
public static void handle(BlockBrokenMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.SERVER) {
//Received serverside

View File

@@ -1,14 +1,13 @@
package nl.requios.effortlessbuilding.network;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.network.NetworkEvent;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.buildmode.BuildModes;
import nl.requios.effortlessbuilding.render.BlockPreviewRenderer;
@@ -20,17 +19,17 @@ import java.util.function.Supplier;
*/
public class BlockPlacedMessage {
private boolean blockHit;
private BlockPos blockPos;
private Direction sideHit;
private Vec3d hitVec;
private boolean placeStartPos; //prevent double placing in normal mode
private final boolean blockHit;
private final BlockPos blockPos;
private final Direction sideHit;
private final Vector3d hitVec;
private final boolean placeStartPos; //prevent double placing in normal mode
public BlockPlacedMessage() {
this.blockHit = false;
this.blockPos = BlockPos.ZERO;
this.sideHit = Direction.UP;
this.hitVec = new Vec3d(0, 0, 0);
this.hitVec = new Vector3d(0, 0, 0);
this.placeStartPos = true;
}
@@ -42,7 +41,7 @@ public class BlockPlacedMessage {
this.placeStartPos = placeStartPos;
}
public BlockPlacedMessage(boolean blockHit, BlockPos blockPos, Direction sideHit, Vec3d hitVec, boolean placeStartPos) {
public BlockPlacedMessage(boolean blockHit, BlockPos blockPos, Direction sideHit, Vector3d hitVec, boolean placeStartPos) {
this.blockHit = blockHit;
this.blockPos = blockPos;
this.sideHit = sideHit;
@@ -50,26 +49,6 @@ public class BlockPlacedMessage {
this.placeStartPos = placeStartPos;
}
public boolean isBlockHit() {
return blockHit;
}
public BlockPos getBlockPos() {
return blockPos;
}
public Direction getSideHit() {
return sideHit;
}
public Vec3d getHitVec() {
return hitVec;
}
public boolean getPlaceStartPos() {
return placeStartPos;
}
public static void encode(BlockPlacedMessage message, PacketBuffer buf) {
buf.writeBoolean(message.blockHit);
buf.writeInt(message.blockPos.getX());
@@ -86,15 +65,33 @@ public class BlockPlacedMessage {
boolean blockHit = buf.readBoolean();
BlockPos blockPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
Direction sideHit = Direction.byIndex(buf.readInt());
Vec3d hitVec = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
Vector3d hitVec = new Vector3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
boolean placeStartPos = buf.readBoolean();
return new BlockPlacedMessage(blockHit, blockPos, sideHit, hitVec, placeStartPos);
}
public static class Handler
{
public static void handle(BlockPlacedMessage message, Supplier<NetworkEvent.Context> ctx)
{
public boolean isBlockHit() {
return blockHit;
}
public BlockPos getBlockPos() {
return blockPos;
}
public Direction getSideHit() {
return sideHit;
}
public Vector3d getHitVec() {
return hitVec;
}
public boolean getPlaceStartPos() {
return placeStartPos;
}
public static class Handler {
public static void handle(BlockPlacedMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
//Received clientside

View File

@@ -20,10 +20,8 @@ public class CancelModeMessage {
return new CancelModeMessage();
}
public static class Handler
{
public static void handle(CancelModeMessage message, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(CancelModeMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
PlayerEntity player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);

View File

@@ -25,10 +25,8 @@ public class ClearUndoMessage {
return new ClearUndoMessage();
}
public static class Handler
{
public static void handle(ClearUndoMessage message, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(ClearUndoMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
//Received clientside

View File

@@ -31,10 +31,8 @@ public class ModeActionMessage {
return new ModeActionMessage(action);
}
public static class Handler
{
public static void handle(ModeActionMessage message, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(ModeActionMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
PlayerEntity player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);

View File

@@ -34,10 +34,8 @@ public class ModeSettingsMessage {
return new ModeSettingsMessage(new ModeSettings(buildMode));
}
public static class Handler
{
public static void handle(ModeSettingsMessage message, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(ModeSettingsMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
PlayerEntity player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);

View File

@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.network;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.fml.network.NetworkEvent;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.buildmodifier.Array;
@@ -82,7 +82,7 @@ public class ModifierSettingsMessage {
Mirror.MirrorSettings m = new Mirror.MirrorSettings();
if (buf.readBoolean()) {
boolean mirrorEnabled = buf.readBoolean();
Vec3d mirrorPosition = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
Vector3d mirrorPosition = new Vector3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
boolean mirrorX = buf.readBoolean();
boolean mirrorY = buf.readBoolean();
boolean mirrorZ = buf.readBoolean();
@@ -110,7 +110,7 @@ public class ModifierSettingsMessage {
RadialMirror.RadialMirrorSettings r = new RadialMirror.RadialMirrorSettings();
if (buf.readBoolean()) {
boolean radialMirrorEnabled = buf.readBoolean();
Vec3d radialMirrorPosition = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
Vector3d radialMirrorPosition = new Vector3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
int radialMirrorSlices = buf.readInt();
boolean radialMirrorAlternate = buf.readBoolean();
int radialMirrorRadius = buf.readInt();
@@ -124,10 +124,8 @@ public class ModifierSettingsMessage {
return new ModifierSettingsMessage(modifierSettings);
}
public static class Handler
{
public static void handle(ModifierSettingsMessage message, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(ModifierSettingsMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
PlayerEntity player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);

View File

@@ -16,7 +16,7 @@ import java.util.function.Supplier;
* This is then sent back with a BlockPlacedMessage.
*/
public class RequestLookAtMessage {
private boolean placeStartPos;
private final boolean placeStartPos;
public RequestLookAtMessage() {
placeStartPos = false;
@@ -26,10 +26,6 @@ public class RequestLookAtMessage {
this.placeStartPos = placeStartPos;
}
public boolean getPlaceStartPos() {
return placeStartPos;
}
public static void encode(RequestLookAtMessage message, PacketBuffer buf) {
buf.writeBoolean(message.placeStartPos);
}
@@ -39,10 +35,12 @@ public class RequestLookAtMessage {
return new RequestLookAtMessage(placeStartPos);
}
public static class Handler
{
public static void handle(RequestLookAtMessage message, Supplier<NetworkEvent.Context> ctx)
{
public boolean getPlaceStartPos() {
return placeStartPos;
}
public static class Handler {
public static void handle(RequestLookAtMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
//Received clientside

View File

@@ -1,24 +1,18 @@
package nl.requios.effortlessbuilding.network;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.network.NetworkEvent;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.buildmodifier.BlockSet;
import nl.requios.effortlessbuilding.buildmodifier.UndoRedo;
import java.util.ArrayList;
import java.util.function.Supplier;
public class TranslatedLogMessage {
private String prefix;
private String translationKey;
private String suffix;
private boolean actionBar;
private final String prefix;
private final String translationKey;
private final String suffix;
private final boolean actionBar;
public TranslatedLogMessage() {
prefix = "";
@@ -34,6 +28,17 @@ public class TranslatedLogMessage {
this.actionBar = actionBar;
}
public static void encode(TranslatedLogMessage message, PacketBuffer buf) {
buf.writeString(message.prefix);
buf.writeString(message.translationKey);
buf.writeString(message.suffix);
buf.writeBoolean(message.actionBar);
}
public static TranslatedLogMessage decode(PacketBuffer buf) {
return new TranslatedLogMessage(buf.readString(), buf.readString(), buf.readString(), buf.readBoolean());
}
public String getPrefix() {
return prefix;
}
@@ -50,21 +55,8 @@ public class TranslatedLogMessage {
return actionBar;
}
public static void encode(TranslatedLogMessage message, PacketBuffer buf) {
buf.writeString(message.prefix);
buf.writeString(message.translationKey);
buf.writeString(message.suffix);
buf.writeBoolean(message.actionBar);
}
public static TranslatedLogMessage decode(PacketBuffer buf) {
return new TranslatedLogMessage(buf.readString(), buf.readString(), buf.readString(), buf.readBoolean());
}
public static class Handler
{
public static void handle(TranslatedLogMessage message, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(TranslatedLogMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
//Received clientside

View File

@@ -1,12 +1,12 @@
package nl.requios.effortlessbuilding.proxy;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings;
@@ -14,15 +14,17 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.client.settings.KeyModifier;
import net.minecraftforge.event.TickEvent;
@@ -49,58 +51,21 @@ import nl.requios.effortlessbuilding.network.*;
import nl.requios.effortlessbuilding.render.ShaderHandler;
import org.lwjgl.glfw.GLFW;
import javax.annotation.Nullable;
import java.util.HashMap;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Supplier;
@Mod.EventBusSubscriber(value = {Dist.CLIENT})
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ClientProxy implements IProxy {
public static KeyBinding[] keyBindings;
public static RayTraceResult previousLookAt;
public static RayTraceResult currentLookAt;
public static int ticksInGame = 0;
private static int placeCooldown = 0;
private static int breakCooldown = 0;
private static boolean shadersInitialized = false;
public static int ticksInGame = 0;
@Override
public void setup(FMLCommonSetupEvent event) {}
@Override
public void clientSetup(FMLClientSetupEvent event) {
// register key bindings
keyBindings = new KeyBinding[7];
// instantiate the key bindings
keyBindings[0] = new KeyBinding("key.effortlessbuilding.hud.desc", KeyConflictContext.UNIVERSAL, InputMappings.getInputByCode(GLFW.GLFW_KEY_KP_ADD, 0), "key.effortlessbuilding.category");
keyBindings[1] = new KeyBinding("key.effortlessbuilding.replace.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_KP_SUBTRACT, 0), "key.effortlessbuilding.category");
keyBindings[2] = new KeyBinding("key.effortlessbuilding.creative.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_F4, 0), "key.effortlessbuilding.category");
keyBindings[3] = new KeyBinding("key.effortlessbuilding.mode.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_LEFT_ALT, 0), "key.effortlessbuilding.category") {
@Override
public boolean conflicts(KeyBinding other) {
//Does not conflict with Chisels and Bits radial menu
if (other.getKey().getKeyCode() == getKey().getKeyCode() && other.getKeyDescription().equals("mod.chiselsandbits.other.mode")) return false;
return super.conflicts(other);
}
};
keyBindings[4] = new KeyBinding("key.effortlessbuilding.undo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputMappings.getInputByCode(GLFW.GLFW_KEY_Z, 0), "key.effortlessbuilding.category");
keyBindings[5] = new KeyBinding("key.effortlessbuilding.redo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputMappings.getInputByCode(GLFW.GLFW_KEY_Y, 0), "key.effortlessbuilding.category");
keyBindings[6] = new KeyBinding("key.effortlessbuilding.altplacement.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_LEFT_CONTROL, 0), "key.effortlessbuilding.category");
//keyBindings[7] = new KeyBinding("Reload shaders", KeyConflictContext.UNIVERSAL, InputMappings.getInputByCode(GLFW.GLFW_KEY_TAB, 0), "key.effortlessbuilding.category");
// register all the key bindings
for (int i = 0; i < keyBindings.length; ++i) {
ClientRegistry.registerKeyBinding(keyBindings[i]);
}
DeferredWorkQueue.runLater( () -> ScreenManager.registerFactory(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER, RandomizerBagScreen::new));
}
public PlayerEntity getPlayerEntityFromContext(Supplier<NetworkEvent.Context> ctx){
return (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT ? Minecraft.getInstance().player : ctx.get().getSender());
}
@SubscribeEvent
public static void onClientTick(TickEvent.ClientTickEvent event) {
@@ -186,7 +151,7 @@ public class ClientProxy implements IProxy {
BlockPos blockPos = blockLookingAt.getPos();
SoundType soundType = state.getBlock().getSoundType(state, player.world, blockPos, player);
player.world.playSound(player, player.getPosition(), soundType.getPlaceSound(), SoundCategory.BLOCKS,
0.4f, soundType.getPitch() * 1f);
0.4f, soundType.getPitch());
player.swingArm(Hand.MAIN_HAND);
}
} else {
@@ -194,8 +159,7 @@ public class ClientProxy implements IProxy {
PacketHandler.INSTANCE.sendToServer(new BlockPlacedMessage());
}
}
}
else if (buildMode == BuildModes.BuildModeEnum.NORMAL_PLUS) {
} else if (buildMode == BuildModes.BuildModeEnum.NORMAL_PLUS) {
placeCooldown--;
if (ModeOptions.getBuildSpeed() == ModeOptions.ActionEnum.FAST_SPEED) placeCooldown = 0;
}
@@ -229,15 +193,14 @@ public class ClientProxy implements IProxy {
BlockState state = player.world.getBlockState(blockPos);
SoundType soundtype = state.getBlock().getSoundType(state, player.world, blockPos, player);
player.world.playSound(player, player.getPosition(), soundtype.getBreakSound(), SoundCategory.BLOCKS,
0.4f, soundtype.getPitch() * 1f);
0.4f, soundtype.getPitch());
player.swingArm(Hand.MAIN_HAND);
}
} else {
BuildModes.onBlockBrokenMessage(player, new BlockBrokenMessage());
PacketHandler.INSTANCE.sendToServer(new BlockBrokenMessage());
}
}
else if (buildMode == BuildModes.BuildModeEnum.NORMAL_PLUS) {
} else if (buildMode == BuildModes.BuildModeEnum.NORMAL_PLUS) {
breakCooldown--;
if (ModeOptions.getBuildSpeed() == ModeOptions.ActionEnum.FAST_SPEED) breakCooldown = 0;
}
@@ -252,6 +215,8 @@ public class ClientProxy implements IProxy {
@SubscribeEvent(receiveCanceled = true)
public static void onKeyPress(InputEvent.KeyInputEvent event) {
ClientPlayerEntity player = Minecraft.getInstance().player;
if (player == null)
return;
//Remember to send packet to server if necessary
//Show Modifier Settings GUI
@@ -320,6 +285,8 @@ public class ClientProxy implements IProxy {
public static void openModifierSettings() {
Minecraft mc = Minecraft.getInstance();
ClientPlayerEntity player = mc.player;
if (player == null)
return;
RadialMenu.instance.setVisibility(0f);
@@ -338,6 +305,8 @@ public class ClientProxy implements IProxy {
public static void openPlayerSettings() {
Minecraft mc = Minecraft.getInstance();
ClientPlayerEntity player = mc.player;
if (player == null)
return;
RadialMenu.instance.setVisibility(0f);
@@ -357,21 +326,59 @@ public class ClientProxy implements IProxy {
}
}
@Nullable
public static RayTraceResult getLookingAt(PlayerEntity player) {
World world = player.world;
//base distance off of player ability (config)
float raytraceRange = ReachHelper.getPlacementReach(player);
Vec3d look = player.getLookVec();
Vec3d start = new Vec3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
Vec3d end = new Vec3d(player.getPosX() + look.x * raytraceRange, player.getPosY() + player.getEyeHeight() + look.y * raytraceRange, player.getPosZ() + look.z * raytraceRange);
Vector3d look = player.getLookVec();
Vector3d start = new Vector3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());
Vector3d end = new Vector3d(player.getPosX() + look.x * raytraceRange, player.getPosY() + player.getEyeHeight() + look.y * raytraceRange, player.getPosZ() + look.z * raytraceRange);
// return player.rayTrace(raytraceRange, 1f, RayTraceFluidMode.NEVER);
//TODO 1.14 check if correct
return world.rayTraceBlocks(new RayTraceContext(start, end, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, player));
}
@Override
public void setup(FMLCommonSetupEvent event) {
}
@Override
public void clientSetup(FMLClientSetupEvent event) {
// register key bindings
keyBindings = new KeyBinding[7];
// instantiate the key bindings
keyBindings[0] = new KeyBinding("key.effortlessbuilding.hud.desc", KeyConflictContext.UNIVERSAL, InputMappings.getInputByCode(GLFW.GLFW_KEY_KP_ADD, 0), "key.effortlessbuilding.category");
keyBindings[1] = new KeyBinding("key.effortlessbuilding.replace.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_KP_SUBTRACT, 0), "key.effortlessbuilding.category");
keyBindings[2] = new KeyBinding("key.effortlessbuilding.creative.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_F4, 0), "key.effortlessbuilding.category");
keyBindings[3] = new KeyBinding("key.effortlessbuilding.mode.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_LEFT_ALT, 0), "key.effortlessbuilding.category") {
@Override
public boolean conflicts(KeyBinding other) {
//Does not conflict with Chisels and Bits radial menu
if (other.getKey().getKeyCode() == getKey().getKeyCode() && other.getKeyDescription().equals("mod.chiselsandbits.other.mode"))
return false;
return super.conflicts(other);
}
};
keyBindings[4] = new KeyBinding("key.effortlessbuilding.undo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputMappings.getInputByCode(GLFW.GLFW_KEY_Z, 0), "key.effortlessbuilding.category");
keyBindings[5] = new KeyBinding("key.effortlessbuilding.redo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputMappings.getInputByCode(GLFW.GLFW_KEY_Y, 0), "key.effortlessbuilding.category");
keyBindings[6] = new KeyBinding("key.effortlessbuilding.altplacement.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_LEFT_CONTROL, 0), "key.effortlessbuilding.category");
//keyBindings[7] = new KeyBinding("Reload shaders", KeyConflictContext.UNIVERSAL, InputMappings.getInputByCode(GLFW.GLFW_KEY_TAB, 0), "key.effortlessbuilding.category");
// register all the key bindings
for (KeyBinding keyBinding : keyBindings) {
ClientRegistry.registerKeyBinding(keyBinding);
}
DeferredWorkQueue.runLater(() -> ScreenManager.registerFactory(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER, RandomizerBagScreen::new));
}
public PlayerEntity getPlayerEntityFromContext(Supplier<NetworkEvent.Context> ctx) {
return (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT ? Minecraft.getInstance().player : ctx.get().getSender());
}
@Override
public void logTranslate(PlayerEntity player, String prefix, String translationKey, String suffix, boolean actionBar) {
EffortlessBuilding.log(Minecraft.getInstance().player, prefix + I18n.format(translationKey) + suffix, actionBar);

View File

@@ -19,7 +19,8 @@ public class ServerProxy implements IProxy {
}
@Override
public void clientSetup(FMLClientSetupEvent event) {}
public void clientSetup(FMLClientSetupEvent event) {
}
public PlayerEntity getPlayerEntityFromContext(Supplier<NetworkEvent.Context> ctx) {
return ctx.get().getSender();

View File

@@ -1,7 +1,6 @@
package nl.requios.effortlessbuilding.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
@@ -9,13 +8,16 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import nl.requios.effortlessbuilding.BuildConfig;
@@ -32,15 +34,14 @@ import nl.requios.effortlessbuilding.helper.ReachHelper;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import org.lwjgl.opengl.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
@OnlyIn(Dist.CLIENT)
public class BlockPreviewRenderer {
private static final List<PlacedData> placedDataList = new ArrayList<>();
private static List<BlockPos> previousCoordinates;
private static List<BlockState> previousBlockStates;
private static List<ItemStack> previousItemStacks;
@@ -48,29 +49,6 @@ public class BlockPreviewRenderer {
private static BlockPos previousSecondPos;
private static int soundTime = 0;
static class PlacedData {
float time;
List<BlockPos> coordinates;
List<BlockState> blockStates;
List<ItemStack> itemStacks;
BlockPos firstPos;
BlockPos secondPos;
boolean breaking;
public PlacedData(float time, List<BlockPos> coordinates, List<BlockState> blockStates,
List<ItemStack> itemStacks, BlockPos firstPos, BlockPos secondPos, boolean breaking) {
this.time = time;
this.coordinates = coordinates;
this.blockStates = blockStates;
this.itemStacks = itemStacks;
this.firstPos = firstPos;
this.secondPos = secondPos;
this.breaking = breaking;
}
}
private static List<PlacedData> placedDataList = new ArrayList<>();
public static void render(MatrixStack matrixStack, IRenderTypeBuffer.Impl renderTypeBuffer, PlayerEntity player, ModifierSettings modifierSettings, ModeSettings modeSettings) {
//Render placed blocks with dissolve effect
@@ -94,14 +72,15 @@ public class BlockPreviewRenderer {
//Render block previews
RayTraceResult lookingAt = ClientProxy.getLookingAt(player);
if (modeSettings.getBuildMode() == BuildModes.BuildModeEnum.NORMAL) lookingAt = Minecraft.getInstance().objectMouseOver;
if (modeSettings.getBuildMode() == BuildModes.BuildModeEnum.NORMAL)
lookingAt = Minecraft.getInstance().objectMouseOver;
ItemStack mainhand = player.getHeldItemMainhand();
boolean toolInHand = !(!mainhand.isEmpty() && CompatHelper.isItemBlockProxy(mainhand));
BlockPos startPos = null;
Direction sideHit = null;
Vec3d hitVec = null;
Vector3d hitVec = null;
//Checking for null is necessary! Even in vanilla when looking down ladders it is occasionally null (instead of Type MISS)
if (lookingAt != null && lookingAt.getType() == RayTraceResult.Type.BLOCK) {
@@ -110,7 +89,7 @@ public class BlockPreviewRenderer {
//Check if tool (or none) in hand
//TODO 1.13 replaceable
boolean replaceable = player.world.getBlockState(startPos).getBlock().getMaterial(player.world.getBlockState(startPos)).isReplaceable();
boolean replaceable = player.world.getBlockState(startPos).getMaterial().isReplaceable();
boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos, blockLookingAt.getFace());
if (!modifierSettings.doQuickReplace() && !toolInHand && !replaceable && !becomesDoubleSlab) {
startPos = startPos.offset(blockLookingAt.getFace());
@@ -162,7 +141,7 @@ public class BlockPreviewRenderer {
sortOnDistanceToPlayer(newCoordinates, player);
hitVec = new Vec3d(Math.abs(hitVec.x - ((int) hitVec.x)), Math.abs(hitVec.y - ((int) hitVec.y)),
hitVec = new Vector3d(Math.abs(hitVec.x - ((int) hitVec.x)), Math.abs(hitVec.y - ((int) hitVec.y)),
Math.abs(hitVec.z - ((int) hitVec.z)));
//Get blockstates
@@ -213,8 +192,8 @@ public class BlockPreviewRenderer {
} else {
IVertexBuilder buffer = RenderHandler.beginLines(renderTypeBuffer);
Vec3d color = new Vec3d(1f, 1f, 1f);
if (breaking) color = new Vec3d(1f, 0f, 0f);
Vector3d color = new Vector3d(1f, 1f, 1f);
if (breaking) color = new Vector3d(1f, 0f, 0f);
for (int i = newCoordinates.size() - 1; i >= 0; i--) {
VoxelShape collisionShape = blockStates.get(i).getCollisionShape(player.world, newCoordinates.get(i));
@@ -275,7 +254,7 @@ public class BlockPreviewRenderer {
if (!blockState.getBlock().isAir(blockState, player.world, coordinate)) {
if (SurvivalHelper.canBreak(player.world, player, coordinate) || i == 0) {
VoxelShape collisionShape = blockState.getCollisionShape(player.world, coordinate);
RenderHandler.renderBlockOutline(matrixStack, buffer, coordinate, collisionShape, new Vec3d(0f, 0f, 0f));
RenderHandler.renderBlockOutline(matrixStack, buffer, coordinate, collisionShape, new Vector3d(0f, 0f, 0f));
}
}
}
@@ -370,15 +349,35 @@ public class BlockPreviewRenderer {
}
private static void sortOnDistanceToPlayer(List<BlockPos> coordinates, PlayerEntity player) {
Collections.sort(coordinates, (lhs, rhs) -> {
// -1 - less than, 1 - greater than, 0 - equal
double lhsDistanceToPlayer = new Vec3d(lhs).subtract(player.getEyePosition(1f)).lengthSquared();
double rhsDistanceToPlayer = new Vec3d(rhs).subtract(player.getEyePosition(1f)).lengthSquared();
double lhsDistanceToPlayer = Vector3d.copy(lhs).subtract(player.getEyePosition(1f)).lengthSquared();
double rhsDistanceToPlayer = Vector3d.copy(rhs).subtract(player.getEyePosition(1f)).lengthSquared();
return (int) Math.signum(lhsDistanceToPlayer - rhsDistanceToPlayer);
});
}
static class PlacedData {
float time;
List<BlockPos> coordinates;
List<BlockState> blockStates;
List<ItemStack> itemStacks;
BlockPos firstPos;
BlockPos secondPos;
boolean breaking;
public PlacedData(float time, List<BlockPos> coordinates, List<BlockState> blockStates,
List<ItemStack> itemStacks, BlockPos firstPos, BlockPos secondPos, boolean breaking) {
this.time = time;
this.coordinates = coordinates;
this.blockStates = blockStates;
this.itemStacks = itemStacks;
this.firstPos = firstPos;
this.secondPos = secondPos;
this.breaking = breaking;
}
}
}

View File

@@ -1,6 +1,5 @@
package nl.requios.effortlessbuilding.render;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderState;
@@ -8,9 +7,8 @@ import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import org.lwjgl.opengl.*;
import java.util.OptionalDouble;
@@ -45,7 +43,7 @@ public class BuildRenderTypes {
DIFFUSE_LIGHTING_ENABLED = new RenderState.DiffuseLightingState(true);
DIFFUSE_LIGHTING_DISABLED = new RenderState.DiffuseLightingState(false);
PROJECTION_LAYERING = ObfuscationReflectionHelper.getPrivateValue(RenderState.class, null, "field_228500_J_");
PROJECTION_LAYERING = ObfuscationReflectionHelper.getPrivateValue(RenderState.class, null, "field_239235_M_");
CULL_DISABLED = new RenderState.CullState(false);
@@ -92,22 +90,6 @@ public class BuildRenderTypes {
}
private class ShaderInfo {
float dissolve;
Vec3d blockPos;
Vec3d firstPos;
Vec3d secondPos;
boolean red;
public ShaderInfo(float dissolve, Vec3d blockPos, Vec3d firstPos, Vec3d secondPos, boolean red) {
this.dissolve = dissolve;
this.blockPos = blockPos;
this.firstPos = firstPos;
this.secondPos = secondPos;
this.red = red;
}
}
public static RenderType getBlockPreviewRenderType(float dissolve, BlockPos blockPos, BlockPos firstPos,
BlockPos secondPos, boolean red) {
// RenderSystem.pushLightingAttributes();
@@ -129,11 +111,9 @@ public class BuildRenderTypes {
// RenderSystem.pushLightingAttributes();
// RenderSystem.pushTextureAttributes();
ShaderHandler.useShader(ShaderHandler.dissolve, generateShaderCallback(dissolve, new Vec3d(blockPos), new Vec3d(firstPos), new Vec3d(secondPos), blockPos == secondPos, red));
ShaderHandler.useShader(ShaderHandler.dissolve, generateShaderCallback(dissolve, Vector3d.copy(blockPos), Vector3d.copy(firstPos), Vector3d.copy(secondPos), blockPos == secondPos, red));
RenderSystem.blendColor(1f, 1f, 1f, 0.8f);
}, () -> {
ShaderHandler.releaseShader();
});
}, ShaderHandler::releaseShader);
RenderType.State renderState = RenderType.State.getBuilder()
.texture(new RenderState.TextureState(ShaderHandler.shaderMaskTextureLocation, false, false))
@@ -151,9 +131,8 @@ public class BuildRenderTypes {
DefaultVertexFormats.BLOCK, GL11.GL_QUADS, 256, true, true, renderState);
}
private static Consumer<Integer> generateShaderCallback(final float dissolve, final Vec3d blockpos,
final Vec3d firstpos, final Vec3d secondpos,
private static Consumer<Integer> generateShaderCallback(final float dissolve, final Vector3d blockpos,
final Vector3d firstpos, final Vector3d secondpos,
final boolean highlight, final boolean red) {
Minecraft mc = Minecraft.getInstance();
return (Integer shader) -> {
@@ -204,17 +183,33 @@ public class BuildRenderTypes {
}
private class ShaderInfo {
float dissolve;
Vector3d blockPos;
Vector3d firstPos;
Vector3d secondPos;
boolean red;
public ShaderInfo(float dissolve, Vector3d blockPos, Vector3d firstPos, Vector3d secondPos, boolean red) {
this.dissolve = dissolve;
this.blockPos = blockPos;
this.firstPos = firstPos;
this.secondPos = secondPos;
this.red = red;
}
}
// public static class MyTexturingState extends RenderState.TexturingState {
//
// public float dissolve;
// public Vec3d blockPos;
// public Vec3d firstPos;
// public Vec3d secondPos;
// public Vector3d blockPos;
// public Vector3d firstPos;
// public Vector3d secondPos;
// public boolean highlight;
// public boolean red;
//
// public MyTexturingState(String p_i225989_1_, float dissolve, Vec3d blockPos, Vec3d firstPos,
// Vec3d secondPos, boolean highlight, boolean red, Runnable p_i225989_2_, Runnable p_i225989_3_) {
// public MyTexturingState(String p_i225989_1_, float dissolve, Vector3d blockPos, Vector3d firstPos,
// Vector3d secondPos, boolean highlight, boolean red, Runnable p_i225989_2_, Runnable p_i225989_3_) {
// super(p_i225989_1_, p_i225989_2_, p_i225989_3_);
// this.dissolve = dissolve;
// this.blockPos = blockPos;

View File

@@ -2,18 +2,14 @@ package nl.requios.effortlessbuilding.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.Matrix4f;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import nl.requios.effortlessbuilding.buildmodifier.Mirror;
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
import org.lwjgl.opengl.GL11;
import java.awt.*;
@@ -26,63 +22,57 @@ public class ModifierRenderer {
protected static final Color colorRadial = new Color(52, 247, 255);
protected static final int lineAlpha = 200;
protected static final int planeAlpha = 75;
protected static final Vec3d epsilon = new Vec3d(0.001, 0.001, 0.001); //prevents z-fighting
protected static final Vector3d epsilon = new Vector3d(0.001, 0.001, 0.001); //prevents z-fighting
public static void render(MatrixStack matrixStack, IRenderTypeBuffer.Impl renderTypeBuffer, ModifierSettingsManager.ModifierSettings modifierSettings) {
//Mirror lines and areas
Mirror.MirrorSettings m = modifierSettings.getMirrorSettings();
if (m != null && m.enabled && (m.mirrorX || m.mirrorY || m.mirrorZ))
{
Vec3d pos = m.position.add(epsilon);
if (m != null && m.enabled && (m.mirrorX || m.mirrorY || m.mirrorZ)) {
Vector3d pos = m.position.add(epsilon);
int radius = m.radius;
if (m.mirrorX)
{
Vec3d posA = new Vec3d(pos.x, pos.y - radius, pos.z - radius);
Vec3d posB = new Vec3d(pos.x, pos.y + radius, pos.z + radius);
if (m.mirrorX) {
Vector3d posA = new Vector3d(pos.x, pos.y - radius, pos.z - radius);
Vector3d posB = new Vector3d(pos.x, pos.y + radius, pos.z + radius);
drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorX, m.drawLines, m.drawPlanes, true);
}
if (m.mirrorY)
{
Vec3d posA = new Vec3d(pos.x - radius, pos.y, pos.z - radius);
Vec3d posB = new Vec3d(pos.x + radius, pos.y, pos.z + radius);
if (m.mirrorY) {
Vector3d posA = new Vector3d(pos.x - radius, pos.y, pos.z - radius);
Vector3d posB = new Vector3d(pos.x + radius, pos.y, pos.z + radius);
drawMirrorPlaneY(matrixStack, renderTypeBuffer, posA, posB, colorY, m.drawLines, m.drawPlanes);
}
if (m.mirrorZ)
{
Vec3d posA = new Vec3d(pos.x - radius, pos.y - radius, pos.z);
Vec3d posB = new Vec3d(pos.x + radius, pos.y + radius, pos.z);
if (m.mirrorZ) {
Vector3d posA = new Vector3d(pos.x - radius, pos.y - radius, pos.z);
Vector3d posB = new Vector3d(pos.x + radius, pos.y + radius, pos.z);
drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorZ, m.drawLines, m.drawPlanes, true);
}
//Draw axis coordinated colors if two or more axes are enabled
//(If only one is enabled the lines are that planes color)
if (m.drawLines && ((m.mirrorX && m.mirrorY) || (m.mirrorX && m.mirrorZ) || (m.mirrorY && m.mirrorZ)))
{
if (m.drawLines && ((m.mirrorX && m.mirrorY) || (m.mirrorX && m.mirrorZ) || (m.mirrorY && m.mirrorZ))) {
drawMirrorLines(matrixStack, renderTypeBuffer, m);
}
}
//Radial mirror lines and areas
RadialMirror.RadialMirrorSettings r = modifierSettings.getRadialMirrorSettings();
if (r != null && r.enabled)
{
Vec3d pos = r.position.add(epsilon);
if (r != null && r.enabled) {
Vector3d pos = r.position.add(epsilon);
int radius = r.radius;
float angle = 2f * ((float) Math.PI) / r.slices;
Vec3d relStartVec = new Vec3d(radius, 0, 0);
Vector3d relStartVec = new Vector3d(radius, 0, 0);
if (r.slices % 4 == 2) relStartVec = relStartVec.rotateYaw(angle / 2f);
for (int i = 0; i < r.slices; i++) {
Vec3d relNewVec = relStartVec.rotateYaw(angle * i);
Vec3d newVec = pos.add(relNewVec);
Vector3d relNewVec = relStartVec.rotateYaw(angle * i);
Vector3d newVec = pos.add(relNewVec);
Vec3d posA = new Vec3d(pos.x, pos.y - radius, pos.z);
Vec3d posB = new Vec3d(newVec.x, pos.y + radius, newVec.z);
Vector3d posA = new Vector3d(pos.x, pos.y - radius, pos.z);
Vector3d posB = new Vector3d(newVec.x, pos.y + radius, newVec.z);
drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorRadial, r.drawLines, r.drawPlanes, false);
}
}
@@ -91,7 +81,7 @@ public class ModifierRenderer {
//----Mirror----
protected static void drawMirrorPlane(MatrixStack matrixStack, IRenderTypeBuffer.Impl renderTypeBuffer, Vec3d posA, Vec3d posB, Color c, boolean drawLines, boolean drawPlanes, boolean drawVerticalLines) {
protected static void drawMirrorPlane(MatrixStack matrixStack, IRenderTypeBuffer.Impl renderTypeBuffer, Vector3d posA, Vector3d posB, Color c, boolean drawLines, boolean drawPlanes, boolean drawVerticalLines) {
// GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha);
Matrix4f matrixPos = matrixStack.getLast().getMatrix();
@@ -113,7 +103,7 @@ public class ModifierRenderer {
if (drawLines) {
IVertexBuilder buffer = RenderHandler.beginLines(renderTypeBuffer);
Vec3d middle = posA.add(posB).scale(0.5);
Vector3d middle = posA.add(posB).scale(0.5);
buffer.pos(matrixPos, (float) posA.x, (float) middle.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
buffer.pos(matrixPos, (float) posB.x, (float) middle.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
if (drawVerticalLines) {
@@ -125,7 +115,7 @@ public class ModifierRenderer {
}
}
protected static void drawMirrorPlaneY(MatrixStack matrixStack, IRenderTypeBuffer.Impl renderTypeBuffer, Vec3d posA, Vec3d posB, Color c, boolean drawLines, boolean drawPlanes) {
protected static void drawMirrorPlaneY(MatrixStack matrixStack, IRenderTypeBuffer.Impl renderTypeBuffer, Vector3d posA, Vector3d posB, Color c, boolean drawLines, boolean drawPlanes) {
// GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
Matrix4f matrixPos = matrixStack.getLast().getMatrix();
@@ -147,7 +137,7 @@ public class ModifierRenderer {
if (drawLines) {
IVertexBuilder buffer = RenderHandler.beginLines(renderTypeBuffer);
Vec3d middle = posA.add(posB).scale(0.5);
Vector3d middle = posA.add(posB).scale(0.5);
buffer.pos(matrixPos, (float) middle.x, (float) middle.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
buffer.pos(matrixPos, (float) middle.x, (float) middle.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
buffer.pos(matrixPos, (float) posA.x, (float) middle.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
@@ -163,7 +153,7 @@ public class ModifierRenderer {
IVertexBuilder buffer = RenderHandler.beginLines(renderTypeBuffer);
Matrix4f matrixPos = matrixStack.getLast().getMatrix();
Vec3d pos = m.position.add(epsilon);
Vector3d pos = m.position.add(epsilon);
buffer.pos(matrixPos, (float) pos.x - m.radius, (float) pos.y, (float) pos.z).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
buffer.pos(matrixPos, (float) pos.x + m.radius, (float) pos.y, (float) pos.z).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();

View File

@@ -1,11 +1,8 @@
package nl.requios.effortlessbuilding.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SimpleSound;
import net.minecraft.client.entity.player.ClientPlayerEntity;
@@ -15,19 +12,15 @@ import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@@ -41,7 +34,6 @@ import nl.requios.effortlessbuilding.network.ModeActionMessage;
import nl.requios.effortlessbuilding.network.ModeSettingsMessage;
import nl.requios.effortlessbuilding.network.PacketHandler;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import org.lwjgl.opengl.GL11;
/***
* Main render class for Effortless Building
@@ -57,12 +49,14 @@ public class RenderHandler {
MatrixStack matrixStack = event.getMatrixStack();
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
IRenderTypeBuffer.Impl renderTypeBuffer = IRenderTypeBuffer.getImpl(bufferBuilder);
if (renderTypeBuffer == null)
return;
PlayerEntity player = Minecraft.getInstance().player;
ModeSettingsManager.ModeSettings modeSettings = ModeSettingsManager.getModeSettings(player);
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
Vec3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
Vector3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
matrixStack.push();
matrixStack.translate(-projectedView.x, -projectedView.y, -projectedView.z);
@@ -141,7 +135,7 @@ public class RenderHandler {
final int mouseX = ((int) mc.mouseHelper.getMouseX()) * scaledWidth / mc.getMainWindow().getFramebufferWidth();
final int mouseY = scaledHeight - ((int) mc.mouseHelper.getMouseY()) * scaledHeight / mc.getMainWindow().getFramebufferHeight() - 1;
net.minecraftforge.client.ForgeHooksClient.drawScreen(RadialMenu.instance, mouseX, mouseY, event.getPartialTicks());
net.minecraftforge.client.ForgeHooksClient.drawScreen(RadialMenu.instance, event.getMatrixStack(), mouseX, mouseY, event.getPartialTicks());
} else {
if (wasVisible &&
RadialMenu.instance.doAction != ModeOptions.ActionEnum.OPEN_MODIFIER_SETTINGS &&
@@ -206,9 +200,9 @@ public class RenderHandler {
matrixStack.pop();
renderTypeBuffer.finish();
IVertexBuilder lineBuffer = beginLines(renderTypeBuffer);
renderBlockOutline(matrixStack, lineBuffer, blockPos, new Vec3d(1f, 1f, 1f));
renderBlockOutline(matrixStack, lineBuffer, blockPos, new Vector3d(1f, 1f, 1f));
endLines(renderTypeBuffer);
buffer = renderTypeBuffer.getBuffer(Atlases.getTranslucentBlockType()); //any type will do, as long as we have something on the stack
buffer = renderTypeBuffer.getBuffer(Atlases.getTranslucentCullBlockType()); //any type will do, as long as we have something on the stack
matrixStack.push();
}
@@ -216,12 +210,12 @@ public class RenderHandler {
matrixStack.pop();
}
protected static void renderBlockOutline(MatrixStack matrixStack, IVertexBuilder buffer, BlockPos pos, Vec3d color) {
protected static void renderBlockOutline(MatrixStack matrixStack, IVertexBuilder buffer, BlockPos pos, Vector3d color) {
renderBlockOutline(matrixStack, buffer, pos, pos, color);
}
//Renders outline. Pos1 has to be minimal x,y,z and pos2 maximal x,y,z
protected static void renderBlockOutline(MatrixStack matrixStack, IVertexBuilder buffer, BlockPos pos1, BlockPos pos2, Vec3d color) {
protected static void renderBlockOutline(MatrixStack matrixStack, IVertexBuilder buffer, BlockPos pos1, BlockPos pos2, Vector3d color) {
AxisAlignedBB aabb = new AxisAlignedBB(pos1, pos2.add(1, 1, 1)).grow(0.0020000000949949026);
WorldRenderer.drawBoundingBox(matrixStack, buffer, aabb, (float) color.x, (float) color.y, (float) color.z, 0.4f);
@@ -229,7 +223,7 @@ public class RenderHandler {
}
//Renders outline with given bounding box
protected static void renderBlockOutline(MatrixStack matrixStack, IVertexBuilder buffer, BlockPos pos, VoxelShape collisionShape, Vec3d color) {
protected static void renderBlockOutline(MatrixStack matrixStack, IVertexBuilder buffer, BlockPos pos, VoxelShape collisionShape, Vector3d color) {
// WorldRenderer.drawShape(collisionShape, pos.getX(), pos.getY(), pos.getZ(), (float) color.x, (float) color.y, (float) color.z, 0.4f);
WorldRenderer.drawVoxelShapeParts(matrixStack, buffer, collisionShape, pos.getX(), pos.getY(), pos.getZ(), (float) color.x, (float) color.y, (float) color.z, 0.4f);
}

View File

@@ -2,12 +2,12 @@
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* <p>
* Modified by Requios
*
* <p>
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* <p>
* File Created @ [Apr 9, 2014, 11:20:26 PM (GMT)]
*/
package nl.requios.effortlessbuilding.render;
@@ -140,8 +140,7 @@ public final class ShaderHandler {
throw new RuntimeException("Error creating shader: " + getLogInfo(shader));
return shader;
}
catch(Exception e) {
} catch (Exception e) {
ARBShaderObjects.glDeleteObjectARB(shader);
e.printStackTrace();
return -1;

View File

@@ -0,0 +1,2 @@
public net.minecraft.client.gui.widget.list.AbstractList field_230680_q_ # renderHeader
public net.minecraft.client.gui.FontRenderer func_228078_a_(Ljava/lang/String;FFILnet/minecraft/util/math/vector/Matrix4f;ZZ)I # renderString

View File

@@ -6,7 +6,8 @@
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[31,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
loaderVersion="[34,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
license="GNU LESSER GENERAL PUBLIC LICENSE"
# A URL to refer people to when problems occur with this mod
issueTrackerURL="http://my.issue.tracker/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
@@ -38,7 +39,7 @@ Makes building easier by providing tools like mirrors, arrays, QuickReplace and
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[31,)" #mandatory
versionRange="[34,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
@@ -47,6 +48,6 @@ Makes building easier by providing tools like mirrors, arrays, QuickReplace and
[[dependencies.examplemod]]
modId="minecraft"
mandatory=true
versionRange="[1.15.2]"
versionRange="[1.16.3,1.17)"
ordering="NONE"
side="BOTH"