From b716c23e3d84bc0405f2bfb126bd60ce4395bede Mon Sep 17 00:00:00 2001 From: malte0811 Date: Fri, 30 Jun 2017 21:04:02 +0200 Subject: [PATCH] Added a way to create tilted panels in-game (no recipe yet) Panels are no longer created from machine casings, but from unfinished panels --- IEIssues.txt | 2 - .../industrialWires/IndustrialWires.java | 6 +- .../industrialWires/blocks/BlockIWBase.java | 7 +- .../blocks/controlpanel/BlockPanel.java | 23 ++-- .../blocks/controlpanel/BlockTypes_Panel.java | 3 +- .../blocks/controlpanel/ItemBlockPanel.java | 109 ++++++++++++++++++ .../blocks/controlpanel/TileEntityPanel.java | 2 +- .../controlpanel/TileEntityPanelCreator.java | 32 +++-- .../TileEntityUnfinishedPanel.java | 51 ++++++++ .../client/ClientEventHandler.java | 1 + .../industrialWires/client/RawQuad.java | 2 +- .../client/gui/GuiPanelCreator.java | 9 +- .../client/panelmodel/PanelModel.java | 5 +- .../controlpanel/PanelComponent.java | 18 +-- .../controlpanel/PanelUtils.java | 69 ++++++++--- .../controlpanel/PropertyComponents.java | 32 ++--- .../industrialWires/controlpanel/Variac.java | 1 + .../blockstates/control_panel.json | 11 +- .../assets/industrialwires/lang/en_US.lang | 4 + 19 files changed, 305 insertions(+), 82 deletions(-) delete mode 100644 IEIssues.txt create mode 100644 src/main/java/malte0811/industrialWires/blocks/controlpanel/ItemBlockPanel.java create mode 100644 src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityUnfinishedPanel.java diff --git a/IEIssues.txt b/IEIssues.txt deleted file mode 100644 index c709b28..0000000 --- a/IEIssues.txt +++ /dev/null @@ -1,2 +0,0 @@ -LV conn=rel item model -RS conns don't update color instantly \ No newline at end of file diff --git a/src/main/java/malte0811/industrialWires/IndustrialWires.java b/src/main/java/malte0811/industrialWires/IndustrialWires.java index 87cbec6..819d4cb 100644 --- a/src/main/java/malte0811/industrialWires/IndustrialWires.java +++ b/src/main/java/malte0811/industrialWires/IndustrialWires.java @@ -19,10 +19,7 @@ package malte0811.industrialWires; import malte0811.industrialWires.blocks.BlockJacobsLadder; import malte0811.industrialWires.blocks.TileEntityJacobsLadder; -import malte0811.industrialWires.blocks.controlpanel.BlockPanel; -import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel; -import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator; -import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn; +import malte0811.industrialWires.blocks.controlpanel.*; import malte0811.industrialWires.blocks.converter.BlockMechanicalConverter; import malte0811.industrialWires.blocks.converter.TileEntityIEMotor; import malte0811.industrialWires.blocks.converter.TileEntityMechICtoIE; @@ -97,6 +94,7 @@ public class IndustrialWires { GameRegistry.registerTileEntity(TileEntityPanel.class, MODID + ":control_panel"); GameRegistry.registerTileEntity(TileEntityRSPanelConn.class, MODID + ":control_panel_rs"); GameRegistry.registerTileEntity(TileEntityPanelCreator.class, MODID + ":panel_creator"); + GameRegistry.registerTileEntity(TileEntityUnfinishedPanel.class, MODID + ":unfinished_panel"); if (mechConv != null) { GameRegistry.registerTileEntity(TileEntityIEMotor.class, MODID + ":ieMotor"); GameRegistry.registerTileEntity(TileEntityMechICtoIE.class, MODID + ":mechIcToIe"); diff --git a/src/main/java/malte0811/industrialWires/blocks/BlockIWBase.java b/src/main/java/malte0811/industrialWires/blocks/BlockIWBase.java index 9c95e99..cdf6b79 100644 --- a/src/main/java/malte0811/industrialWires/blocks/BlockIWBase.java +++ b/src/main/java/malte0811/industrialWires/blocks/BlockIWBase.java @@ -32,6 +32,7 @@ import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; @@ -56,11 +57,15 @@ public abstract class BlockIWBase extends Block { setHardness(3.0F); setResistance(15.0F); GameRegistry.register(this, new ResourceLocation(IndustrialWires.MODID, name)); - GameRegistry.register(new ItemBlockIW(this), new ResourceLocation(IndustrialWires.MODID, name)); + GameRegistry.register(createItemBlock(), new ResourceLocation(IndustrialWires.MODID, name)); setUnlocalizedName(IndustrialWires.MODID + "." + name); setCreativeTab(IndustrialWires.creativeTab); } + protected ItemBlock createItemBlock() { + return new ItemBlockIW(this); + } + @Nonnull @Override protected BlockStateContainer createBlockState() { diff --git a/src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockPanel.java b/src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockPanel.java index b9139b8..50e2544 100644 --- a/src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockPanel.java +++ b/src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockPanel.java @@ -32,6 +32,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; @@ -56,6 +57,11 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum { lightOpacity = 0; } + @Override + protected ItemBlock createItemBlock() { + return new ItemBlockPanel(this); + } + @Override public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) { switch (state.getValue(type)) { @@ -77,6 +83,8 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum { return new TileEntityRSPanelConn(); case CREATOR: return new TileEntityPanelCreator(); + case UNFINISHED: + return new TileEntityUnfinishedPanel(); default: return null; } @@ -145,10 +153,9 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum { @Override public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, NonNullList list) { - list.add(new ItemStack(itemIn, 1, 0)); - list.add(new ItemStack(itemIn, 1, 1)); - list.add(new ItemStack(itemIn, 1, 2)); - list.add(new ItemStack(itemIn, 1, 3)); + for (int i = 0; i < BlockTypes_Panel.values().length; i++) { + list.add(new ItemStack(itemIn, 1, i)); + } } @Override @@ -195,11 +202,9 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum { @Override @Nonnull public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) { - if (state.getValue(type) == BlockTypes_Panel.TOP) { - TileEntity te = world.getTileEntity(pos); - if (te instanceof TileEntityPanel) { - return ((TileEntityPanel) te).getTileDrop(player, state); - } + TileEntity te = world.getTileEntity(pos); + if (te instanceof TileEntityPanel) { + return ((TileEntityPanel) te).getTileDrop(player, state); } return super.getPickBlock(state, target, world, pos, player); } diff --git a/src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockTypes_Panel.java b/src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockTypes_Panel.java index 0496484..4840df5 100644 --- a/src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockTypes_Panel.java +++ b/src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockTypes_Panel.java @@ -26,7 +26,8 @@ public enum BlockTypes_Panel implements IStringSerializable { TOP, RS_WIRE, DUMMY, - CREATOR; + CREATOR, + UNFINISHED; @Override public String getName() { diff --git a/src/main/java/malte0811/industrialWires/blocks/controlpanel/ItemBlockPanel.java b/src/main/java/malte0811/industrialWires/blocks/controlpanel/ItemBlockPanel.java new file mode 100644 index 0000000..20641c4 --- /dev/null +++ b/src/main/java/malte0811/industrialWires/blocks/controlpanel/ItemBlockPanel.java @@ -0,0 +1,109 @@ +/* + * This file is part of Industrial Wires. + * Copyright (C) 2016-2017 malte0811 + * + * Industrial Wires is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Industrial Wires is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Industrial Wires. If not, see . + */ + +package malte0811.industrialWires.blocks.controlpanel; + +import blusunrize.immersiveengineering.api.tool.IConfigurableTool; +import malte0811.industrialWires.blocks.ItemBlockIW; +import net.minecraft.block.Block; +import net.minecraft.client.resources.I18n; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.MathHelper; + +public class ItemBlockPanel extends ItemBlockIW implements IConfigurableTool { + private static final String HEIGHT = "height"; + private static final String ANGLE = "angle"; + + public ItemBlockPanel(Block b) { + super(b); + } + + @Override + public boolean canConfigure(ItemStack stack) { + return stack.getMetadata() == BlockTypes_Panel.UNFINISHED.ordinal(); + } + + @Override + public ToolConfig.ToolConfigBoolean[] getBooleanOptions(ItemStack stack) { + return new ToolConfig.ToolConfigBoolean[0]; + } + + @Override + public ToolConfig.ToolConfigFloat[] getFloatOptions(ItemStack stack) { + float height; + float angle; + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + height = .5F; + angle = 0; + } else { + height = nbt.getFloat(HEIGHT); + angle = nbt.getFloat(ANGLE); + } + angle = (float) ((angle * 180 / Math.PI + 45) / 90); + return new ToolConfig.ToolConfigFloat[]{ + new ToolConfig.ToolConfigFloat(HEIGHT, 60, 20, height), + new ToolConfig.ToolConfigFloat(ANGLE, 60, 40, angle) + }; + } + + @Override + public void applyConfigOption(ItemStack stack, String key, Object value) { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + nbt = new NBTTagCompound(); + stack.setTagCompound(nbt); + } + switch (key) { + case HEIGHT: + float angle = nbt.getFloat(ANGLE); + float halfH = (float) (.5 * Math.tan(angle)); + nbt.setFloat(HEIGHT, MathHelper.clamp((Float) value + .001F, halfH, 1 - halfH)); + break; + case ANGLE: + float height = nbt.getFloat(HEIGHT); + float angleMax = (float) Math.atan(2 * Math.min(height, 1 - height)); + float newAngle = (float) ((Math.PI / 2 * ((Float) value - .5))); + nbt.setFloat(ANGLE, MathHelper.clamp(newAngle, -angleMax, angleMax)); + break; + } + } + + @Override + public String fomatConfigName(ItemStack stack, ToolConfig config) { + switch (config.name) { + case HEIGHT: + return I18n.format("industrialwires.desc.height"); + case ANGLE: + return I18n.format("industrialwires.desc.angle"); + } + return null; + } + + @Override + public String fomatConfigDescription(ItemStack stack, ToolConfig config) { + switch (config.name) { + case HEIGHT: + return I18n.format("industrialwires.desc.height_info"); + case ANGLE: + return I18n.format("industrialwires.desc.angle_info");//TODO talk to blu to make this less awkward + } + return null; + } +} diff --git a/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanel.java b/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanel.java index b71d6ce..fee3918 100644 --- a/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanel.java +++ b/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanel.java @@ -226,7 +226,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil @Nullable public Pair getSelectedComponent(EntityPlayer player, Vec3d hit, boolean hitAbs) { - //TODO prvent clicking through the back of the panel + //TODO prevent clicking through the back of the panel Matrix4 mat = components.getPanelTopTransform(); mat.invert(); PanelComponent retPc = null; diff --git a/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanelCreator.java b/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanelCreator.java index 514c59b..63cd2f9 100644 --- a/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanelCreator.java +++ b/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanelCreator.java @@ -41,7 +41,6 @@ import java.util.List; public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI, IBlockBoundsIW { public List components = new ArrayList<>(); - public float height = 0.5F; @Nonnull public ItemStack inv = ItemStack.EMPTY; @@ -49,7 +48,6 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI, public void readNBT(NBTTagCompound nbt, boolean updatePacket) { NBTTagList l = nbt.getTagList("components", 10); PanelUtils.readListFromNBT(l, components); - height = nbt.getFloat("height"); NBTTagCompound invTag; if (nbt.hasKey("inventory", 9)) { invTag = nbt.getTagList("inventory", 10).getCompoundTagAt(0); @@ -73,7 +71,8 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI, comps.appendTag(nbtInner); } nbt.setTag("components", comps); - nbt.setFloat("height", height); + nbt.setFloat("height", PanelUtils.getHeight(inv)); + nbt.setFloat("angle", PanelUtils.getAngle(inv)); } @Override @@ -86,7 +85,6 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI, if (pc != null) { pc.setX(nbt.getFloat("x")); pc.setY(nbt.getFloat("y")); - pc.setPanelHeight(height); components.add(pc); if (!curr.isEmpty()) { curr.shrink(1); @@ -110,13 +108,24 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI, } break; case CREATE_PANEL: - if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv)) { - NBTTagCompound panelNBT = new NBTTagCompound(); - writeToItemNBT(panelNBT, true); - ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal()); - panel.setTagCompound(panelNBT); - inv = panel; - components.clear(); + if (ItemStack.areItemsEqual(PanelUtils.getPanelBase(), inv)) { + float height = PanelUtils.getHeight(inv); + float angle = PanelUtils.getAngle(inv); + boolean valid = true; + for (PanelComponent comp : components) { + if (!comp.isValidPos(components, height, angle)) { + valid = false; + break; + } + } + if (valid) { + NBTTagCompound panelNBT = new NBTTagCompound(); + writeToItemNBT(panelNBT, true); + ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal()); + panel.setTagCompound(panelNBT); + inv = panel; + components.clear(); + } } break; case REMOVE_ALL: @@ -138,7 +147,6 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI, TileEntityPanel te = new TileEntityPanel(); te.readFromItemNBT(inv.getTagCompound()); components = new ArrayList<>(te.getComponents()); - height = te.getComponents().height; inv = ItemStack.EMPTY; } break; diff --git a/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityUnfinishedPanel.java b/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityUnfinishedPanel.java new file mode 100644 index 0000000..c972346 --- /dev/null +++ b/src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityUnfinishedPanel.java @@ -0,0 +1,51 @@ +/* + * This file is part of Industrial Wires. + * Copyright (C) 2016-2017 malte0811 + * + * Industrial Wires is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Industrial Wires is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Industrial Wires. If not, see . + */ + +package malte0811.industrialWires.blocks.controlpanel; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; + +import javax.annotation.Nonnull; + +public class TileEntityUnfinishedPanel extends TileEntityPanel { + public TileEntityUnfinishedPanel() { + super(); + getComponents().clear(); + } + + @Override + public boolean interact(@Nonnull EnumFacing side, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, @Nonnull ItemStack heldItem, float hitX, float hitY, float hitZ) { + return false; + } + + @Nonnull + @Override + public ItemStack getTileDrop(@Nonnull EntityPlayer player, @Nonnull IBlockState state) { + ItemStack ret = super.getTileDrop(player, state); + ret.setItemDamage(BlockTypes_Panel.UNFINISHED.ordinal()); + NBTTagCompound nbt = ret.getTagCompound(); + if (nbt != null && nbt.hasKey("components")) + nbt.removeTag("components"); + return ret; + } +} diff --git a/src/main/java/malte0811/industrialWires/client/ClientEventHandler.java b/src/main/java/malte0811/industrialWires/client/ClientEventHandler.java index 050e7f3..dd1b26d 100644 --- a/src/main/java/malte0811/industrialWires/client/ClientEventHandler.java +++ b/src/main/java/malte0811/industrialWires/client/ClientEventHandler.java @@ -98,5 +98,6 @@ public class ClientEventHandler { @SubscribeEvent public void bakeModel(ModelBakeEvent event) { event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID + ":control_panel", "inventory,type=top"), new PanelModel()); + event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID + ":control_panel", "inventory,type=unfinished"), new PanelModel()); } } diff --git a/src/main/java/malte0811/industrialWires/client/RawQuad.java b/src/main/java/malte0811/industrialWires/client/RawQuad.java index 87c177a..0935832 100644 --- a/src/main/java/malte0811/industrialWires/client/RawQuad.java +++ b/src/main/java/malte0811/industrialWires/client/RawQuad.java @@ -71,7 +71,7 @@ public class RawQuad { if (normal != null) { this.normal = normal; } else { - this.normal = cross(sub(v1, v3, null), sub(v2, v0, null), null);//TODO is this the right way around? + this.normal = cross(sub(v1, v3, null), sub(v2, v0, null), null); this.normal.normalise(this.normal); } this.uvs = uvs; diff --git a/src/main/java/malte0811/industrialWires/client/gui/GuiPanelCreator.java b/src/main/java/malte0811/industrialWires/client/gui/GuiPanelCreator.java index 7f7b5ac..6c22e15 100644 --- a/src/main/java/malte0811/industrialWires/client/gui/GuiPanelCreator.java +++ b/src/main/java/malte0811/industrialWires/client/gui/GuiPanelCreator.java @@ -25,8 +25,10 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator; import malte0811.industrialWires.containers.ContainerPanelCreator; import malte0811.industrialWires.controlpanel.MessageType; import malte0811.industrialWires.controlpanel.PanelComponent; +import malte0811.industrialWires.controlpanel.PanelUtils; import malte0811.industrialWires.items.ItemPanelComponent; import malte0811.industrialWires.network.MessageGUIInteract; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; @@ -103,7 +105,9 @@ public class GuiPanelCreator extends GuiContainer { pc.setX(x / (float) panelSize); pc.setY(y / (float) panelSize); } - if (!pc.isValidPos(container.tile.components)) { + ItemStack unfinishedPanel = container.getInventory().get(0); + boolean red = (512 & (Minecraft.getSystemTime())) != 0; + if (red && !pc.isValidPos(container.tile.components, PanelUtils.getHeight(unfinishedPanel), PanelUtils.getAngle(unfinishedPanel))) { AxisAlignedBB aabb = pc.getBlockRelativeAABB(); int left = (int) (getX0() + aabb.minX * panelSize) - 1; int top = (int) (getY0() + aabb.minZ * panelSize) - 1; @@ -137,7 +141,8 @@ public class GuiPanelCreator extends GuiContainer { if (0 <= xRel && xRel <= panelSize && 0 <= yRel && yRel <= panelSize) { List components = container.tile.components; if (curr != null) { - if (curr.isValidPos(components)) { + ItemStack unfinishedPanel = container.getInventory().get(0); + if (curr.isValidPos(components, PanelUtils.getHeight(unfinishedPanel), PanelUtils.getAngle(unfinishedPanel))) { NBTTagCompound nbt = new NBTTagCompound(); nbt.setFloat("x", curr.getX()); nbt.setFloat("y", curr.getY()); diff --git a/src/main/java/malte0811/industrialWires/client/panelmodel/PanelModel.java b/src/main/java/malte0811/industrialWires/client/panelmodel/PanelModel.java index 96aaa5e..37b5efa 100644 --- a/src/main/java/malte0811/industrialWires/client/panelmodel/PanelModel.java +++ b/src/main/java/malte0811/industrialWires/client/panelmodel/PanelModel.java @@ -24,6 +24,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.collect.ImmutableList; import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel; import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel; +import malte0811.industrialWires.blocks.controlpanel.TileEntityUnfinishedPanel; import malte0811.industrialWires.controlpanel.PanelUtils; import malte0811.industrialWires.controlpanel.PropertyComponents; import malte0811.industrialWires.controlpanel.PropertyComponents.PanelRenderProperties; @@ -188,10 +189,10 @@ public class PanelModel implements IBakedModel { @Nonnull @Override public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) { - if (stack != null && stack.getItem() == PanelUtils.PANEL_ITEM && stack.getMetadata() == BlockTypes_Panel.TOP.ordinal()) { + if (stack != null && stack.getItem() == PanelUtils.PANEL_ITEM) { try { return ITEM_MODEL_CACHE.get(stack, () -> { - TileEntityPanel te = new TileEntityPanel(); + TileEntityPanel te = stack.getMetadata() == BlockTypes_Panel.TOP.ordinal() ? new TileEntityPanel() : new TileEntityUnfinishedPanel(); te.readFromItemNBT(stack.getTagCompound()); return new AssembledBakedModel(te.getComponents()); }); diff --git a/src/main/java/malte0811/industrialWires/controlpanel/PanelComponent.java b/src/main/java/malte0811/industrialWires/controlpanel/PanelComponent.java index 0a159bf..e499b82 100644 --- a/src/main/java/malte0811/industrialWires/controlpanel/PanelComponent.java +++ b/src/main/java/malte0811/industrialWires/controlpanel/PanelComponent.java @@ -18,7 +18,7 @@ package malte0811.industrialWires.controlpanel; -import blusunrize.immersiveengineering.common.util.IELogger; +import malte0811.industrialWires.IndustrialWires; import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel; import malte0811.industrialWires.client.RawQuad; import malte0811.industrialWires.client.gui.GuiPanelCreator; @@ -30,8 +30,10 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3d; +import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.logging.log4j.Level; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -154,7 +156,7 @@ public abstract class PanelComponent { ret.setPanelHeight(nbt.getFloat("panelHeight")); return ret; } else { - IELogger.info("(IndustrialWires) Unknown panel component: " + type);//TODO own logger? + FMLLog.log(IndustrialWires.MODID, Level.WARN, "Unknown panel component: " + type); return null; } } @@ -189,18 +191,20 @@ public abstract class PanelComponent { } - public boolean isValidPos(List components) { - AxisAlignedBB aabb = getBlockRelativeAABB().offset(0, panelHeight, 0); - if (aabb.minX < 0 || aabb.maxX > 1) { + public boolean isValidPos(List components, float height, float angle) { + float h = PanelUtils.getHeightWithComponent(this, angle, height); + if (h < 0 || h > 1) { return false; } - if (aabb.minY < 0 || aabb.maxY > 1) { + + AxisAlignedBB aabb = getBlockRelativeAABB(); + if (aabb.minX < 0 || aabb.maxX > 1) { return false; } if (aabb.minZ < 0 || aabb.maxZ > 1) { return false; } - aabb = getBlockRelativeAABB(); + for (PanelComponent pc : components) { if (pc == this) { continue; diff --git a/src/main/java/malte0811/industrialWires/controlpanel/PanelUtils.java b/src/main/java/malte0811/industrialWires/controlpanel/PanelUtils.java index c51cd8d..bd0415d 100644 --- a/src/main/java/malte0811/industrialWires/controlpanel/PanelUtils.java +++ b/src/main/java/malte0811/industrialWires/controlpanel/PanelUtils.java @@ -20,7 +20,6 @@ package malte0811.industrialWires.controlpanel; import blusunrize.immersiveengineering.api.Lib; import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4; -import ic2.api.item.IC2Items; import malte0811.industrialWires.IndustrialWires; import malte0811.industrialWires.blocks.controlpanel.BlockPanel; import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel; @@ -93,13 +92,13 @@ public final class PanelUtils { baseNorm.transpose(); List rawOut = new ArrayList<>(); - //addTexturedBox(new Vector3f(0, 0, 0), new Vector3f(1, components.height, 1), rawOut, UV_FULL, PANEL_TEXTURE); - float maxHeight = components.getPanelMaxHeight(); - float vMaxLower = 16 * components.height; - float vMaxUpper = 16 * maxHeight; + float height1 = getLocalHeightFromZ(1, components.height, components.angle); + float height0 = getLocalHeightFromZ(0, components.height, components.angle); + float vMax1 = 16 * height1; + float vMax0 = 16 * height0; //TOP - rawOut.add(new RawQuad(new Vector3f(0, maxHeight, 0), new Vector3f(0, components.height, 1), - new Vector3f(1, components.height, 1), new Vector3f(1, maxHeight, 0), + rawOut.add(new RawQuad(new Vector3f(0, height0, 0), new Vector3f(0, height1, 1), + new Vector3f(1, height1, 1), new Vector3f(1, height0, 0), EnumFacing.UP, PANEL_TEXTURE, WHITE, null, UV_FULL, -1)); //BOTTOM rawOut.add(new RawQuad(new Vector3f(0, 0, 0), new Vector3f(1, 0, 0), @@ -107,26 +106,26 @@ public final class PanelUtils { EnumFacing.DOWN, PANEL_TEXTURE, WHITE, null, UV_FULL, -1)); //LEFT rawOut.add(new RawQuad(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1), - new Vector3f(0, components.height, 1), new Vector3f(0, maxHeight, 0), + new Vector3f(0, height1, 1), new Vector3f(0, height0, 0), EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[][]{ {0, 0}, {0, 16}, - {vMaxLower, 16}, {vMaxUpper, 0} + {vMax1, 16}, {vMax0, 0} }, -1)); //RIGHT - rawOut.add(new RawQuad(new Vector3f(1, 0, 0), new Vector3f(1, maxHeight, 0), - new Vector3f(1, components.height, 1), new Vector3f(1, 0, 1), + rawOut.add(new RawQuad(new Vector3f(1, 0, 0), new Vector3f(1, height0, 0), + new Vector3f(1, height1, 1), new Vector3f(1, 0, 1), EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[][]{ - {0, 0}, {vMaxUpper, 0}, - {vMaxLower, 16}, {0, 16} + {0, 0}, {vMax0, 0}, + {vMax1, 16}, {0, 16} }, -1)); //BACK rawOut.add(new RawQuad(new Vector3f(1, 0, 0), new Vector3f(0, 0, 0), - new Vector3f(0, maxHeight, 0), new Vector3f(1, maxHeight, 0), - EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMaxUpper, 16}, -1)); + new Vector3f(0, height0, 0), new Vector3f(1, height0, 0), + EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMax0, 16}, -1)); //FRONT rawOut.add(new RawQuad(new Vector3f(0, 0, 1), new Vector3f(1, 0, 1), - new Vector3f(1, components.height, 1), new Vector3f(0, components.height, 1), - EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMaxLower, 16}, -1)); + new Vector3f(1, height1, 1), new Vector3f(0, height1, 1), + EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMax1, 16}, -1)); for (RawQuad bq : rawOut) { ret.add(bakeQuad(bq, baseTrans, baseNorm)); } @@ -358,7 +357,7 @@ public final class PanelUtils { public static ItemStack getPanelBase() { if (panelBase == null) { - panelBase = IC2Items.getItem("resource", "machine"); + panelBase = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.UNFINISHED.ordinal()); } return panelBase; } @@ -380,4 +379,38 @@ public final class PanelUtils { } return ret; } + + public static float getAngle(ItemStack inv) { + float angle = 0; + if (inv.hasTagCompound()) { + angle = inv.getTagCompound().getFloat("angle"); + } + return angle; + } + + public static float getHeight(ItemStack inv) { + float height = 0; + if (inv.hasTagCompound()) { + height = inv.getTagCompound().getFloat("height"); + } + return height; + } + + public static float getHeightWithComponent(PanelComponent pc, float angle, float height) { + AxisAlignedBB aabb = pc.getBlockRelativeAABB(); + double y = angle > 0 ? aabb.minZ : aabb.maxZ; + float hComp = (float) (pc.getHeight() * Math.cos(angle)); + float localPanelHeight = getLocalHeight(y, angle, height); + return hComp + localPanelHeight; + } + + public static float getLocalHeight(double y, float angle, float height) { + double centerOffset = .5 * (1 / Math.cos(angle) - 1); + y += centerOffset; + return getLocalHeightFromZ(Math.cos(angle) * y, height, angle); + } + + public static float getLocalHeightFromZ(double z, float height, float angle) { + return (float) (height + (.5 - z) * Math.tan(angle)); + } } \ No newline at end of file diff --git a/src/main/java/malte0811/industrialWires/controlpanel/PropertyComponents.java b/src/main/java/malte0811/industrialWires/controlpanel/PropertyComponents.java index 5818c69..f8d2db3 100644 --- a/src/main/java/malte0811/industrialWires/controlpanel/PropertyComponents.java +++ b/src/main/java/malte0811/industrialWires/controlpanel/PropertyComponents.java @@ -22,7 +22,6 @@ import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraftforge.common.property.IUnlistedProperty; import net.minecraftforge.fml.relauncher.Side; @@ -81,9 +80,8 @@ public class PropertyComponents implements IUnlistedProperty 0 ? aabb.minY : aabb.maxY; - float hComp = (float) (pc.getHeight() * Math.cos(angle)); - float localPanelHeight = (float) (height + (1 - (y + centerOffset)) * Math.sin(angle)); - if (hComp + localPanelHeight > max) { - max = hComp + localPanelHeight; + float h = PanelUtils.getHeightWithComponent(pc, angle, height); + if (h > max) { + max = h; } } return max; @@ -162,7 +154,7 @@ public class PropertyComponents implements IUnlistedProperty