mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-14 22:03:40 +01:00
Refactoring Events
- Moved main Client code to separate class - Bundled some events into a single subscriber - Renamed a few things - Keybinds and Keys have their own enum now
This commit is contained in:
parent
ebaf22ddcc
commit
d20ac87f2c
43 changed files with 530 additions and 459 deletions
72
src/main/java/com/simibubi/create/AllKeys.java
Normal file
72
src/main/java/com/simibubi/create/AllKeys.java
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
108
src/main/java/com/simibubi/create/ClientEvents.java
Normal file
108
src/main/java/com/simibubi/create/ClientEvents.java
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Item> event) {
|
||||
AllItems.registerItems(event.getRegistry());
|
||||
AllBlocks.registerItemBlocks(event.getRegistry());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerClose(FMLServerStoppingEvent event) {
|
||||
sSchematicLoader.shutdown();
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> 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<IRecipeSerializer<?>> event) {
|
||||
AllRecipes.register(event);
|
||||
}
|
||||
|
||||
@EventBusSubscriber(bus = Bus.MOD)
|
||||
public static class RegistryListener {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event) {
|
||||
AllItems.registerItems(event.getRegistry());
|
||||
AllBlocks.registerItemBlocks(event.getRegistry());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
||||
AllBlocks.registerBlocks(event.getRegistry());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerCustomRecipes(RegistryEvent.Register<IRecipeSerializer<?>> event) {
|
||||
AllRecipes.register(event);
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
schematicReceiver.tick();
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
schematicReceiver.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
43
src/main/java/com/simibubi/create/CreateClient.java
Normal file
43
src/main/java/com/simibubi/create/CreateClient.java
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
26
src/main/java/com/simibubi/create/Events.java
Normal file
26
src/main/java/com/simibubi/create/Events.java
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -40,10 +40,10 @@ public class RotationPropagator {
|
|||
final World world = from.getWorld();
|
||||
|
||||
IProperty<Axis> 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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<ProcessedItem> 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<ProcessedItem> iterator = items.iterator();
|
||||
while (iterator.hasNext())
|
||||
if (!iterator.next().entity.getBoundingBox().intersects(frontBB))
|
||||
iterator.remove();
|
||||
|
||||
}
|
||||
|
||||
protected void moveEntity(Entity entity, boolean push) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<SchematicT
|
|||
int mainLeft = guiLeft - 56;
|
||||
int mainTop = guiTop - 16;
|
||||
|
||||
Create.cSchematicLoader.refresh();
|
||||
List<String> availableSchematics = Create.cSchematicLoader.getAvailableSchematics();
|
||||
CreateClient.schematicSender.refresh();
|
||||
List<String> availableSchematics = CreateClient.schematicSender.getAvailableSchematics();
|
||||
|
||||
schematicsLabel = new Label(mainLeft + 36, mainTop + 26, "").withShadow();
|
||||
schematicsLabel.text = "";
|
||||
|
@ -172,13 +173,15 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
|
|||
|
||||
@Override
|
||||
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) {
|
||||
ClientSchematicLoader schematicSender = CreateClient.schematicSender;
|
||||
|
||||
if (confirmButton.active && confirmButton.isHovered() && ((SchematicTableContainer) container).canWrite()
|
||||
&& schematicsArea != null) {
|
||||
|
||||
lastChasingProgress = chasingProgress = progress = 0;
|
||||
List<String> availableSchematics = Create.cSchematicLoader.getAvailableSchematics();
|
||||
List<String> 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<SchematicT
|
|||
}
|
||||
|
||||
if (refreshButton.isHovered()) {
|
||||
Create.cSchematicLoader.refresh();
|
||||
List<String> availableSchematics = Create.cSchematicLoader.getAvailableSchematics();
|
||||
schematicSender.refresh();
|
||||
List<String> availableSchematics = schematicSender.getAvailableSchematics();
|
||||
widgets.remove(schematicsArea);
|
||||
|
||||
if (!availableSchematics.isEmpty()) {
|
||||
|
|
|
@ -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 {
|
|
@ -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 {
|
||||
|
@ -151,9 +149,9 @@ public class BlueprintEditScreen extends AbstractSimiScreen {
|
|||
}
|
||||
|
||||
if (validCoords)
|
||||
bh.moveTo(newLocation);
|
||||
bh.setRotation(Rotation.values()[rotationArea.getState()]);
|
||||
bh.setMirror(Mirror.values()[mirrorArea.getState()]);
|
||||
handler.moveTo(newLocation);
|
||||
handler.setRotation(Rotation.values()[rotationArea.getState()]);
|
||||
handler.setMirror(Mirror.values()[mirrorArea.getState()]);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
@ -367,7 +317,7 @@ public class BlueprintHandler {
|
|||
CompoundNBT nbt = item.getTag();
|
||||
nbt.putBoolean("Deployed", false);
|
||||
item.setTag(nbt);
|
||||
SchematicHologram.reset();
|
||||
CreateClient.schematicHologram.setActive(false);
|
||||
active = false;
|
||||
}
|
||||
|
|
@ -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<BlockState> 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)) {
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public class PlaceTool extends SchematicToolBase {
|
|||
|
||||
@Override
|
||||
public boolean handleRightClick() {
|
||||
blueprint.printInstantly();
|
||||
schematicHandler.printInstantly();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
if (KeyboardHelper.isKeyDown(KeyboardHelper.LSHIFT)) {
|
||||
if (AllKeys.shiftDown()) {
|
||||
TextFormatting gray = TextFormatting.GRAY;
|
||||
TextFormatting blue = TextFormatting.BLUE;
|
||||
|
||||
|
|
|
@ -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<ITextComponent> 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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue