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:
simibubi 2019-09-03 08:34:02 +02:00
parent ebaf22ddcc
commit d20ac87f2c
43 changed files with 530 additions and 459 deletions

View 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();
}
}

View 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);
}
}

View file

@ -3,36 +3,20 @@ package com.simibubi.create;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; 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.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.block.Block;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.crafting.IRecipeSerializer; 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.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.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;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; 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.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) @Mod(Create.ID)
public class Create { public class Create {
@ -41,82 +25,37 @@ public class Create {
public static final String VERSION = "0.0.5"; public static final String VERSION = "0.0.5";
public static Logger logger = LogManager.getLogger(); public static Logger logger = LogManager.getLogger();
public static ItemGroup creativeTab = new CreateItemGroup(); public static ItemGroup creativeTab = new CreateItemGroup();
public static ServerSchematicLoader schematicReceiver;
@OnlyIn(Dist.CLIENT) @SubscribeEvent
public static ClientSchematicLoader cSchematicLoader; public static void init(final FMLCommonSetupEvent event) {
@OnlyIn(Dist.CLIENT) schematicReceiver = new ServerSchematicLoader();
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) {
AllPackets.registerPackets(); AllPackets.registerPackets();
DistExecutor.runWhenOn(Dist.CLIENT, () -> AllContainers::registerScreenFactories);
sSchematicLoader = new ServerSchematicLoader();
} }
@SubscribeEvent @SubscribeEvent
public static void onTick(ServerTickEvent event) { public static void registerItems(RegistryEvent.Register<Item> event) {
if (event.phase == Phase.START) AllItems.registerItems(event.getRegistry());
return; AllBlocks.registerItemBlocks(event.getRegistry());
sSchematicLoader.tick();
} }
@SubscribeEvent @SubscribeEvent
public static void onServerClose(FMLServerStoppingEvent event) { public static void registerBlocks(RegistryEvent.Register<Block> event) {
sSchematicLoader.shutdown(); AllBlocks.registerBlocks(event.getRegistry());
} }
@OnlyIn(Dist.CLIENT)
@SubscribeEvent @SubscribeEvent
public static void onClientTick(ClientTickEvent event) { public static void registerRecipes(RegistryEvent.Register<IRecipeSerializer<?>> event) {
if (event.phase == Phase.START) AllRecipes.register(event);
return;
if (cSchematicLoader == null)
return;
cSchematicLoader.tick();
} }
@EventBusSubscriber(bus = Bus.MOD) public static void tick() {
public static class RegistryListener { schematicReceiver.tick();
@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 shutdown() {
schematicReceiver.shutdown();
}
} }

View 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();
}
}

View 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();
}
}

View file

@ -4,26 +4,26 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@OnlyIn(Dist.CLIENT)
@EventBusSubscriber(value = Dist.CLIENT)
public class ScreenOpener { public class ScreenOpener {
@OnlyIn(Dist.CLIENT)
private static Screen openedGuiNextTick; private static Screen openedGuiNextTick;
@SubscribeEvent public static void tick() {
public static void onClientTick(ClientTickEvent event) { DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
if (openedGuiNextTick != null) { if (openedGuiNextTick != null) {
Minecraft.getInstance().displayGuiScreen(openedGuiNextTick); Minecraft.getInstance().displayGuiScreen(openedGuiNextTick);
openedGuiNextTick = null; openedGuiNextTick = null;
} }
});
} }
public static void open(Screen gui) { public static void open(Screen gui) {
openedGuiNextTick = gui; DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
openedGuiNextTick = gui;
});
} }
} }

View file

@ -4,7 +4,7 @@ import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.mojang.blaze3d.platform.GlStateManager; 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 com.simibubi.create.modules.schematics.client.tools.Tools;
import net.minecraft.client.MainWindow; import net.minecraft.client.MainWindow;
@ -88,10 +88,10 @@ public class ToolSelectionScreen extends Screen {
GlStateManager.color4f(1, 1, 1, 1); GlStateManager.color4f(1, 1, 1, 1);
if (tools.size() > 1) { if (tools.size() > 1) {
String translationKey = Create.TOOL_MENU.getLocalizedName().toUpperCase(); String keyName = AllKeys.TOOL_MENU.getBoundKey();
int width = minecraft.mainWindow.getScaledWidth(); int width = minecraft.mainWindow.getScaledWidth();
if (!focused) 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 else
drawCenteredString(minecraft.fontRenderer, "[SCROLL] to Cycle", width/2, y - 10, 0xCCDDFF); drawCenteredString(minecraft.fontRenderer, "[SCROLL] to Cycle", width/2, y - 10, 0xCCDDFF);
} else { } else {

View file

@ -2,7 +2,7 @@ package com.simibubi.create.foundation.gui.widgets;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.simibubi.create.foundation.utility.KeyboardHelper; import com.simibubi.create.AllKeys;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@ -71,7 +71,7 @@ public class ScrollInput extends AbstractSimiWidget {
return false; return false;
int priorState = state; int priorState = state;
boolean shifted = KeyboardHelper.isKeyDown(KeyboardHelper.LSHIFT); boolean shifted = AllKeys.shiftDown();
int step = (int) Math.signum(delta) * (shifted ? shiftStep : 1); int step = (int) Math.signum(delta) * (shifted ? shiftStep : 1);
state += step; state += step;
if (shifted) if (shifted)

View file

@ -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;
}
}

View file

@ -40,10 +40,10 @@ public class RotationPropagator {
final World world = from.getWorld(); final World world = from.getWorld();
IProperty<Axis> axisProperty = BlockStateProperties.AXIS; IProperty<Axis> axisProperty = BlockStateProperties.AXIS;
boolean connectedByAxis = definitionFrom.isAxisTowards(world, from.getPos(), stateFrom, direction) boolean connectedByAxis = definitionFrom.hasShaftTowards(world, from.getPos(), stateFrom, direction)
&& definitionTo.isAxisTowards(world, to.getPos(), stateTo, direction.getOpposite()); && definitionTo.hasShaftTowards(world, to.getPos(), stateTo, direction.getOpposite());
boolean connectedByGears = definitionFrom.isGearTowards(world, from.getPos(), stateFrom, direction) boolean connectedByGears = definitionFrom.hasCogsTowards(world, from.getPos(), stateFrom, direction)
&& definitionTo.isGearTowards(world, to.getPos(), stateTo, direction.getOpposite()); && definitionTo.hasCogsTowards(world, to.getPos(), stateTo, direction.getOpposite());
// Belt <-> Belt // Belt <-> Belt
if (from instanceof BeltTileEntity && to instanceof BeltTileEntity && !connectedByAxis) { if (from instanceof BeltTileEntity && to instanceof BeltTileEntity && !connectedByAxis) {

View file

@ -8,8 +8,8 @@ import net.minecraft.world.World;
public interface IRotate { public interface IRotate {
public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face); public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face);
public boolean isGearTowards(World world, BlockPos pos, BlockState state, Direction face); public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face);
public Axis getRotationAxis(BlockState state); public Axis getRotationAxis(BlockState state);

View file

@ -26,12 +26,12 @@ public abstract class KineticBlock extends InfoBlock implements IRotate {
// IRotate // IRotate
@Override @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; return false;
} }
@Override @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; return false;
} }

View file

@ -36,7 +36,7 @@ public class MotorBlock extends HorizontalKineticBlock {
// IRotate: // IRotate:
@Override @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); return face == state.get(HORIZONTAL_FACING);
} }

