diff --git a/src/main/java/com/simibubi/create/AllKeys.java b/src/main/java/com/simibubi/create/AllKeys.java new file mode 100644 index 000000000..2baa4a4c1 --- /dev/null +++ b/src/main/java/com/simibubi/create/AllKeys.java @@ -0,0 +1,72 @@ +package com.simibubi.create; + +import org.lwjgl.glfw.GLFW; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.settings.KeyBinding; +import net.minecraftforge.fml.client.registry.ClientRegistry; + +public enum AllKeys { + + TOOL_MENU("Tool Menu (Hold)", GLFW.GLFW_KEY_LEFT_ALT), + ACTIVATE_TOOL("", GLFW.GLFW_KEY_LEFT_CONTROL), + + ; + + private KeyBinding keybind; + private String description; + private int key; + private boolean modifiable; + + private AllKeys(String description, int defaultKey) { + this.description = description; + this.key = defaultKey; + this.modifiable = !description.isEmpty(); + } + + public static void register() { + for (AllKeys key : values()) { + key.keybind = new KeyBinding(key.description, key.key, Create.NAME); + if (!key.modifiable) + continue; + + ClientRegistry.registerKeyBinding(key.keybind); + } + } + + public KeyBinding getKeybind() { + return keybind; + } + + public boolean isPressed() { + if (!modifiable) + return isKeyDown(key); + return keybind.isKeyDown(); + } + + public String getBoundKey() { + return keybind.getLocalizedName().toUpperCase(); + } + + public int getBoundCode() { + return keybind.getKey().getKeyCode(); + } + + public static boolean isKeyDown(int key) { + return GLFW.glfwGetKey(Minecraft.getInstance().mainWindow.getHandle(), key) != 0; + } + + public static boolean ctrlDown() { + return Screen.hasControlDown(); + } + + public static boolean shiftDown() { + return Screen.hasShiftDown(); + } + + public static boolean altDown() { + return Screen.hasAltDown(); + } + +} diff --git a/src/main/java/com/simibubi/create/ClientEvents.java b/src/main/java/com/simibubi/create/ClientEvents.java new file mode 100644 index 000000000..ec4be586e --- /dev/null +++ b/src/main/java/com/simibubi/create/ClientEvents.java @@ -0,0 +1,108 @@ +package com.simibubi.create; + +import com.simibubi.create.foundation.gui.ScreenOpener; +import com.simibubi.create.modules.contraptions.receivers.TurntableHandler; +import com.simibubi.create.modules.contraptions.relays.belt.BeltItemHandler; + +import net.minecraft.client.Minecraft; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.client.event.GuiScreenEvent.MouseScrollEvent; +import net.minecraftforge.client.event.InputEvent.KeyInputEvent; +import net.minecraftforge.client.event.InputEvent.MouseInputEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.event.TickEvent.ClientTickEvent; +import net.minecraftforge.event.TickEvent.Phase; +import net.minecraftforge.event.TickEvent.RenderTickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; + +@EventBusSubscriber(value = Dist.CLIENT) +public class ClientEvents { + + @SubscribeEvent + public static void onTick(ClientTickEvent event) { + if (event.phase == Phase.START) + return; + if (!isGameActive()) + return; + + ScreenOpener.tick(); + onGameTick(); + } + + public static void onGameTick() { + CreateClient.gameTick(); + BeltItemHandler.gameTick(); + } + + @SubscribeEvent + public static void onRenderWorld(RenderWorldLastEvent event) { + CreateClient.schematicHandler.render(); + CreateClient.schematicAndQuillHandler.render(); + CreateClient.schematicHologram.render(); + } + + @SubscribeEvent + public static void onRenderOverlay(RenderGameOverlayEvent.Post event) { + if (event.getType() != ElementType.HOTBAR) + return; + + onRenderHotbar(); + } + + public static void onRenderHotbar() { + CreateClient.schematicHandler.renderOverlay(); + } + + @SubscribeEvent + public static void onKeyInput(KeyInputEvent event) { + int key = event.getKey(); + boolean pressed = !(event.getAction() == 0); + + if (Minecraft.getInstance().currentScreen != null) + return; + + CreateClient.schematicHandler.onKeyInput(key, pressed); + } + + @SubscribeEvent + // TODO: This is a fabricated event call by ScrollFixer until a proper event + // exists + public static void onMouseScrolled(MouseScrollEvent.Post event) { + if (event.getGui() != null) + return; + + double delta = event.getScrollDelta(); + + boolean cancelled = CreateClient.schematicHandler.mouseScrolled(delta) + || CreateClient.schematicAndQuillHandler.mouseScrolled(delta); + event.setCanceled(cancelled); + } + + @SubscribeEvent + public static void onMouseInput(MouseInputEvent event) { + if (Minecraft.getInstance().currentScreen != null) + return; + + int button = event.getButton(); + boolean pressed = !(event.getAction() == 0); + + CreateClient.schematicHandler.onMouseInput(button, pressed); + CreateClient.schematicAndQuillHandler.onMouseInput(button, pressed); + } + + @SubscribeEvent + public static void onRenderTick(RenderTickEvent event) { + if (!isGameActive()) + return; + + TurntableHandler.gameRenderTick(); + } + + protected static boolean isGameActive() { + return !(Minecraft.getInstance().world == null || Minecraft.getInstance().player == null); + } + +} diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index b21129fdc..dd7606e6b 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -3,36 +3,20 @@ package com.simibubi.create; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.simibubi.create.foundation.utility.KeyboardHelper; -import com.simibubi.create.modules.schematics.ClientSchematicLoader; import com.simibubi.create.modules.schematics.ServerSchematicLoader; -import com.simibubi.create.modules.schematics.client.BlueprintHandler; -import com.simibubi.create.modules.schematics.client.SchematicHologram; import net.minecraft.block.Block; -import net.minecraft.client.settings.KeyBinding; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.event.TickEvent.ClientTickEvent; -import net.minecraftforge.event.TickEvent.Phase; -import net.minecraftforge.event.TickEvent.ServerTickEvent; -import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.event.server.FMLServerStoppingEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -@EventBusSubscriber(bus = Bus.FORGE) +@EventBusSubscriber(bus = Bus.MOD) @Mod(Create.ID) public class Create { @@ -41,82 +25,37 @@ public class Create { public static final String VERSION = "0.0.5"; public static Logger logger = LogManager.getLogger(); - public static ItemGroup creativeTab = new CreateItemGroup(); + public static ServerSchematicLoader schematicReceiver; - @OnlyIn(Dist.CLIENT) - public static ClientSchematicLoader cSchematicLoader; - @OnlyIn(Dist.CLIENT) - public static KeyBinding TOOL_MENU; - - public static ServerSchematicLoader sSchematicLoader; - - public Create() { - IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); - modEventBus.addListener(this::clientInit); - modEventBus.addListener(this::init); - } - - private void clientInit(FMLClientSetupEvent event) { - DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { - AllTileEntities.registerRenderers(); - cSchematicLoader = new ClientSchematicLoader(); - new SchematicHologram(); - new BlueprintHandler(); - ScrollFixer.init(); - TOOL_MENU = new KeyBinding("Tool Menu (Hold)", KeyboardHelper.LALT, NAME); - ClientRegistry.registerKeyBinding(TOOL_MENU); - AllItems.registerColorHandlers(); - }); - } - - private void init(final FMLCommonSetupEvent event) { + @SubscribeEvent + public static void init(final FMLCommonSetupEvent event) { + schematicReceiver = new ServerSchematicLoader(); AllPackets.registerPackets(); - DistExecutor.runWhenOn(Dist.CLIENT, () -> AllContainers::registerScreenFactories); - sSchematicLoader = new ServerSchematicLoader(); } @SubscribeEvent - public static void onTick(ServerTickEvent event) { - if (event.phase == Phase.START) - return; - sSchematicLoader.tick(); + public static void registerItems(RegistryEvent.Register event) { + AllItems.registerItems(event.getRegistry()); + AllBlocks.registerItemBlocks(event.getRegistry()); } @SubscribeEvent - public static void onServerClose(FMLServerStoppingEvent event) { - sSchematicLoader.shutdown(); + public static void registerBlocks(RegistryEvent.Register event) { + AllBlocks.registerBlocks(event.getRegistry()); } - @OnlyIn(Dist.CLIENT) @SubscribeEvent - public static void onClientTick(ClientTickEvent event) { - if (event.phase == Phase.START) - return; - if (cSchematicLoader == null) - return; - - cSchematicLoader.tick(); + public static void registerRecipes(RegistryEvent.Register> event) { + AllRecipes.register(event); + } + + public static void tick() { + schematicReceiver.tick(); } - @EventBusSubscriber(bus = Bus.MOD) - public static class RegistryListener { - - @SubscribeEvent - public static void registerItems(RegistryEvent.Register event) { - AllItems.registerItems(event.getRegistry()); - AllBlocks.registerItemBlocks(event.getRegistry()); - } - - @SubscribeEvent - public static void registerBlocks(RegistryEvent.Register event) { - AllBlocks.registerBlocks(event.getRegistry()); - } - - @SubscribeEvent - public static void registerCustomRecipes(RegistryEvent.Register> event) { - AllRecipes.register(event); - } - + public static void shutdown() { + schematicReceiver.shutdown(); } + } diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java new file mode 100644 index 000000000..db9c5ef57 --- /dev/null +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -0,0 +1,43 @@ +package com.simibubi.create; + +import com.simibubi.create.modules.schematics.ClientSchematicLoader; +import com.simibubi.create.modules.schematics.client.SchematicAndQuillHandler; +import com.simibubi.create.modules.schematics.client.SchematicHandler; +import com.simibubi.create.modules.schematics.client.SchematicHologram; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; + +@EventBusSubscriber(value = Dist.CLIENT, bus = Bus.MOD) +public class CreateClient { + + public static ClientSchematicLoader schematicSender; + public static SchematicHandler schematicHandler; + public static SchematicHologram schematicHologram; + public static SchematicAndQuillHandler schematicAndQuillHandler; + + @SubscribeEvent + public static void clientInit(FMLClientSetupEvent event) { + schematicSender = new ClientSchematicLoader(); + schematicHandler = new SchematicHandler(); + schematicHologram = new SchematicHologram(); + + ScrollFixer.init(); + + AllKeys.register(); + AllContainers.registerScreenFactories(); + AllTileEntities.registerRenderers(); + AllItems.registerColorHandlers(); + } + + public static void gameTick() { + schematicSender.tick(); + schematicAndQuillHandler.tick(); + schematicHandler.tick(); + schematicHologram.tick(); + } + +} diff --git a/src/main/java/com/simibubi/create/Events.java b/src/main/java/com/simibubi/create/Events.java new file mode 100644 index 000000000..6e81bd793 --- /dev/null +++ b/src/main/java/com/simibubi/create/Events.java @@ -0,0 +1,26 @@ +package com.simibubi.create; + +import net.minecraftforge.event.TickEvent.Phase; +import net.minecraftforge.event.TickEvent.ServerTickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.event.server.FMLServerStoppingEvent; + +@EventBusSubscriber +public class Events { + + @SubscribeEvent + public static void onTick(ServerTickEvent event) { + if (event.phase == Phase.START) + return; + + Create.tick(); + } + + @SubscribeEvent + public static void onClose(FMLServerStoppingEvent event) { + Create.shutdown(); + } + + +} diff --git a/src/main/java/com/simibubi/create/foundation/gui/ScreenOpener.java b/src/main/java/com/simibubi/create/foundation/gui/ScreenOpener.java index 25acabc6b..2f0a39636 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ScreenOpener.java +++ b/src/main/java/com/simibubi/create/foundation/gui/ScreenOpener.java @@ -4,26 +4,26 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.event.TickEvent.ClientTickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.DistExecutor; -@OnlyIn(Dist.CLIENT) -@EventBusSubscriber(value = Dist.CLIENT) public class ScreenOpener { + @OnlyIn(Dist.CLIENT) private static Screen openedGuiNextTick; - @SubscribeEvent - public static void onClientTick(ClientTickEvent event) { - if (openedGuiNextTick != null) { - Minecraft.getInstance().displayGuiScreen(openedGuiNextTick); - openedGuiNextTick = null; - } + public static void tick() { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { + if (openedGuiNextTick != null) { + Minecraft.getInstance().displayGuiScreen(openedGuiNextTick); + openedGuiNextTick = null; + } + }); } - + public static void open(Screen gui) { - openedGuiNextTick = gui; + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { + openedGuiNextTick = gui; + }); } - + } diff --git a/src/main/java/com/simibubi/create/foundation/gui/ToolSelectionScreen.java b/src/main/java/com/simibubi/create/foundation/gui/ToolSelectionScreen.java index 27cd6f0fb..2be65faea 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ToolSelectionScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/ToolSelectionScreen.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.function.Consumer; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.Create; +import com.simibubi.create.AllKeys; import com.simibubi.create.modules.schematics.client.tools.Tools; import net.minecraft.client.MainWindow; @@ -88,10 +88,10 @@ public class ToolSelectionScreen extends Screen { GlStateManager.color4f(1, 1, 1, 1); if (tools.size() > 1) { - String translationKey = Create.TOOL_MENU.getLocalizedName().toUpperCase(); + String keyName = AllKeys.TOOL_MENU.getBoundKey(); int width = minecraft.mainWindow.getScaledWidth(); if (!focused) - drawCenteredString(minecraft.fontRenderer, "Hold [" + translationKey + "] to focus", width/2, y - 10, 0xCCDDFF); + drawCenteredString(minecraft.fontRenderer, "Hold [" + keyName + "] to focus", width/2, y - 10, 0xCCDDFF); else drawCenteredString(minecraft.fontRenderer, "[SCROLL] to Cycle", width/2, y - 10, 0xCCDDFF); } else { diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/ScrollInput.java b/src/main/java/com/simibubi/create/foundation/gui/widgets/ScrollInput.java index c4dbd77ee..7a01d7511 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/ScrollInput.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widgets/ScrollInput.java @@ -2,7 +2,7 @@ package com.simibubi.create.foundation.gui.widgets; import java.util.function.Consumer; -import com.simibubi.create.foundation.utility.KeyboardHelper; +import com.simibubi.create.AllKeys; import net.minecraft.util.text.TextFormatting; @@ -71,7 +71,7 @@ public class ScrollInput extends AbstractSimiWidget { return false; int priorState = state; - boolean shifted = KeyboardHelper.isKeyDown(KeyboardHelper.LSHIFT); + boolean shifted = AllKeys.shiftDown(); int step = (int) Math.signum(delta) * (shifted ? shiftStep : 1); state += step; if (shifted) diff --git a/src/main/java/com/simibubi/create/foundation/utility/KeyboardHelper.java b/src/main/java/com/simibubi/create/foundation/utility/KeyboardHelper.java deleted file mode 100644 index 86987a77e..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/KeyboardHelper.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.simibubi.create.foundation.utility; - -import org.lwjgl.glfw.GLFW; - -import net.minecraft.client.Minecraft; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -@OnlyIn(Dist.CLIENT) -public class KeyboardHelper { - - public static final int PRESS = 1; - public static final int HOLD = 2; - public static final int RELEASE = 0; - - public static final int LSHIFT = 340; - public static final int LALT = 342; - public static final int RETURN = 257; - - public static final int DOWN = 264; - public static final int LEFT = 263; - public static final int RIGHT = 262; - public static final int UP = 265; - - public static final int G = 71; - - public static boolean isKeyDown(int key) { - return GLFW.glfwGetKey(Minecraft.getInstance().mainWindow.getHandle(), key) != 0; - } - -} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java index 844dd0ebd..2cef8f30f 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java @@ -40,10 +40,10 @@ public class RotationPropagator { final World world = from.getWorld(); IProperty axisProperty = BlockStateProperties.AXIS; - boolean connectedByAxis = definitionFrom.isAxisTowards(world, from.getPos(), stateFrom, direction) - && definitionTo.isAxisTowards(world, to.getPos(), stateTo, direction.getOpposite()); - boolean connectedByGears = definitionFrom.isGearTowards(world, from.getPos(), stateFrom, direction) - && definitionTo.isGearTowards(world, to.getPos(), stateTo, direction.getOpposite()); + boolean connectedByAxis = definitionFrom.hasShaftTowards(world, from.getPos(), stateFrom, direction) + && definitionTo.hasShaftTowards(world, to.getPos(), stateTo, direction.getOpposite()); + boolean connectedByGears = definitionFrom.hasCogsTowards(world, from.getPos(), stateFrom, direction) + && definitionTo.hasCogsTowards(world, to.getPos(), stateTo, direction.getOpposite()); // Belt <-> Belt if (from instanceof BeltTileEntity && to instanceof BeltTileEntity && !connectedByAxis) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/IRotate.java b/src/main/java/com/simibubi/create/modules/contraptions/base/IRotate.java index 3f7f169eb..d676176c7 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/IRotate.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/IRotate.java @@ -8,8 +8,8 @@ import net.minecraft.world.World; public interface IRotate { - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face); - public boolean isGearTowards(World world, BlockPos pos, BlockState state, Direction face); + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face); + public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face); public Axis getRotationAxis(BlockState state); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java index d0d2eee6f..f41b881ad 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java @@ -26,12 +26,12 @@ public abstract class KineticBlock extends InfoBlock implements IRotate { // IRotate @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return false; } @Override - public boolean isGearTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face) { return false; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorBlock.java index fde94de04..bfc9aab0b 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorBlock.java @@ -36,7 +36,7 @@ public class MotorBlock extends HorizontalKineticBlock { // IRotate: @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return face == state.get(HORIZONTAL_FACING); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelBlock.java index 7085f080f..6749ca058 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelBlock.java @@ -123,7 +123,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock { } @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return state.get(HORIZONTAL_FACING).getAxis() == face.getAxis(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingWheelBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingWheelBlock.java index fa9268b60..7af651eff 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingWheelBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingWheelBlock.java @@ -153,7 +153,7 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock { } @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return face.getAxis() == state.get(AXIS); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java index 64aaf6492..2eee59dd5 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java @@ -82,7 +82,7 @@ public class DrillBlock extends DirectionalKineticBlock implements IHaveMovement } @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return !state.get(FIXATED) && face == state.get(FACING).getOpposite(); } @@ -96,7 +96,7 @@ public class DrillBlock extends DirectionalKineticBlock implements IHaveMovement BlockPos offsetPos = pos.offset(direction); BlockState blockStateAttached = world.getBlockState(offsetPos); if (blockStateAttached.getBlock() instanceof IRotate && ((IRotate) blockStateAttached.getBlock()) - .isAxisTowards(world.getWorld(), offsetPos, blockStateAttached, direction.getOpposite())) { + .hasShaftTowards(world.getWorld(), offsetPos, blockStateAttached, direction.getOpposite())) { return true; } return false; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java index 49f5673e6..6c444a0b9 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java @@ -6,6 +6,7 @@ import static net.minecraft.util.Direction.AxisDirection.POSITIVE; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; @@ -21,6 +22,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.item.ItemEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListNBT; @@ -81,6 +84,16 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable public ProcessedItem(ItemEntity item) { entity = item; + processingTimeLeft = 100; + } + + public void tick() { + world.addParticle(new RedstoneParticleData(1, 0, 1, 1), entity.posX, entity.posY, entity.posZ, 0, 0, 0); + processingTimeLeft--; + + if (processingTimeLeft <= 0) { + entity.setItem(new ItemStack(Items.COAL)); + } } } @@ -322,6 +335,18 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable entity.setFire(10); entity.attackEntityFrom(damageSourceLava, 8); } + } else { + boolean missing = true; + for (ProcessedItem processed : items) { + if (processed.entity == entity) { + processed.tick(); + missing = false; + break; + } + } + if (missing) { + items.add(new ProcessedItem((ItemEntity) entity)); + } } } for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(null, backBB)) { @@ -340,15 +365,25 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable if (findLoadedItems) { findLoadedItems = false; - for (ProcessedItem item : items) { + Iterator iterator = items.iterator(); + while (iterator.hasNext()) { + ProcessedItem item = iterator.next(); for (Entity entity : frontEntities) { if (!(entity instanceof ItemEntity)) continue; if (entity.getUniqueID().equals(item.loadedUUID)) item.entity = (ItemEntity) entity; } + if (item.entity == null) + iterator.remove(); } } + + Iterator iterator = items.iterator(); + while (iterator.hasNext()) + if (!iterator.next().entity.getBoundingBox().intersects(frontBB)) + iterator.remove(); + } protected void moveEntity(Entity entity, boolean push) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableBlock.java index 3e109b29e..efd688432 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableBlock.java @@ -92,7 +92,7 @@ public class TurntableBlock extends KineticBlock { // IRotate: @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return face == Direction.DOWN; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableHandler.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableHandler.java index 1c5987be3..7d69b8241 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableHandler.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableHandler.java @@ -4,21 +4,12 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import net.minecraft.client.Minecraft; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.event.TickEvent.RenderTickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -@EventBusSubscriber(value = Dist.CLIENT) public class TurntableHandler { - @SubscribeEvent - public static void onRenderTick(RenderTickEvent event) { + public static void gameRenderTick() { Minecraft mc = Minecraft.getInstance(); - if (mc.world == null || mc.player == null) - return; - if (!AllBlocks.TURNTABLE.typeOf(mc.world.getBlockState(mc.player.getPosition()))) return; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonBlock.java index 9440cd5c6..96cd04a3a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonBlock.java @@ -101,7 +101,7 @@ public class MechanicalPistonBlock extends KineticBlock { } @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return face.getAxis() == getRotationAxis(state); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/CogWheelBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/CogWheelBlock.java index 86cf3ce23..1274159d0 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/CogWheelBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/CogWheelBlock.java @@ -61,7 +61,7 @@ public class CogWheelBlock extends ShaftBlock { // IRotate @Override - public boolean isGearTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face) { return !isLarge && face.getAxis() != state.get(AXIS); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/EncasedBeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/EncasedBeltBlock.java index 396ac3729..c125eb0a6 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/EncasedBeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/EncasedBeltBlock.java @@ -85,7 +85,7 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock { } @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return face.getAxis() == state.get(AXIS); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/EncasedShaftBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/EncasedShaftBlock.java index 1c1b6a4a3..1816fe06d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/EncasedShaftBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/EncasedShaftBlock.java @@ -43,7 +43,7 @@ public class EncasedShaftBlock extends RotatedPillarKineticBlock { } @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return face.getAxis() == state.get(AXIS); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/GearboxBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/GearboxBlock.java index 9d88e678f..8314cf8f5 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/GearboxBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/GearboxBlock.java @@ -31,7 +31,7 @@ public class GearboxBlock extends RotatedPillarKineticBlock { // IRotate: @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return face.getAxis() != state.get(AXIS); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/GearshiftBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/GearshiftBlock.java index ce548b7de..794966272 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/GearshiftBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/GearshiftBlock.java @@ -64,8 +64,8 @@ public class GearshiftBlock extends EncasedShaftBlock { } } - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { - return super.isAxisTowards(world, pos, state, face); + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { + return super.hasShaftTowards(world, pos, state, face); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/ShaftBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/ShaftBlock.java index c674b8a8d..c5a9915b8 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/ShaftBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/ShaftBlock.java @@ -53,7 +53,7 @@ public class ShaftBlock extends RotatedPillarKineticBlock { // IRotate: @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { return face.getAxis() == state.get(AXIS); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java index 663dd0053..104d97cf0 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java @@ -280,7 +280,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt } @Override - public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { + public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) { if (face.getAxis() != getRotationAxis(state)) return false; BeltTileEntity beltEntity = (BeltTileEntity) world.getTileEntity(pos); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItemHandler.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItemHandler.java index bebcc308c..dbd49fb88 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItemHandler.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItemHandler.java @@ -21,22 +21,12 @@ import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.event.TickEvent.ClientTickEvent; -import net.minecraftforge.event.TickEvent.Phase; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -@EventBusSubscriber(value = Dist.CLIENT) public class BeltItemHandler { private static Random r = new Random(); - @SubscribeEvent - public static void onClientTick(ClientTickEvent event) { - if (event.phase == Phase.START) - return; - + public static void gameTick() { PlayerEntity player = Minecraft.getInstance().player; World world = Minecraft.getInstance().world; diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableScreen.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableScreen.java index 0186be7d3..501f35b44 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableScreen.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableScreen.java @@ -8,13 +8,14 @@ import java.util.List; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllBlocks; -import com.simibubi.create.Create; +import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.ScreenResources; import com.simibubi.create.foundation.gui.widgets.IconButton; import com.simibubi.create.foundation.gui.widgets.Label; import com.simibubi.create.foundation.gui.widgets.ScrollInput; import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput; +import com.simibubi.create.modules.schematics.ClientSchematicLoader; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.IHasContainer; @@ -52,8 +53,8 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen availableSchematics = Create.cSchematicLoader.getAvailableSchematics(); + CreateClient.schematicSender.refresh(); + List availableSchematics = CreateClient.schematicSender.getAvailableSchematics(); schematicsLabel = new Label(mainLeft + 36, mainTop + 26, "").withShadow(); schematicsLabel.text = ""; @@ -172,13 +173,15 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen availableSchematics = Create.cSchematicLoader.getAvailableSchematics(); + List availableSchematics = schematicSender.getAvailableSchematics(); String schematic = availableSchematics.get(schematicsArea.getState()); - Create.cSchematicLoader.startNewUpload(schematic); + schematicSender.startNewUpload(schematic); } if (folderButton.isHovered()) { @@ -186,8 +189,8 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen availableSchematics = Create.cSchematicLoader.getAvailableSchematics(); + schematicSender.refresh(); + List availableSchematics = schematicSender.getAvailableSchematics(); widgets.remove(schematicsArea); if (!availableSchematics.isEmpty()) { diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/BlueprintAndQuillHandler.java b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicAndQuillHandler.java similarity index 80% rename from src/main/java/com/simibubi/create/modules/schematics/client/BlueprintAndQuillHandler.java rename to src/main/java/com/simibubi/create/modules/schematics/client/SchematicAndQuillHandler.java index ec34656c6..58c1698a0 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/BlueprintAndQuillHandler.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicAndQuillHandler.java @@ -7,15 +7,14 @@ import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import org.apache.commons.io.IOUtils; -import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllItems; +import com.simibubi.create.AllKeys; import com.simibubi.create.AllSpecialTextures; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.TextInputPromptScreen; import com.simibubi.create.foundation.utility.FilesHelper; -import com.simibubi.create.foundation.utility.KeyboardHelper; import com.simibubi.create.foundation.utility.RaycastHelper; import com.simibubi.create.foundation.utility.RaycastHelper.PredicateTraceResult; import com.simibubi.create.foundation.utility.TessellatorHelper; @@ -42,54 +41,38 @@ import net.minecraft.util.math.Vec3i; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.gen.feature.template.Template; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.GuiScreenEvent.MouseScrollEvent; -import net.minecraftforge.client.event.InputEvent.MouseInputEvent; -import net.minecraftforge.client.event.RenderWorldLastEvent; -import net.minecraftforge.event.TickEvent.ClientTickEvent; -import net.minecraftforge.event.TickEvent.Phase; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; -@EventBusSubscriber(value = Dist.CLIENT, bus = Bus.FORGE) -public class BlueprintAndQuillHandler { +public class SchematicAndQuillHandler { - static BlockPos firstPos; - static BlockPos secondPos; - static BlockPos selectedPos; - static Direction selectedFace; - static int range = 10; + private BlockPos firstPos; + private BlockPos secondPos; + private BlockPos selectedPos; + private Direction selectedFace; + private int range = 10; - private static boolean active() { - return present() && AllItems.BLUEPRINT_AND_QUILL.typeOf(Minecraft.getInstance().player.getHeldItemMainhand()); + private boolean isActive() { + return isPresent() && AllItems.BLUEPRINT_AND_QUILL.typeOf(Minecraft.getInstance().player.getHeldItemMainhand()); } - private static boolean present() { + private boolean isPresent() { return Minecraft.getInstance() != null && Minecraft.getInstance().world != null && Minecraft.getInstance().currentScreen == null; } - @SubscribeEvent - // TODO: This is a fabricated event call by ScrollFixer until a proper event - // exists - public static void onMouseScrolled(MouseScrollEvent.Post event) { - if (event.getGui() != null) - return; - if (!active()) - return; - if (!KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL)) - return; - int delta = (int) event.getScrollDelta(); + public boolean mouseScrolled(double delta) { + if (!isActive()) + return false; + if (!AllKeys.ctrlDown()) + return false; if (secondPos == null) range = (int) MathHelper.clamp(range + delta, 1, 100); if (selectedFace != null) { MutableBoundingBox bb = new MutableBoundingBox(firstPos, secondPos); Vec3i vec = selectedFace.getDirectionVec(); - int x = vec.getX() * delta; - int y = vec.getY() * delta; - int z = vec.getZ() * delta; + int x = (int) (vec.getX() * delta); + int y = (int) (vec.getY() * delta); + int z = (int) (vec.getZ() * delta); AxisDirection axisDirection = selectedFace.getAxisDirection(); if (axisDirection == AxisDirection.NEGATIVE) @@ -107,17 +90,15 @@ public class BlueprintAndQuillHandler { true); } - event.setCanceled(true); + return true; } - @SubscribeEvent - public static void onClick(MouseInputEvent event) { - if (event.getAction() != KeyboardHelper.PRESS) + public void onMouseInput(int button, boolean pressed) { + if (!pressed || button != 1) return; - if (event.getButton() != 1) - return; - if (!active()) + if (!isActive()) return; + ClientPlayerEntity player = Minecraft.getInstance().player; if (player.isSneaking()) { @@ -128,7 +109,7 @@ public class BlueprintAndQuillHandler { } if (secondPos != null) { - TextInputPromptScreen guiScreenIn = new TextInputPromptScreen(BlueprintAndQuillHandler::saveSchematic, s -> { + TextInputPromptScreen guiScreenIn = new TextInputPromptScreen(this::saveSchematic, s -> { }); guiScreenIn.setTitle("Enter a name for the Schematic:"); guiScreenIn.setButtonTextConfirm("Save"); @@ -152,7 +133,7 @@ public class BlueprintAndQuillHandler { player.sendStatusMessage(new StringTextComponent(TextFormatting.GREEN + "First position set."), true); } - public static void saveSchematic(String string) { + public void saveSchematic(String string) { Template t = new Template(); MutableBoundingBox bb = new MutableBoundingBox(firstPos, secondPos); t.takeBlocksFromWorld(Minecraft.getInstance().world, new BlockPos(bb.minX, bb.minY, bb.minZ), @@ -182,9 +163,8 @@ public class BlueprintAndQuillHandler { Minecraft.getInstance().player.sendStatusMessage(new StringTextComponent("Saved as " + filepath), true); } - @SubscribeEvent - public static void onRenderWorld(RenderWorldLastEvent event) { - if (!active()) + public void render() { + if (!isActive()) return; TessellatorHelper.prepareForDrawing(); @@ -256,16 +236,13 @@ public class BlueprintAndQuillHandler { max.getX() + 1 / 16d, max.getY() + 1 / 16d, max.getZ() + 1 / 16d, red, green, 1, 1); } - @SubscribeEvent - public static void onClientTick(ClientTickEvent event) { - if (event.phase == Phase.START) - return; - if (!active()) + public void tick() { + if (!isActive()) return; ClientPlayerEntity player = Minecraft.getInstance().player; selectedPos = null; - if (KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL)) { + if (AllKeys.ACTIVATE_TOOL.isPressed()) { selectedPos = new BlockPos(player.getEyePosition(Minecraft.getInstance().getRenderPartialTicks()) .add(player.getLookVec().scale(range))); } else { diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/BlueprintEditScreen.java b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicEditScreen.java similarity index 83% rename from src/main/java/com/simibubi/create/modules/schematics/client/BlueprintEditScreen.java rename to src/main/java/com/simibubi/create/modules/schematics/client/SchematicEditScreen.java index 8babee2da..813851f61 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/BlueprintEditScreen.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicEditScreen.java @@ -6,6 +6,7 @@ import java.util.List; import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllItems; +import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.ScreenResources; import com.simibubi.create.foundation.gui.widgets.Label; @@ -18,7 +19,7 @@ import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; -public class BlueprintEditScreen extends AbstractSimiScreen { +public class SchematicEditScreen extends AbstractSimiScreen { private TextFieldWidget xInput; private TextFieldWidget yInput; @@ -30,22 +31,23 @@ public class BlueprintEditScreen extends AbstractSimiScreen { private ScrollInput rotationArea; private ScrollInput mirrorArea; + private SchematicHandler handler; @Override protected void init() { setWindowSize(ScreenResources.SCHEMATIC.width + 50, ScreenResources.SCHEMATIC.height); int x = guiLeft; int y = guiTop; - BlueprintHandler bh = BlueprintHandler.instance; + handler = CreateClient.schematicHandler; xInput = new TextFieldWidget(font, x + 75, y + 32, 32, 10, ""); yInput = new TextFieldWidget(font, x + 115, y + 32, 32, 10, ""); zInput = new TextFieldWidget(font, x + 155, y + 32, 32, 10, ""); - if (bh.deployed) { - xInput.setText("" + bh.anchor.getX()); - yInput.setText("" + bh.anchor.getY()); - zInput.setText("" + bh.anchor.getZ()); + if (handler.deployed) { + xInput.setText("" + handler.anchor.getX()); + yInput.setText("" + handler.anchor.getY()); + zInput.setText("" + handler.anchor.getZ()); } else { BlockPos alt = minecraft.player.getPosition(); xInput.setText("" + alt.getX()); @@ -73,11 +75,11 @@ public class BlueprintEditScreen extends AbstractSimiScreen { Label labelR = new Label(x + 99, y + 52, "").withShadow(); rotationArea = new SelectionScrollInput(x + 96, y + 49, 94, 14).forOptions(rotationOptions).titled("Rotation") - .setState(bh.cachedSettings.getRotation().ordinal()).writingTo(labelR); + .setState(handler.cachedSettings.getRotation().ordinal()).writingTo(labelR); Label labelM = new Label(x + 99, y + 72, "").withShadow(); mirrorArea = new SelectionScrollInput(x + 96, y + 69, 94, 14).forOptions(mirrorOptions).titled("Mirror") - .setState(bh.cachedSettings.getMirror().ordinal()).writingTo(labelM); + .setState(handler.cachedSettings.getMirror().ordinal()).writingTo(labelM); Collections.addAll(widgets, xInput, yInput, zInput); Collections.addAll(widgets, labelR, labelM, rotationArea, mirrorArea); @@ -120,10 +122,9 @@ public class BlueprintEditScreen extends AbstractSimiScreen { int x = guiLeft; int y = guiTop; ScreenResources.SCHEMATIC.draw(this, x, y); - BlueprintHandler bh = BlueprintHandler.instance; - font.drawStringWithShadow(bh.cachedSchematicName, x + 103 - font.getStringWidth(bh.cachedSchematicName) / 2, - y + 10, 0xDDEEFF); + font.drawStringWithShadow(handler.cachedSchematicName, + x + 103 - font.getStringWidth(handler.cachedSchematicName) / 2, y + 10, 0xDDEEFF); font.drawString("Position", x + 10, y + 32, ScreenResources.FONT_COLOR); font.drawString("Rotation", x + 10, y + 52, ScreenResources.FONT_COLOR); @@ -138,9 +139,6 @@ public class BlueprintEditScreen extends AbstractSimiScreen { @Override public void removed() { - // notify Blueprinthandler - BlueprintHandler bh = BlueprintHandler.instance; - boolean validCoords = true; BlockPos newLocation = null; try { @@ -150,10 +148,10 @@ public class BlueprintEditScreen extends AbstractSimiScreen { validCoords = false; } - if (validCoords) - bh.moveTo(newLocation); - bh.setRotation(Rotation.values()[rotationArea.getState()]); - bh.setMirror(Mirror.values()[mirrorArea.getState()]); + if (validCoords) + handler.moveTo(newLocation); + handler.setRotation(Rotation.values()[rotationArea.getState()]); + handler.setMirror(Mirror.values()[mirrorArea.getState()]); } } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/BlueprintHandler.java b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHandler.java similarity index 66% rename from src/main/java/com/simibubi/create/modules/schematics/client/BlueprintHandler.java rename to src/main/java/com/simibubi/create/modules/schematics/client/SchematicHandler.java index e875e305d..0d7822feb 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/BlueprintHandler.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHandler.java @@ -2,16 +2,14 @@ package com.simibubi.create.modules.schematics.client; import java.util.HashMap; -import org.lwjgl.glfw.GLFW; - import com.google.common.collect.ImmutableList; import com.simibubi.create.AllItems; +import com.simibubi.create.AllKeys; import com.simibubi.create.AllPackets; -import com.simibubi.create.Create; +import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.gui.ToolSelectionScreen; import com.simibubi.create.foundation.packet.NbtPacket; import com.simibubi.create.foundation.type.Cuboid; -import com.simibubi.create.foundation.utility.KeyboardHelper; import com.simibubi.create.foundation.utility.TessellatorHelper; import com.simibubi.create.modules.schematics.SchematicWorld; import com.simibubi.create.modules.schematics.client.tools.Tools; @@ -32,23 +30,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.gen.feature.template.PlacementSettings; import net.minecraft.world.gen.feature.template.Template; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.GuiScreenEvent.MouseScrollEvent; -import net.minecraftforge.client.event.InputEvent.KeyInputEvent; -import net.minecraftforge.client.event.InputEvent.MouseInputEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.client.event.RenderWorldLastEvent; -import net.minecraftforge.event.TickEvent.ClientTickEvent; -import net.minecraftforge.event.TickEvent.Phase; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; -@EventBusSubscriber(value = Dist.CLIENT, bus = Bus.FORGE) -public class BlueprintHandler { - - public static BlueprintHandler instance; +public class SchematicHandler { public Template cachedSchematic; public String cachedSchematicName; @@ -69,137 +52,104 @@ public class BlueprintHandler { private BlueprintHotbarOverlay overlay; - public BlueprintHandler() { - instance = this; + public SchematicHandler() { currentTool = Tools.Deploy; overlay = new BlueprintHotbarOverlay(); selectionScreen = new ToolSelectionScreen(ImmutableList.of(Tools.Deploy), this::equip); } - @SubscribeEvent - public static void onClientTick(ClientTickEvent event) { - if (event.phase == Phase.START) - return; + public void tick() { ClientPlayerEntity player = Minecraft.getInstance().player; - if (player == null) - return; - ItemStack stack = findBlueprintInHand(player); if (stack == null) { - instance.active = false; - instance.syncCooldown = 0; - if (instance.item != null && itemLost(player)) { - instance.slot = 0; - instance.item = null; - SchematicHologram.reset(); + active = false; + syncCooldown = 0; + if (item != null && itemLost(player)) { + slot = 0; + item = null; + CreateClient.schematicHologram.setActive(false); } return; } // Newly equipped - if (!instance.active || !stack.getTag().getString("File").equals(instance.cachedSchematicName)) { - instance.loadSettings(stack); - instance.cachedSchematicName = stack.getTag().getString("File"); - instance.active = true; - if (instance.deployed) { - Tools toolBefore = instance.currentTool; - instance.selectionScreen = new ToolSelectionScreen(Tools.getTools(player.isCreative()), - instance::equip); + if (!active || !stack.getTag().getString("File").equals(cachedSchematicName)) { + loadSettings(stack); + cachedSchematicName = stack.getTag().getString("File"); + active = true; + if (deployed) { + Tools toolBefore = currentTool; + selectionScreen = new ToolSelectionScreen(Tools.getTools(player.isCreative()), this::equip); if (toolBefore != null) { - instance.selectionScreen.setSelectedElement(toolBefore); - instance.equip(toolBefore); + selectionScreen.setSelectedElement(toolBefore); + equip(toolBefore); } } else - instance.selectionScreen = new ToolSelectionScreen(ImmutableList.of(Tools.Deploy), instance::equip); - instance.sync(); + selectionScreen = new ToolSelectionScreen(ImmutableList.of(Tools.Deploy), this::equip); + sync(); } - if (!instance.active) + if (!active) return; - if (instance.syncCooldown > 0) - instance.syncCooldown--; - if (instance.syncCooldown == 1) - instance.sync(); + if (syncCooldown > 0) + syncCooldown--; + if (syncCooldown == 1) + sync(); - instance.selectionScreen.update(); - instance.currentTool.getTool().updateSelection(); + selectionScreen.update(); + currentTool.getTool().updateSelection(); } - @SubscribeEvent - public static void onRenderWorld(RenderWorldLastEvent event) { - if (!instance.active) + public void render() { + if (!active) return; if (Minecraft.getInstance().player.isSneaking()) return; TessellatorHelper.prepareForDrawing(); - instance.currentTool.getTool().renderTool(); + currentTool.getTool().renderTool(); TessellatorHelper.cleanUpAfterDrawing(); } - @SubscribeEvent - public static void onRenderOverlay(RenderGameOverlayEvent.Post event) { - if (!instance.active) + public void renderOverlay() { + if (!active) return; - if (event.getType() != ElementType.HOTBAR) - return; - if (instance.item != null) - instance.overlay.renderOn(instance.slot); + if (item != null) + overlay.renderOn(slot); - instance.currentTool.getTool().renderOverlay(); - instance.selectionScreen.renderPassive(event.getPartialTicks()); + currentTool.getTool().renderOverlay(); + selectionScreen.renderPassive(Minecraft.getInstance().getRenderPartialTicks()); } - @SubscribeEvent - public static void onClick(MouseInputEvent event) { - if (Minecraft.getInstance().currentScreen != null) + public void onMouseInput(int button, boolean pressed) { + if (!active) return; - if (event.getAction() != KeyboardHelper.PRESS) - return; - if (event.getButton() != 1) - return; - if (!instance.active) + if (!pressed || button != 1) return; if (Minecraft.getInstance().player.isSneaking()) return; - instance.currentTool.getTool().handleRightClick(); + currentTool.getTool().handleRightClick(); } - @SubscribeEvent - public static void onKeyTyped(KeyInputEvent event) { - if (Minecraft.getInstance().currentScreen != null) + public void onKeyInput(int key, boolean pressed) { + if (!active) return; - if (event.getKey() != Create.TOOL_MENU.getKey().getKeyCode()) - return; - if (!instance.active) + if (key != AllKeys.TOOL_MENU.getBoundCode()) return; - boolean released = event.getAction() == KeyboardHelper.RELEASE; + if (pressed && !selectionScreen.focused) + selectionScreen.focused = true; - ToolSelectionScreen toolSelection = instance.selectionScreen; - if (released && toolSelection.focused) { - toolSelection.focused = false; - toolSelection.onClose(); + if (!pressed && selectionScreen.focused) { + selectionScreen.focused = false; + selectionScreen.onClose(); } - - if (!released && !toolSelection.focused) - toolSelection.focused = true; } - @SubscribeEvent - // TODO: This is a fabricated event call by ScrollFixer until a proper event - // exists - public static void onMouseScrolled(MouseScrollEvent.Post event) { - if (event.getGui() != null) - return; - if (instance.onScroll(event.getScrollDelta())) - event.setCanceled(true); - } - - public boolean onScroll(double delta) { + public boolean mouseScrolled(double delta) { if (!active) return false; if (Minecraft.getInstance().player.isSneaking()) @@ -208,30 +158,30 @@ public class BlueprintHandler { selectionScreen.cycle((int) delta); return true; } - if (KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL)) { + if (AllKeys.ACTIVATE_TOOL.isPressed()) { return currentTool.getTool().handleMouseWheel(delta); } return false; } - private static ItemStack findBlueprintInHand(PlayerEntity player) { + private ItemStack findBlueprintInHand(PlayerEntity player) { ItemStack stack = player.getHeldItemMainhand(); if (!AllItems.BLUEPRINT.typeOf(stack)) return null; if (!stack.hasTag()) return null; - instance.item = stack; - instance.slot = player.inventory.currentItem; + item = stack; + slot = player.inventory.currentItem; return stack; } - private static boolean itemLost(PlayerEntity player) { + private boolean itemLost(PlayerEntity player) { for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) { - if (!player.inventory.getStackInSlot(i).isItemEqual(instance.item)) + if (!player.inventory.getStackInSlot(i).isItemEqual(item)) continue; - if (!ItemStack.areItemStackTagsEqual(player.inventory.getStackInSlot(i), instance.item)) + if (!ItemStack.areItemStackTagsEqual(player.inventory.getStackInSlot(i), item)) continue; return false; } @@ -240,7 +190,7 @@ public class BlueprintHandler { public void markDirty() { syncCooldown = SYNC_DELAY; - SchematicHologram.reset(); + CreateClient.schematicHologram.setActive(false); } public void sync() { @@ -352,8 +302,8 @@ public class BlueprintHandler { public void moveTo(BlockPos anchor) { if (!deployed) - instance.selectionScreen = new ToolSelectionScreen( - Tools.getTools(Minecraft.getInstance().player.isCreative()), instance::equip); + selectionScreen = new ToolSelectionScreen(Tools.getTools(Minecraft.getInstance().player.isCreative()), + this::equip); deployed = true; this.anchor = anchor; @@ -361,13 +311,13 @@ public class BlueprintHandler { item.getTag().put("Anchor", NBTUtil.writeBlockPos(anchor)); markDirty(); } - + public void printInstantly() { AllPackets.channel.sendToServer(new SchematicPlacePacket(item.copy())); CompoundNBT nbt = item.getTag(); nbt.putBoolean("Deployed", false); item.setTag(nbt); - SchematicHologram.reset(); + CreateClient.schematicHologram.setActive(false); active = false; } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHologram.java b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHologram.java index 969ffeea6..b8934f0c9 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHologram.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHologram.java @@ -31,44 +31,27 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.gen.feature.template.PlacementSettings; import net.minecraft.world.gen.feature.template.Template; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.model.data.EmptyModelData; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.event.TickEvent.ClientTickEvent; -import net.minecraftforge.event.TickEvent.Phase; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -@OnlyIn(Dist.CLIENT) -@EventBusSubscriber(Dist.CLIENT) public class SchematicHologram { - // These buffers are large enough for an entire chunk, consider using - // smaller buffers - private static final RegionRenderCacheBuilder bufferCache = new RegionRenderCacheBuilder(); - private static final boolean[] usedBlockRenderLayers = new boolean[BlockRenderLayer.values().length]; - private static final boolean[] startedBufferBuilders = new boolean[BlockRenderLayer.values().length]; - - private static SchematicHologram instance; + private final RegionRenderCacheBuilder bufferCache = new RegionRenderCacheBuilder(); + private final boolean[] usedBlockRenderLayers = new boolean[BlockRenderLayer.values().length]; + private final boolean[] startedBufferBuilders = new boolean[BlockRenderLayer.values().length]; private boolean active; private boolean changed; private SchematicWorld schematic; private BlockPos anchor; public SchematicHologram() { - instance = this; changed = false; } public void startHologram(Template schematic, BlockPos anchor) { - this.schematic = new SchematicWorld(new HashMap<>(), new Cuboid(BlockPos.ZERO, BlockPos.ZERO), anchor); - this.anchor = anchor; - schematic.addBlocksToWorld(this.schematic, anchor, new PlacementSettings()); - active = true; - changed = true; + SchematicWorld world = new SchematicWorld(new HashMap<>(), new Cuboid(BlockPos.ZERO, BlockPos.ZERO), anchor); + schematic.addBlocksToWorld(world, anchor, new PlacementSettings()); + startHologram(world); } public void startHologram(SchematicWorld world) { @@ -78,49 +61,40 @@ public class SchematicHologram { this.changed = true; } - public static SchematicHologram getInstance() { - return instance; + public void setActive(boolean active) { + this.active = active; } - public static void reset() { - instance = null; - } - - public void schematicChanged() { + public void update() { changed = true; } - @SubscribeEvent - public static void onClientTickEvent(final ClientTickEvent event) { - if (event.phase == Phase.START) + public void tick() { + if (!active) return; - if (instance != null && instance.active) { - final Minecraft minecraft = Minecraft.getInstance(); - if (event.phase != TickEvent.Phase.END) - return; - if (minecraft.world == null) - return; - if (minecraft.player == null) - return; - if (instance.changed) { - redraw(minecraft); - instance.changed = false; - } + Minecraft minecraft = Minecraft.getInstance(); + if (minecraft.world == null) + return; + if (minecraft.player == null) + return; + if (changed) { + redraw(minecraft); + changed = false; } } - private static void redraw(final Minecraft minecraft) { + private void redraw(Minecraft minecraft) { Arrays.fill(usedBlockRenderLayers, false); Arrays.fill(startedBufferBuilders, false); - final SchematicWorld blockAccess = instance.schematic; + final SchematicWorld blockAccess = schematic; final BlockRendererDispatcher blockRendererDispatcher = minecraft.getBlockRendererDispatcher(); List blockstates = new LinkedList<>(); for (BlockPos localPos : BlockPos.getAllInBoxMutable(blockAccess.getBounds().getOrigin(), blockAccess.getBounds().getOrigin().add(blockAccess.getBounds().getSize()))) { - BlockPos pos = localPos.add(instance.anchor); + BlockPos pos = localPos.add(anchor); BlockState state = blockAccess.getBlockState(pos); for (BlockRenderLayer blockRenderLayer : BlockRenderLayer.values()) { if (!state.getBlock().canRenderInLayer(state, blockRenderLayer)) { @@ -139,12 +113,12 @@ public class SchematicHologram { // OptiFine Shaders compatibility // if (Config.isShaders()) SVertexBuilder.pushEntity(state, pos, // blockAccess, bufferBuilder); - + // Block transformations if (state.getBlock() instanceof BedBlock) { state = Blocks.QUARTZ_SLAB.getDefaultState(); } - + usedBlockRenderLayers[blockRenderLayerId] |= blockRendererDispatcher.renderBlock(state, pos, blockAccess, bufferBuilder, minecraft.world.rand, EmptyModelData.INSTANCE); blockstates.add(state); @@ -163,9 +137,8 @@ public class SchematicHologram { } } - @SubscribeEvent - public static void onRenderWorldLastEvent(final RenderWorldLastEvent event) { - if (instance != null && instance.active) { + public void render() { + if (active) { final Entity entity = Minecraft.getInstance().getRenderViewEntity(); if (entity == null) { diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/tools/DeployTool.java b/src/main/java/com/simibubi/create/modules/schematics/client/tools/DeployTool.java index b7358a9ab..306e79f02 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/tools/DeployTool.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/tools/DeployTool.java @@ -1,9 +1,7 @@ package com.simibubi.create.modules.schematics.client.tools; -import org.lwjgl.glfw.GLFW; - import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.utility.KeyboardHelper; +import com.simibubi.create.AllKeys; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.util.math.BlockPos; @@ -20,11 +18,11 @@ public class DeployTool extends PlacementToolBase { @Override public void updateSelection() { - if (blueprint.active && selectionRange == -1) { - selectionRange = (int) blueprint.size.manhattanDistance(BlockPos.ZERO) / 2; + if (schematicHandler.active && selectionRange == -1) { + selectionRange = (int) schematicHandler.size.manhattanDistance(BlockPos.ZERO) / 2; selectionRange = MathHelper.clamp(selectionRange, 1, 100); } - selectIgnoreBlocks = KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL); + selectIgnoreBlocks = AllKeys.ACTIVATE_TOOL.isPressed(); super.updateSelection(); } @@ -36,12 +34,12 @@ public class DeployTool extends PlacementToolBase { if (selectedPos == null) return; - BlockPos size = blueprint.getTransformedSize(); + BlockPos size = schematicHandler.getTransformedSize(); BlockPos min = selectedPos.add(Math.round(size.getX() * -.5f), 0, Math.round(size.getZ() * -.5f)); BlockPos max = min.add(size.getX(), size.getY(), size.getZ()); - if (blueprint.deployed) { - MutableBoundingBox bb = new MutableBoundingBox(min, min.add(blueprint.getTransformedSize())); + if (schematicHandler.deployed) { + MutableBoundingBox bb = new MutableBoundingBox(min, min.add(schematicHandler.getTransformedSize())); min = new BlockPos(bb.minX, bb.minY, bb.minZ); max = new BlockPos(bb.maxX, bb.maxY, bb.maxZ); } @@ -75,8 +73,8 @@ public class DeployTool extends PlacementToolBase { if (selectedPos == null) return super.handleRightClick(); - BlockPos size = blueprint.getTransformedSize(); - blueprint.moveTo(selectedPos.add(Math.round(size.getX() * -.5f), 0, Math.round(size.getZ() * -.5f))); + BlockPos size = schematicHandler.getTransformedSize(); + schematicHandler.moveTo(selectedPos.add(Math.round(size.getX() * -.5f), 0, Math.round(size.getZ() * -.5f))); return true; } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/tools/FlipTool.java b/src/main/java/com/simibubi/create/modules/schematics/client/tools/FlipTool.java index b0f4d7fce..c404d4b58 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/tools/FlipTool.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/tools/FlipTool.java @@ -32,7 +32,7 @@ public class FlipTool extends PlacementToolBase { private void mirror() { if (schematicSelected && selectedFace.getAxis().isHorizontal()) { - blueprint.flip(selectedFace.getAxis()); + schematicHandler.flip(selectedFace.getAxis()); } } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/tools/MoveTool.java b/src/main/java/com/simibubi/create/modules/schematics/client/tools/MoveTool.java index 528ce9296..80500ba89 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/tools/MoveTool.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/tools/MoveTool.java @@ -21,8 +21,8 @@ public class MoveTool extends PlacementToolBase { @Override public boolean handleMouseWheel(double delta) { if (schematicSelected && selectedFace.getAxis().isHorizontal()) { - blueprint.moveTo(delta < 0 ? blueprint.anchor.add(selectedFace.getDirectionVec()) - : blueprint.anchor.subtract(selectedFace.getDirectionVec())); + schematicHandler.moveTo(delta < 0 ? schematicHandler.anchor.add(selectedFace.getDirectionVec()) + : schematicHandler.anchor.subtract(selectedFace.getDirectionVec())); } return true; } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/tools/MoveVerticalTool.java b/src/main/java/com/simibubi/create/modules/schematics/client/tools/MoveVerticalTool.java index d4ee439c5..3910a0a22 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/tools/MoveVerticalTool.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/tools/MoveVerticalTool.java @@ -4,8 +4,8 @@ public class MoveVerticalTool extends PlacementToolBase { @Override public boolean handleMouseWheel(double delta) { - if (blueprint.deployed) { - blueprint.moveTo(blueprint.anchor.add(0, delta, 0)); + if (schematicHandler.deployed) { + schematicHandler.moveTo(schematicHandler.anchor.add(0, delta, 0)); } return true; } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/tools/PlaceTool.java b/src/main/java/com/simibubi/create/modules/schematics/client/tools/PlaceTool.java index 208724c17..f9ac22097 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/tools/PlaceTool.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/tools/PlaceTool.java @@ -4,7 +4,7 @@ public class PlaceTool extends SchematicToolBase { @Override public boolean handleRightClick() { - blueprint.printInstantly(); + schematicHandler.printInstantly(); return true; } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/tools/RotateTool.java b/src/main/java/com/simibubi/create/modules/schematics/client/tools/RotateTool.java index d87f72acf..171f132f0 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/tools/RotateTool.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/tools/RotateTool.java @@ -6,7 +6,7 @@ public class RotateTool extends PlacementToolBase { @Override public boolean handleMouseWheel(double delta) { - blueprint.rotate(delta > 0 ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90); + schematicHandler.rotate(delta > 0 ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90); return true; } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/tools/SchematicToolBase.java b/src/main/java/com/simibubi/create/modules/schematics/client/tools/SchematicToolBase.java index c5f854228..12af5f211 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/tools/SchematicToolBase.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/tools/SchematicToolBase.java @@ -1,12 +1,11 @@ package com.simibubi.create.modules.schematics.client.tools; -import org.lwjgl.glfw.GLFW; - import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.utility.KeyboardHelper; +import com.simibubi.create.AllKeys; +import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.RaycastHelper; import com.simibubi.create.foundation.utility.RaycastHelper.PredicateTraceResult; -import com.simibubi.create.modules.schematics.client.BlueprintHandler; +import com.simibubi.create.modules.schematics.client.SchematicHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; @@ -23,7 +22,7 @@ import net.minecraft.util.math.Vec3d; public abstract class SchematicToolBase implements ISchematicTool { - protected BlueprintHandler blueprint; + protected SchematicHandler schematicHandler; public BlockPos selectedPos; public boolean selectIgnoreBlocks; @@ -34,7 +33,7 @@ public abstract class SchematicToolBase implements ISchematicTool { public Direction selectedFace; public SchematicToolBase() { - blueprint = BlueprintHandler.instance; + schematicHandler = CreateClient.schematicHandler; } @Override @@ -49,9 +48,9 @@ public abstract class SchematicToolBase implements ISchematicTool { ClientPlayerEntity player = Minecraft.getInstance().player; // Select Blueprint - if (blueprint.deployed) { - BlockPos min = blueprint.getTransformedAnchor(); - MutableBoundingBox bb = new MutableBoundingBox(min, min.add(blueprint.getTransformedSize())); + if (schematicHandler.deployed) { + BlockPos min = schematicHandler.getTransformedAnchor(); + MutableBoundingBox bb = new MutableBoundingBox(min, min.add(schematicHandler.getTransformedSize())); PredicateTraceResult result = RaycastHelper.rayTraceUntil(player, 70, pos -> bb.isVecInside(pos)); schematicSelected = !result.missed(); @@ -84,20 +83,20 @@ public abstract class SchematicToolBase implements ISchematicTool { @Override public void renderTool() { - if (blueprint.deployed) { + if (schematicHandler.deployed) { GlStateManager.lineWidth(2); GlStateManager.color4f(1, 1, 1, 1); GlStateManager.disableTexture(); - BlockPos min = blueprint.getTransformedAnchor(); - MutableBoundingBox bb = new MutableBoundingBox(min, min.add(blueprint.getTransformedSize())); + BlockPos min = schematicHandler.getTransformedAnchor(); + MutableBoundingBox bb = new MutableBoundingBox(min, min.add(schematicHandler.getTransformedSize())); min = new BlockPos(bb.minX, bb.minY, bb.minZ); BlockPos max = new BlockPos(bb.maxX, bb.maxY, bb.maxZ); WorldRenderer.drawBoundingBox(min.getX() - 1 / 8d, min.getY() + 1 / 16d, min.getZ() - 1 / 8d, max.getX() + 1 / 8d, max.getY() + 1 / 8d, max.getZ() + 1 / 8d, 1, 1, 1, 1); - if (schematicSelected && renderSelectedFace && KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL)) { + if (schematicSelected && renderSelectedFace && AllKeys.ACTIVATE_TOOL.isPressed()) { Vec3d vec = new Vec3d(selectedFace.getDirectionVec()); Vec3d center = new Vec3d(min.add(max)).scale(1 / 2f); Vec3d radii = new Vec3d(max.subtract(min)).scale(1 / 2f); diff --git a/src/main/java/com/simibubi/create/modules/schematics/item/BlueprintAndQuillItem.java b/src/main/java/com/simibubi/create/modules/schematics/item/BlueprintAndQuillItem.java index 4ec72b222..0fd9a20e8 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/item/BlueprintAndQuillItem.java +++ b/src/main/java/com/simibubi/create/modules/schematics/item/BlueprintAndQuillItem.java @@ -2,7 +2,7 @@ package com.simibubi.create.modules.schematics.item; import java.util.List; -import com.simibubi.create.foundation.utility.KeyboardHelper; +import com.simibubi.create.AllKeys; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.item.Item; @@ -20,7 +20,7 @@ public class BlueprintAndQuillItem extends Item { @Override public void addInformation(ItemStack stack, World worldIn, List tooltip, ITooltipFlag flagIn) { - if (KeyboardHelper.isKeyDown(KeyboardHelper.LSHIFT)) { + if (AllKeys.shiftDown()) { TextFormatting gray = TextFormatting.GRAY; TextFormatting blue = TextFormatting.BLUE; diff --git a/src/main/java/com/simibubi/create/modules/schematics/item/BlueprintItem.java b/src/main/java/com/simibubi/create/modules/schematics/item/BlueprintItem.java index 837615b0a..7c539dfb1 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/item/BlueprintItem.java +++ b/src/main/java/com/simibubi/create/modules/schematics/item/BlueprintItem.java @@ -10,9 +10,9 @@ import java.util.List; import org.apache.commons.io.IOUtils; import com.simibubi.create.AllItems; +import com.simibubi.create.AllKeys; import com.simibubi.create.foundation.gui.ScreenOpener; -import com.simibubi.create.foundation.utility.KeyboardHelper; -import com.simibubi.create.modules.schematics.client.BlueprintEditScreen; +import com.simibubi.create.modules.schematics.client.SchematicEditScreen; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.PlayerEntity; @@ -67,7 +67,7 @@ public class BlueprintItem extends Item { @Override @OnlyIn(value = Dist.CLIENT) public void addInformation(ItemStack stack, World worldIn, List tooltip, ITooltipFlag flagIn) { - if (KeyboardHelper.isKeyDown(KeyboardHelper.LSHIFT)) { + if (AllKeys.shiftDown()) { TextFormatting gray = TextFormatting.GRAY; tooltip.add(new StringTextComponent(gray + "Holds a structure to be printed")); tooltip.add(new StringTextComponent(gray + "by the Schematicannon.")); @@ -138,7 +138,7 @@ public class BlueprintItem extends Item { @OnlyIn(value = Dist.CLIENT) protected void displayBlueprintScreen() { - ScreenOpener.open(new BlueprintEditScreen()); + ScreenOpener.open(new SchematicEditScreen()); } @Override diff --git a/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicUploadPacket.java b/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicUploadPacket.java index 4c8f800b1..55f27f5ba 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicUploadPacket.java +++ b/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicUploadPacket.java @@ -69,13 +69,13 @@ public class SchematicUploadPacket extends SimplePacketBase { ServerPlayerEntity player = context.get().getSender(); if (code == BEGIN) { BlockPos pos = ((SchematicTableContainer) player.openContainer).getTileEntity().getPos(); - Create.sSchematicLoader.handleNewUpload(player, schematic, size, new DimensionPos(player, pos)); + Create.schematicReceiver.handleNewUpload(player, schematic, size, new DimensionPos(player, pos)); } if (code == WRITE) { - Create.sSchematicLoader.handleWriteRequest(player, schematic, data); + Create.schematicReceiver.handleWriteRequest(player, schematic, data); } if (code == FINISH) { - Create.sSchematicLoader.handleFinishedUpload(player, schematic); + Create.schematicReceiver.handleFinishedUpload(player, schematic); } }); context.get().setPacketHandled(true);