View file

@ -123,7 +123,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock {
} }
@Override @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(); return state.get(HORIZONTAL_FACING).getAxis() == face.getAxis();
} }

View file

@ -153,7 +153,7 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock {
} }
@Override @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); return face.getAxis() == state.get(AXIS);
} }

View file

@ -82,7 +82,7 @@ public class DrillBlock extends DirectionalKineticBlock implements IHaveMovement
} }
@Override @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(); 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); BlockPos offsetPos = pos.offset(direction);
BlockState blockStateAttached = world.getBlockState(offsetPos); BlockState blockStateAttached = world.getBlockState(offsetPos);
if (blockStateAttached.getBlock() instanceof IRotate && ((IRotate) blockStateAttached.getBlock()) 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 true;
} }
return false; return false;

View file

@ -6,6 +6,7 @@ import static net.minecraft.util.Direction.AxisDirection.POSITIVE;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
@ -21,6 +22,8 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity; 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.CompoundNBT;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListNBT;
@ -81,6 +84,16 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable
public ProcessedItem(ItemEntity item) { public ProcessedItem(ItemEntity item) {
entity = 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.setFire(10);
entity.attackEntityFrom(damageSourceLava, 8); 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)) { for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(null, backBB)) {
@ -340,15 +365,25 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable
if (findLoadedItems) { if (findLoadedItems) {
findLoadedItems = false; findLoadedItems = false;
for (ProcessedItem item : items) { Iterator<ProcessedItem> iterator = items.iterator();
while (iterator.hasNext()) {
ProcessedItem item = iterator.next();
for (Entity entity : frontEntities) { for (Entity entity : frontEntities) {
if (!(entity instanceof ItemEntity)) if (!(entity instanceof ItemEntity))
continue; continue;
if (entity.getUniqueID().equals(item.loadedUUID)) if (entity.getUniqueID().equals(item.loadedUUID))
item.entity = (ItemEntity) entity; 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) { protected void moveEntity(Entity entity, boolean push) {

View file

@ -92,7 +92,7 @@ public class TurntableBlock extends KineticBlock {
// IRotate: // IRotate:
@Override @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; return face == Direction.DOWN;
} }

View file

@ -4,21 +4,12 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
import net.minecraft.client.Minecraft; 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 { public class TurntableHandler {
@SubscribeEvent public static void gameRenderTick() {
public static void onRenderTick(RenderTickEvent event) {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
if (mc.world == null || mc.player == null)
return;
if (!AllBlocks.TURNTABLE.typeOf(mc.world.getBlockState(mc.player.getPosition()))) if (!AllBlocks.TURNTABLE.typeOf(mc.world.getBlockState(mc.player.getPosition())))
return; return;

View file

@ -101,7 +101,7 @@ public class MechanicalPistonBlock extends KineticBlock {
} }
@Override @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); return face.getAxis() == getRotationAxis(state);
} }

View file

@ -61,7 +61,7 @@ public class CogWheelBlock extends ShaftBlock {
// IRotate // IRotate
@Override @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); return !isLarge && face.getAxis() != state.get(AXIS);
} }

View file

@ -85,7 +85,7 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
} }
@Override @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); return face.getAxis() == state.get(AXIS);
} }

View file

@ -43,7 +43,7 @@ public class EncasedShaftBlock extends RotatedPillarKineticBlock {
} }
@Override @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); return face.getAxis() == state.get(AXIS);
} }

View file

@ -31,7 +31,7 @@ public class GearboxBlock extends RotatedPillarKineticBlock {
// IRotate: // IRotate:
@Override @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); return face.getAxis() != state.get(AXIS);
} }

View file

@ -64,8 +64,8 @@ public class GearshiftBlock extends EncasedShaftBlock {
} }
} }
public boolean isAxisTowards(World world, BlockPos pos, BlockState state, Direction face) { public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
return super.isAxisTowards(world, pos, state, face); return super.hasShaftTowards(world, pos, state, face);
} }
} }

View file

@ -53,7 +53,7 @@ public class ShaftBlock extends RotatedPillarKineticBlock {
// IRotate: // IRotate:
@Override @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); return face.getAxis() == state.get(AXIS);
} }

View file

@ -280,7 +280,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt
} }
@Override @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)) if (face.getAxis() != getRotationAxis(state))
return false; return false;
BeltTileEntity beltEntity = (BeltTileEntity) world.getTileEntity(pos); BeltTileEntity beltEntity = (BeltTileEntity) world.getTileEntity(pos);

View file

@ -21,22 +21,12 @@ import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; 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 { public class BeltItemHandler {
private static Random r = new Random(); private static Random r = new Random();
@SubscribeEvent public static void gameTick() {
public static void onClientTick(ClientTickEvent event) {
if (event.phase == Phase.START)
return;
PlayerEntity player = Minecraft.getInstance().player; PlayerEntity player = Minecraft.getInstance().player;
World world = Minecraft.getInstance().world; World world = Minecraft.getInstance().world;

View file

@ -8,13 +8,14 @@ import java.util.List;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.AllBlocks; 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.AbstractSimiContainerScreen;
import com.simibubi.create.foundation.gui.ScreenResources; import com.simibubi.create.foundation.gui.ScreenResources;
import com.simibubi.create.foundation.gui.widgets.IconButton; import com.simibubi.create.foundation.gui.widgets.IconButton;
import com.simibubi.create.foundation.gui.widgets.Label; import com.simibubi.create.foundation.gui.widgets.Label;
import com.simibubi.create.foundation.gui.widgets.ScrollInput; import com.simibubi.create.foundation.gui.widgets.ScrollInput;
import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput; import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput;
import com.simibubi.create.modules.schematics.ClientSchematicLoader;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.IHasContainer; import net.minecraft.client.gui.IHasContainer;
@ -52,8 +53,8 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
int mainLeft = guiLeft - 56; int mainLeft = guiLeft - 56;
int mainTop = guiTop - 16; int mainTop = guiTop - 16;
Create.cSchematicLoader.refresh(); CreateClient.schematicSender.refresh();
List<String> availableSchematics = Create.cSchematicLoader.getAvailableSchematics(); List<String> availableSchematics = CreateClient.schematicSender.getAvailableSchematics();
schematicsLabel = new Label(mainLeft + 36, mainTop + 26, "").withShadow(); schematicsLabel = new Label(mainLeft + 36, mainTop + 26, "").withShadow();
schematicsLabel.text = ""; schematicsLabel.text = "";
@ -172,13 +173,15 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
@Override @Override
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) { 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() if (confirmButton.active && confirmButton.isHovered() && ((SchematicTableContainer) container).canWrite()
&& schematicsArea != null) { && schematicsArea != null) {
lastChasingProgress = chasingProgress = progress = 0; lastChasingProgress = chasingProgress = progress = 0;
List<String> availableSchematics = Create.cSchematicLoader.getAvailableSchematics(); List<String> availableSchematics = schematicSender.getAvailableSchematics();
String schematic = availableSchematics.get(schematicsArea.getState()); String schematic = availableSchematics.get(schematicsArea.getState());
Create.cSchematicLoader.startNewUpload(schematic); schematicSender.startNewUpload(schematic);
} }
if (folderButton.isHovered()) { if (folderButton.isHovered()) {
@ -186,8 +189,8 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
} }
if (refreshButton.isHovered()) { if (refreshButton.isHovered()) {
Create.cSchematicLoader.refresh(); schematicSender.refresh();
List<String> availableSchematics = Create.cSchematicLoader.getAvailableSchematics(); List<String> availableSchematics = schematicSender.getAvailableSchematics();
widgets.remove(schematicsArea); widgets.remove(schematicsArea);
if (!availableSchematics.isEmpty()) { if (!availableSchematics.isEmpty()) {

View file

@ -7,15 +7,14 @@ import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.AllKeys;
import com.simibubi.create.AllSpecialTextures; import com.simibubi.create.AllSpecialTextures;
import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.ScreenOpener;
import com.simibubi.create.foundation.gui.TextInputPromptScreen; import com.simibubi.create.foundation.gui.TextInputPromptScreen;
import com.simibubi.create.foundation.utility.FilesHelper; 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;
import com.simibubi.create.foundation.utility.RaycastHelper.PredicateTraceResult; import com.simibubi.create.foundation.utility.RaycastHelper.PredicateTraceResult;
import com.simibubi.create.foundation.utility.TessellatorHelper; 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.StringTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.gen.feature.template.Template; 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 SchematicAndQuillHandler {
public class BlueprintAndQuillHandler {
static BlockPos firstPos; private BlockPos firstPos;
static BlockPos secondPos; private BlockPos secondPos;
static BlockPos selectedPos; private BlockPos selectedPos;
static Direction selectedFace; private Direction selectedFace;
static int range = 10; private int range = 10;
private static boolean active() { private boolean isActive() {
return present() && AllItems.BLUEPRINT_AND_QUILL.typeOf(Minecraft.getInstance().player.getHeldItemMainhand()); 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 return Minecraft.getInstance() != null && Minecraft.getInstance().world != null
&& Minecraft.getInstance().currentScreen == null; && Minecraft.getInstance().currentScreen == null;
} }
@SubscribeEvent public boolean mouseScrolled(double delta) {
// TODO: This is a fabricated event call by ScrollFixer until a proper event if (!isActive())
// exists return false;
public static void onMouseScrolled(MouseScrollEvent.Post event) { if (!AllKeys.ctrlDown())
if (event.getGui() != null) return false;
return;
if (!active())
return;
if (!KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL))
return;
int delta = (int) event.getScrollDelta();
if (secondPos == null) if (secondPos == null)
range = (int) MathHelper.clamp(range + delta, 1, 100); range = (int) MathHelper.clamp(range + delta, 1, 100);
if (selectedFace != null) { if (selectedFace != null) {
MutableBoundingBox bb = new MutableBoundingBox(firstPos, secondPos); MutableBoundingBox bb = new MutableBoundingBox(firstPos, secondPos);
Vec3i vec = selectedFace.getDirectionVec(); Vec3i vec = selectedFace.getDirectionVec();
int x = vec.getX() * delta; int x = (int) (vec.getX() * delta);
int y = vec.getY() * delta; int y = (int) (vec.getY() * delta);
int z = vec.getZ() * delta; int z = (int) (vec.getZ() * delta);
AxisDirection axisDirection = selectedFace.getAxisDirection(); AxisDirection axisDirection = selectedFace.getAxisDirection();
if (axisDirection == AxisDirection.NEGATIVE) if (axisDirection == AxisDirection.NEGATIVE)
@ -107,17 +90,15 @@ public class BlueprintAndQuillHandler {
true); true);
} }
event.setCanceled(true); return true;
} }
@SubscribeEvent public void onMouseInput(int button, boolean pressed) {
public static void onClick(MouseInputEvent event) { if (!pressed || button != 1)
if (event.getAction() != KeyboardHelper.PRESS)
return; return;
if (event.getButton() != 1) if (!isActive())
return;
if (!active())
return; return;
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
if (player.isSneaking()) { if (player.isSneaking()) {
@ -128,7 +109,7 @@ public class BlueprintAndQuillHandler {
} }
if (secondPos != null) { 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.setTitle("Enter a name for the Schematic:");
guiScreenIn.setButtonTextConfirm("Save"); guiScreenIn.setButtonTextConfirm("Save");
@ -152,7 +133,7 @@ public class BlueprintAndQuillHandler {
player.sendStatusMessage(new StringTextComponent(TextFormatting.GREEN + "First position set."), true); 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(); Template t = new Template();
MutableBoundingBox bb = new MutableBoundingBox(firstPos, secondPos); MutableBoundingBox bb = new MutableBoundingBox(firstPos, secondPos);
t.takeBlocksFromWorld(Minecraft.getInstance().world, new BlockPos(bb.minX, bb.minY, bb.minZ), 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); Minecraft.getInstance().player.sendStatusMessage(new StringTextComponent("Saved as " + filepath), true);
} }
@SubscribeEvent public void render() {
public static void onRenderWorld(RenderWorldLastEvent event) { if (!isActive())
if (!active())
return; return;
TessellatorHelper.prepareForDrawing(); 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); max.getX() + 1 / 16d, max.getY() + 1 / 16d, max.getZ() + 1 / 16d, red, green, 1, 1);
} }
@SubscribeEvent public void tick() {
public static void onClientTick(ClientTickEvent event) { if (!isActive())
if (event.phase == Phase.START)
return;
if (!active())
return; return;
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
selectedPos = null; selectedPos = null;
if (KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL)) { if (AllKeys.ACTIVATE_TOOL.isPressed()) {
selectedPos = new BlockPos(player.getEyePosition(Minecraft.getInstance().getRenderPartialTicks()) selectedPos = new BlockPos(player.getEyePosition(Minecraft.getInstance().getRenderPartialTicks())
.add(player.getLookVec().scale(range))); .add(player.getLookVec().scale(range)));
} else { } else {

View file

@ -6,6 +6,7 @@ import java.util.List;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.CreateClient;
import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AbstractSimiScreen;
import com.simibubi.create.foundation.gui.ScreenResources; import com.simibubi.create.foundation.gui.ScreenResources;
import com.simibubi.create.foundation.gui.widgets.Label; 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.Rotation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
public class BlueprintEditScreen extends AbstractSimiScreen { public class SchematicEditScreen extends AbstractSimiScreen {
private TextFieldWidget xInput; private TextFieldWidget xInput;
private TextFieldWidget yInput; private TextFieldWidget yInput;
@ -30,22 +31,23 @@ public class BlueprintEditScreen extends AbstractSimiScreen {
private ScrollInput rotationArea; private ScrollInput rotationArea;
private ScrollInput mirrorArea; private ScrollInput mirrorArea;
private SchematicHandler handler;
@Override @Override
protected void init() { protected void init() {
setWindowSize(ScreenResources.SCHEMATIC.width + 50, ScreenResources.SCHEMATIC.height); setWindowSize(ScreenResources.SCHEMATIC.width + 50, ScreenResources.SCHEMATIC.height);
int x = guiLeft; int x = guiLeft;
int y = guiTop; int y = guiTop;
BlueprintHandler bh = BlueprintHandler.instance; handler = CreateClient.schematicHandler;
xInput = new TextFieldWidget(font, x + 75, y + 32, 32, 10, ""); xInput = new TextFieldWidget(font, x + 75, y + 32, 32, 10, "");
yInput = new TextFieldWidget(font, x + 115, y + 32, 32, 10, ""); yInput = new TextFieldWidget(font, x + 115, y + 32, 32, 10, "");
zInput = new TextFieldWidget(font, x + 155, y + 32, 32, 10, ""); zInput = new TextFieldWidget(font, x + 155, y + 32, 32, 10, "");
if (bh.deployed) { if (handler.deployed) {
xInput.setText("" + bh.anchor.getX()); xInput.setText("" + handler.anchor.getX());
yInput.setText("" + bh.anchor.getY()); yInput.setText("" + handler.anchor.getY());
zInput.setText("" + bh.anchor.getZ()); zInput.setText("" + handler.anchor.getZ());
} else { } else {
BlockPos alt = minecraft.player.getPosition(); BlockPos alt = minecraft.player.getPosition();
xInput.setText("" + alt.getX()); xInput.setText("" + alt.getX());
@ -73,11 +75,11 @@ public class BlueprintEditScreen extends AbstractSimiScreen {
Label labelR = new Label(x + 99, y + 52, "").withShadow(); Label labelR = new Label(x + 99, y + 52, "").withShadow();
rotationArea = new SelectionScrollInput(x + 96, y + 49, 94, 14).forOptions(rotationOptions).titled("Rotation") 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(); Label labelM = new Label(x + 99, y + 72, "").withShadow();
mirrorArea = new SelectionScrollInput(x + 96, y + 69, 94, 14).forOptions(mirrorOptions).titled("Mirror") 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, xInput, yInput, zInput);
Collections.addAll(widgets, labelR, labelM, rotationArea, mirrorArea); Collections.addAll(widgets, labelR, labelM, rotationArea, mirrorArea);
@ -120,10 +122,9 @@ public class BlueprintEditScreen extends AbstractSimiScreen {
int x = guiLeft; int x = guiLeft;
int y = guiTop; int y = guiTop;
ScreenResources.SCHEMATIC.draw(this, x, y); ScreenResources.SCHEMATIC.draw(this, x, y);
BlueprintHandler bh = BlueprintHandler.instance;
font.drawStringWithShadow(bh.cachedSchematicName, x + 103 - font.getStringWidth(bh.cachedSchematicName) / 2, font.drawStringWithShadow(handler.cachedSchematicName,
y + 10, 0xDDEEFF); x + 103 - font.getStringWidth(handler.cachedSchematicName) / 2, y + 10, 0xDDEEFF);
font.drawString("Position", x + 10, y + 32, ScreenResources.FONT_COLOR); font.drawString("Position", x + 10, y + 32, ScreenResources.FONT_COLOR);
font.drawString("Rotation", x + 10, y + 52, ScreenResources.FONT_COLOR); font.drawString("Rotation", x + 10, y + 52, ScreenResources.FONT_COLOR);
@ -138,9 +139,6 @@ public class BlueprintEditScreen extends AbstractSimiScreen {
@Override @Override
public void removed() { public void removed() {
// notify Blueprinthandler
BlueprintHandler bh = BlueprintHandler.instance;
boolean validCoords = true; boolean validCoords = true;
BlockPos newLocation = null; BlockPos newLocation = null;
try { try {
@ -151,9 +149,9 @@ public class BlueprintEditScreen extends AbstractSimiScreen {
} }
if (validCoords) if (validCoords)
bh.moveTo(newLocation); handler.moveTo(newLocation);
bh.setRotation(Rotation.values()[rotationArea.getState()]); handler.setRotation(Rotation.values()[rotationArea.getState()]);
bh.setMirror(Mirror.values()[mirrorArea.getState()]); handler.setMirror(Mirror.values()[mirrorArea.getState()]);
} }
} }

View file

@ -2,16 +2,14 @@ package com.simibubi.create.modules.schematics.client;
import java.util.HashMap; import java.util.HashMap;
import org.lwjgl.glfw.GLFW;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.AllKeys;
import com.simibubi.create.AllPackets; 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.gui.ToolSelectionScreen;
import com.simibubi.create.foundation.packet.NbtPacket; import com.simibubi.create.foundation.packet.NbtPacket;
import com.simibubi.create.foundation.type.Cuboid; 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.foundation.utility.TessellatorHelper;
import com.simibubi.create.modules.schematics.SchematicWorld; import com.simibubi.create.modules.schematics.SchematicWorld;
import com.simibubi.create.modules.schematics.client.tools.Tools; 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.util.text.StringTextComponent;
import net.minecraft.world.gen.feature.template.PlacementSettings; import net.minecraft.world.gen.feature.template.PlacementSettings;
import net.minecraft.world.gen.feature.template.Template; 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 SchematicHandler {
public class BlueprintHandler {
public static BlueprintHandler instance;
public Template cachedSchematic; public Template cachedSchematic;
public String cachedSchematicName; public String cachedSchematicName;
@ -69,137 +52,104 @@ public class BlueprintHandler {
private BlueprintHotbarOverlay overlay; private BlueprintHotbarOverlay overlay;
public BlueprintHandler() { public SchematicHandler() {
instance = this;
currentTool = Tools.Deploy; currentTool = Tools.Deploy;
overlay = new BlueprintHotbarOverlay(); overlay = new BlueprintHotbarOverlay();
selectionScreen = new ToolSelectionScreen(ImmutableList.of(Tools.Deploy), this::equip); selectionScreen = new ToolSelectionScreen(ImmutableList.of(Tools.Deploy), this::equip);
} }
@SubscribeEvent public void tick() {
public static void onClientTick(ClientTickEvent event) {
if (event.phase == Phase.START)
return;
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
if (player == null)
return;
ItemStack stack = findBlueprintInHand(player); ItemStack stack = findBlueprintInHand(player);
if (stack == null) { if (stack == null) {
instance.active = false; active = false;
instance.syncCooldown = 0; syncCooldown = 0;
if (instance.item != null && itemLost(player)) { if (item != null && itemLost(player)) {
instance.slot = 0; slot = 0;
instance.item = null; item = null;
SchematicHologram.reset(); CreateClient.schematicHologram.setActive(false);
} }
return; return;
} }
// Newly equipped // Newly equipped
if (!instance.active || !stack.getTag().getString("File").equals(instance.cachedSchematicName)) { if (!active || !stack.getTag().getString("File").equals(cachedSchematicName)) {
instance.loadSettings(stack); loadSettings(stack);
instance.cachedSchematicName = stack.getTag().getString("File"); cachedSchematicName = stack.getTag().getString("File");
instance.active = true; active = true;
if (instance.deployed) { if (deployed) {
Tools toolBefore = instance.currentTool; Tools toolBefore = currentTool;
instance.selectionScreen = new ToolSelectionScreen(Tools.getTools(player.isCreative()), selectionScreen = new ToolSelectionScreen(Tools.getTools(player.isCreative()), this::equip);
instance::equip);
if (toolBefore != null) { if (toolBefore != null) {
instance.selectionScreen.setSelectedElement(toolBefore); selectionScreen.setSelectedElement(toolBefore);
instance.equip(toolBefore); equip(toolBefore);
} }
} else } else
instance.selectionScreen = new ToolSelectionScreen(ImmutableList.of(Tools.Deploy), instance::equip); selectionScreen = new ToolSelectionScreen(ImmutableList.of(Tools.Deploy), this::equip);
instance.sync(); sync();
} }
if (!instance.active) if (!active)
return; return;
if (instance.syncCooldown > 0) if (syncCooldown > 0)
instance.syncCooldown--; syncCooldown--;
if (instance.syncCooldown == 1) if (syncCooldown == 1)
instance.sync(); sync();
instance.selectionScreen.update(); selectionScreen.update();
instance.currentTool.getTool().updateSelection(); currentTool.getTool().updateSelection();
} }
@SubscribeEvent public void render() {
public static void onRenderWorld(RenderWorldLastEvent event) { if (!active)
if (!instance.active)
return; return;
if (Minecraft.getInstance().player.isSneaking()) if (Minecraft.getInstance().player.isSneaking())
return; return;
TessellatorHelper.prepareForDrawing(); TessellatorHelper.prepareForDrawing();
instance.currentTool.getTool().renderTool(); currentTool.getTool().renderTool();
TessellatorHelper.cleanUpAfterDrawing(); TessellatorHelper.cleanUpAfterDrawing();
} }
@SubscribeEvent public void renderOverlay() {
public static void onRenderOverlay(RenderGameOverlayEvent.Post event) { if (!active)
if (!instance.active)
return; return;
if (event.getType() != ElementType.HOTBAR) if (item != null)
return; overlay.renderOn(slot);
if (instance.item != null)
instance.overlay.renderOn(instance.slot);
instance.currentTool.getTool().renderOverlay(); currentTool.getTool().renderOverlay();
instance.selectionScreen.renderPassive(event.getPartialTicks()); selectionScreen.renderPassive(Minecraft.getInstance().getRenderPartialTicks());
} }
@SubscribeEvent public void onMouseInput(int button, boolean pressed) {
public static void onClick(MouseInputEvent event) { if (!active)
if (Minecraft.getInstance().currentScreen != null)
return; return;
if (event.getAction() != KeyboardHelper.PRESS) if (!pressed || button != 1)
return;
if (event.getButton() != 1)
return;
if (!instance.active)
return; return;
if (Minecraft.getInstance().player.isSneaking()) if (Minecraft.getInstance().player.isSneaking())
return; return;
instance.currentTool.getTool().handleRightClick(); currentTool.getTool().handleRightClick();
} }
@SubscribeEvent public void onKeyInput(int key, boolean pressed) {
public static void onKeyTyped(KeyInputEvent event) { if (!active)
if (Minecraft.getInstance().currentScreen != null)
return; return;
if (event.getKey() != Create.TOOL_MENU.getKey().getKeyCode()) if (key != AllKeys.TOOL_MENU.getBoundCode())
return;
if (!instance.active)
return; return;
boolean released = event.getAction() == KeyboardHelper.RELEASE; if (pressed && !selectionScreen.focused)
selectionScreen.focused = true;
ToolSelectionScreen toolSelection = instance.selectionScreen; if (!pressed && selectionScreen.focused) {
if (released && toolSelection.focused) { selectionScreen.focused = false;
toolSelection.focused = false; selectionScreen.onClose();
toolSelection.onClose();
} }
if (!released && !toolSelection.focused)
toolSelection.focused = true;
} }
@SubscribeEvent public boolean mouseScrolled(double delta) {
// 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) {
if (!active) if (!active)
return false; return false;
if (Minecraft.getInstance().player.isSneaking()) if (Minecraft.getInstance().player.isSneaking())
@ -208,30 +158,30 @@ public class BlueprintHandler {
selectionScreen.cycle((int) delta); selectionScreen.cycle((int) delta);
return true; return true;
} }
if (KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL)) { if (AllKeys.ACTIVATE_TOOL.isPressed()) {
return currentTool.getTool().handleMouseWheel(delta); return currentTool.getTool().handleMouseWheel(delta);
} }
return false; return false;
} }
private static ItemStack findBlueprintInHand(PlayerEntity player) { private ItemStack findBlueprintInHand(PlayerEntity player) {
ItemStack stack = player.getHeldItemMainhand(); ItemStack stack = player.getHeldItemMainhand();
if (!AllItems.BLUEPRINT.typeOf(stack)) if (!AllItems.BLUEPRINT.typeOf(stack))
return null; return null;
if (!stack.hasTag()) if (!stack.hasTag())
return null; return null;
instance.item = stack; item = stack;
instance.slot = player.inventory.currentItem; slot = player.inventory.currentItem;
return stack; return stack;
} }
private static boolean itemLost(PlayerEntity player) { private boolean itemLost(PlayerEntity player) {
for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) { for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) {
if (!player.inventory.getStackInSlot(i).isItemEqual(instance.item)) if (!player.inventory.getStackInSlot(i).isItemEqual(item))
continue; continue;
if (!ItemStack.areItemStackTagsEqual(player.inventory.getStackInSlot(i), instance.item)) if (!ItemStack.areItemStackTagsEqual(player.inventory.getStackInSlot(i), item))
continue; continue;
return false; return false;
} }
@ -240,7 +190,7 @@ public class BlueprintHandler {
public void markDirty() { public void markDirty() {
syncCooldown = SYNC_DELAY; syncCooldown = SYNC_DELAY;
SchematicHologram.reset(); CreateClient.schematicHologram.setActive(false);
} }
public void sync() { public void sync() {
@ -352,8 +302,8 @@ public class BlueprintHandler {
public void moveTo(BlockPos anchor) { public void moveTo(BlockPos anchor) {
if (!deployed) if (!deployed)
instance.selectionScreen = new ToolSelectionScreen( selectionScreen = new ToolSelectionScreen(Tools.getTools(Minecraft.getInstance().player.isCreative()),
Tools.getTools(Minecraft.getInstance().player.isCreative()), instance::equip); this::equip);
deployed = true; deployed = true;
this.anchor = anchor; this.anchor = anchor;
@ -367,7 +317,7 @@ public class BlueprintHandler {
CompoundNBT nbt = item.getTag(); CompoundNBT nbt = item.getTag();
nbt.putBoolean("Deployed", false); nbt.putBoolean("Deployed", false);
item.setTag(nbt); item.setTag(nbt);
SchematicHologram.reset(); CreateClient.schematicHologram.setActive(false);
active = false; active = false;
} }

View file

@ -31,44 +31,27 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.gen.feature.template.PlacementSettings; import net.minecraft.world.gen.feature.template.PlacementSettings;
import net.minecraft.world.gen.feature.template.Template; 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.ForgeHooksClient;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.model.data.EmptyModelData; 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 { public class SchematicHologram {
// These buffers are large enough for an entire chunk, consider using private final RegionRenderCacheBuilder bufferCache = new RegionRenderCacheBuilder();
// smaller buffers private final boolean[] usedBlockRenderLayers = new boolean[BlockRenderLayer.values().length];
private static final RegionRenderCacheBuilder bufferCache = new RegionRenderCacheBuilder(); private final boolean[] startedBufferBuilders = new boolean[BlockRenderLayer.values().length];
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 boolean active; private boolean active;
private boolean changed; private boolean changed;
private SchematicWorld schematic; private SchematicWorld schematic;
private BlockPos anchor; private BlockPos anchor;
public SchematicHologram() { public SchematicHologram() {
instance = this;
changed = false; changed = false;
} }
public void startHologram(Template schematic, BlockPos anchor) { public void startHologram(Template schematic, BlockPos anchor) {
this.schematic = new SchematicWorld(new HashMap<>(), new Cuboid(BlockPos.ZERO, BlockPos.ZERO), anchor); SchematicWorld world = new SchematicWorld(new HashMap<>(), new Cuboid(BlockPos.ZERO, BlockPos.ZERO), anchor);
this.anchor = anchor; schematic.addBlocksToWorld(world, anchor, new PlacementSettings());
schematic.addBlocksToWorld(this.schematic, anchor, new PlacementSettings()); startHologram(world);
active = true;
changed = true;
} }
public void startHologram(SchematicWorld world) { public void startHologram(SchematicWorld world) {
@ -78,49 +61,40 @@ public class SchematicHologram {
this.changed = true; this.changed = true;
} }
public static SchematicHologram getInstance() { public void setActive(boolean active) {
return instance; this.active = active;
} }
public static void reset() { public void update() {
instance = null;
}
public void schematicChanged() {
changed = true; changed = true;
} }
@SubscribeEvent public void tick() {
public static void onClientTickEvent(final ClientTickEvent event) { if (!active)
if (event.phase == Phase.START)
return; return;
if (instance != null && instance.active) { Minecraft minecraft = Minecraft.getInstance();
final Minecraft minecraft = Minecraft.getInstance(); if (minecraft.world == null)
if (event.phase != TickEvent.Phase.END) return;
return; if (minecraft.player == null)
if (minecraft.world == null) return;
return; if (changed) {
if (minecraft.player == null) redraw(minecraft);
return; changed = false;
if (instance.changed) {
redraw(minecraft);
instance.changed = false;
}
} }
} }
private static void redraw(final Minecraft minecraft) { private void redraw(Minecraft minecraft) {
Arrays.fill(usedBlockRenderLayers, false); Arrays.fill(usedBlockRenderLayers, false);
Arrays.fill(startedBufferBuilders, false); Arrays.fill(startedBufferBuilders, false);
final SchematicWorld blockAccess = instance.schematic; final SchematicWorld blockAccess = schematic;
final BlockRendererDispatcher blockRendererDispatcher = minecraft.getBlockRendererDispatcher(); final BlockRendererDispatcher blockRendererDispatcher = minecraft.getBlockRendererDispatcher();
List<BlockState> blockstates = new LinkedList<>(); List<BlockState> blockstates = new LinkedList<>();
for (BlockPos localPos : BlockPos.getAllInBoxMutable(blockAccess.getBounds().getOrigin(), for (BlockPos localPos : BlockPos.getAllInBoxMutable(blockAccess.getBounds().getOrigin(),
blockAccess.getBounds().getOrigin().add(blockAccess.getBounds().getSize()))) { blockAccess.getBounds().getOrigin().add(blockAccess.getBounds().getSize()))) {
BlockPos pos = localPos.add(instance.anchor); BlockPos pos = localPos.add(anchor);
BlockState state = blockAccess.getBlockState(pos); BlockState state = blockAccess.getBlockState(pos);
for (BlockRenderLayer blockRenderLayer : BlockRenderLayer.values()) { for (BlockRenderLayer blockRenderLayer : BlockRenderLayer.values()) {
if (!state.getBlock().canRenderInLayer(state, blockRenderLayer)) { if (!state.getBlock().canRenderInLayer(state, blockRenderLayer)) {
@ -163,9 +137,8 @@ public class SchematicHologram {
} }
} }
@SubscribeEvent public void render() {
public static void onRenderWorldLastEvent(final RenderWorldLastEvent event) { if (active) {
if (instance != null && instance.active) {
final Entity entity = Minecraft.getInstance().getRenderViewEntity(); final Entity entity = Minecraft.getInstance().getRenderViewEntity();
if (entity == null) { if (entity == null) {

View file

@ -1,9 +1,7 @@
package com.simibubi.create.modules.schematics.client.tools; package com.simibubi.create.modules.schematics.client.tools;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.GlStateManager; 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.client.renderer.WorldRenderer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -20,11 +18,11 @@ public class DeployTool extends PlacementToolBase {
@Override @Override
public void updateSelection() { public void updateSelection() {
if (blueprint.active && selectionRange == -1) { if (schematicHandler.active && selectionRange == -1) {
selectionRange = (int) blueprint.size.manhattanDistance(BlockPos.ZERO) / 2; selectionRange = (int) schematicHandler.size.manhattanDistance(BlockPos.ZERO) / 2;
selectionRange = MathHelper.clamp(selectionRange, 1, 100); selectionRange = MathHelper.clamp(selectionRange, 1, 100);
} }
selectIgnoreBlocks = KeyboardHelper.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL); selectIgnoreBlocks = AllKeys.ACTIVATE_TOOL.isPressed();
super.updateSelection(); super.updateSelection();
} }
@ -36,12 +34,12 @@ public class DeployTool extends PlacementToolBase {
if (selectedPos == null) if (selectedPos == null)
return; 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 min = selectedPos.add(Math.round(size.getX() * -.5f), 0, Math.round(size.getZ() * -.5f));
BlockPos max = min.add(size.getX(), size.getY(), size.getZ()); BlockPos max = min.add(size.getX(), size.getY(), size.getZ());
if (blueprint.deployed) { if (schematicHandler.deployed) {
MutableBoundingBox bb = new MutableBoundingBox(min, min.add(blueprint.getTransformedSize())); MutableBoundingBox bb = new MutableBoundingBox(min, min.add(schematicHandler.getTransformedSize()));
min = new BlockPos(bb.minX, bb.minY, bb.minZ); min = new BlockPos(bb.minX, bb.minY, bb.minZ);
max = new BlockPos(bb.maxX, bb.maxY, bb.maxZ); max = new BlockPos(bb.maxX, bb.maxY, bb.maxZ);
} }
@ -75,8 +73,8 @@ public class DeployTool extends PlacementToolBase {
if (selectedPos == null) if (selectedPos == null)
return super.handleRightClick(); return super.handleRightClick();
BlockPos size = blueprint.getTransformedSize(); BlockPos size = schematicHandler.getTransformedSize();
blueprint.moveTo(selectedPos.add(Math.round(size.getX() * -.5f), 0, Math.round(size.getZ() * -.5f))); schematicHandler.moveTo(selectedPos.add(Math.round(size.getX() * -.5f), 0, Math.round(size.getZ() * -.5f)));
return true; return true;
} }

View file

@ -32,7 +32,7 @@ public class FlipTool extends PlacementToolBase {
private void mirror() { private void mirror() {
if (schematicSelected && selectedFace.getAxis().isHorizontal()) { if (schematicSelected && selectedFace.getAxis().isHorizontal()) {
blueprint.flip(selectedFace.getAxis()); schematicHandler.flip(selectedFace.getAxis());
} }
} }

View file

@ -21,8 +21,8 @@ public class MoveTool extends PlacementToolBase {
@Override @Override
public boolean handleMouseWheel(double delta) { public boolean handleMouseWheel(double delta) {
if (schematicSelected && selectedFace.getAxis().isHorizontal()) { if (schematicSelected && selectedFace.getAxis().isHorizontal()) {
blueprint.moveTo(delta < 0 ? blueprint.anchor.add(selectedFace.getDirectionVec()) schematicHandler.moveTo(delta < 0 ? schematicHandler.anchor.add(selectedFace.getDirectionVec())
: blueprint.anchor.subtract(selectedFace.getDirectionVec())); : schematicHandler.anchor.subtract(selectedFace.getDirectionVec()));
} }
return true; return true;
} }

View file

@ -4,8 +4,8 @@ public class MoveVerticalTool extends PlacementToolBase {
@Override @Override
public boolean handleMouseWheel(double delta) { public boolean handleMouseWheel(double delta) {
if (blueprint.deployed) { if (schematicHandler.deployed) {
blueprint.moveTo(blueprint.anchor.add(0, delta, 0)); schematicHandler.moveTo(schematicHandler.anchor.add(0, delta, 0));
} }
return true; return true;
} }

View file

@ -4,7 +4,7 @@ public class PlaceTool extends SchematicToolBase {
@Override @Override
public boolean handleRightClick() { public boolean handleRightClick() {
blueprint.printInstantly(); schematicHandler.printInstantly();
return true; return true;
} }

View file

@ -6,7 +6,7 @@ public class RotateTool extends PlacementToolBase {
@Override @Override
public boolean handleMouseWheel(double delta) { 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; return true;
} }

View file

@ -1,12 +1,11 @@
package com.simibubi.create.modules.schematics.client.tools; package com.simibubi.create.modules.schematics.client.tools;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.GlStateManager; 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;
import com.simibubi.create.foundation.utility.RaycastHelper.PredicateTraceResult; 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.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity;
@ -23,7 +22,7 @@ import net.minecraft.util.math.Vec3d;
public abstract class SchematicToolBase implements ISchematicTool { public abstract class SchematicToolBase implements ISchematicTool {
protected BlueprintHandler blueprint; protected SchematicHandler schematicHandler;
public BlockPos selectedPos; public BlockPos selectedPos;
public boolean selectIgnoreBlocks; public boolean selectIgnoreBlocks;
@ -34,7 +33,7 @@ public abstract class SchematicToolBase implements ISchematicTool {
public Direction selectedFace; public Direction selectedFace;
public SchematicToolBase() { public SchematicToolBase() {
blueprint = BlueprintHandler.instance; schematicHandler = CreateClient.schematicHandler;
} }
@Override @Override
@ -49,9 +48,9 @@ public abstract class SchematicToolBase implements ISchematicTool {
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
// Select Blueprint // Select Blueprint
if (blueprint.deployed) { if (schematicHandler.deployed) {
BlockPos min = blueprint.getTransformedAnchor(); BlockPos min = schematicHandler.getTransformedAnchor();
MutableBoundingBox bb = new MutableBoundingBox(min, min.add(blueprint.getTransformedSize())); MutableBoundingBox bb = new MutableBoundingBox(min, min.add(schematicHandler.getTransformedSize()));
PredicateTraceResult result = RaycastHelper.rayTraceUntil(player, 70, PredicateTraceResult result = RaycastHelper.rayTraceUntil(player, 70,
pos -> bb.isVecInside(pos)); pos -> bb.isVecInside(pos));
schematicSelected = !result.missed(); schematicSelected = !result.missed();
@ -84,20 +83,20 @@ public abstract class SchematicToolBase implements ISchematicTool {
@Override @Override
public void renderTool() { public void renderTool() {
if (blueprint.deployed) { if (schematicHandler.deployed) {
GlStateManager.lineWidth(2); GlStateManager.lineWidth(2);
GlStateManager.color4f(1, 1, 1, 1); GlStateManager.color4f(1, 1, 1, 1);
GlStateManager.disableTexture(); GlStateManager.disableTexture();
BlockPos min = blueprint.getTransformedAnchor(); BlockPos min = schematicHandler.getTransformedAnchor();
MutableBoundingBox bb = new MutableBoundingBox(min, min.add(blueprint.getTransformedSize())); MutableBoundingBox bb = new MutableBoundingBox(min, min.add(schematicHandler.getTransformedSize()));
min = new BlockPos(bb.minX, bb.minY, bb.minZ); min = new BlockPos(bb.minX, bb.minY, bb.minZ);
BlockPos max = new BlockPos(bb.maxX, bb.maxY, bb.maxZ); BlockPos max = new BlockPos(bb.maxX, bb.maxY, bb.maxZ);
WorldRenderer.drawBoundingBox(min.getX() - 1 / 8d, min.getY() + 1 / 16d, min.getZ() - 1 / 8d, 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); 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 vec = new Vec3d(selectedFace.getDirectionVec());
Vec3d center = new Vec3d(min.add(max)).scale(1 / 2f); Vec3d center = new Vec3d(min.add(max)).scale(1 / 2f);
Vec3d radii = new Vec3d(max.subtract(min)).scale(1 / 2f); Vec3d radii = new Vec3d(max.subtract(min)).scale(1 / 2f);

View file

@ -2,7 +2,7 @@ package com.simibubi.create.modules.schematics.item;
import java.util.List; 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.client.util.ITooltipFlag;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -20,7 +20,7 @@ public class BlueprintAndQuillItem extends Item {
@Override @Override
public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { 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 gray = TextFormatting.GRAY;
TextFormatting blue = TextFormatting.BLUE; TextFormatting blue = TextFormatting.BLUE;

View file

@ -10,9 +10,9 @@ import java.util.List;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.AllKeys;
import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.ScreenOpener;
import com.simibubi.create.foundation.utility.KeyboardHelper; import com.simibubi.create.modules.schematics.client.SchematicEditScreen;
import com.simibubi.create.modules.schematics.client.BlueprintEditScreen;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -67,7 +67,7 @@ public class BlueprintItem extends Item {
@Override @Override
@OnlyIn(value = Dist.CLIENT) @OnlyIn(value = Dist.CLIENT)
public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { 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 gray = TextFormatting.GRAY;
tooltip.add(new StringTextComponent(gray + "Holds a structure to be printed")); tooltip.add(new StringTextComponent(gray + "Holds a structure to be printed"));
tooltip.add(new StringTextComponent(gray + "by the Schematicannon.")); tooltip.add(new StringTextComponent(gray + "by the Schematicannon."));
@ -138,7 +138,7 @@ public class BlueprintItem extends Item {
@OnlyIn(value = Dist.CLIENT) @OnlyIn(value = Dist.CLIENT)
protected void displayBlueprintScreen() { protected void displayBlueprintScreen() {
ScreenOpener.open(new BlueprintEditScreen()); ScreenOpener.open(new SchematicEditScreen());
} }
@Override @Override

View file

@ -69,13 +69,13 @@ public class SchematicUploadPacket extends SimplePacketBase {
ServerPlayerEntity player = context.get().getSender(); ServerPlayerEntity player = context.get().getSender();
if (code == BEGIN) { if (code == BEGIN) {
BlockPos pos = ((SchematicTableContainer) player.openContainer).getTileEntity().getPos(); 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) { if (code == WRITE) {
Create.sSchematicLoader.handleWriteRequest(player, schematic, data); Create.schematicReceiver.handleWriteRequest(player, schematic, data);
} }
if (code == FINISH) { if (code == FINISH) {
Create.sSchematicLoader.handleFinishedUpload(player, schematic); Create.schematicReceiver.handleFinishedUpload(player, schematic);
} }
}); });
context.get().setPacketHandled(true); context.get().setPacketHandled(true);