Compare commits

...

20 commits

Author SHA1 Message Date
malte0811 405172da7a Build 1.4-18 2017-08-14 18:37:05 +02:00
malte0811 78e468dec8 Don't interact with other TE's in onChunkUnload, closes #12
(back-ported from 1.11)
2017-08-13 22:19:11 +02:00
malte0811 2b8263308f Build 1.4-16 2017-08-04 19:11:22 +02:00
malte0811 20cd180757 Added documentation on the key ring and fixed some bugs with it
Backported other fixes from 1.12
2017-08-04 19:01:24 +02:00
malte0811 78bc37771a Fixed labels breaking the model cache and on dedicated servers, closes #10
(back-port from 1.11)
2017-08-04 18:51:26 +02:00
malte0811 6ca8ca5a0a One more fix for connecting panels using connectors after the panel and the controller have been placed
(back-port from 1.12 via 1.11)
2017-08-04 18:47:46 +02:00
malte0811 6c66ce648a Fixed panels not updating when a connection via panel connectors is broken or placed
(back-port from 1.11)
2017-08-04 18:47:20 +02:00
malte0811 7a5edfa825 Fixed a CME when chunk rendering is multithreaded, see #10
(back-port from 1.11)
2017-08-04 18:41:47 +02:00
malte0811 b1a1b4e62a Allowed multiple components on the same panel network to modify the same RS signal
Cleaned up RS output code for panel components
(Back-port from 1.11)
2017-08-04 18:37:03 +02:00
malte0811 56f9852acc Cleaned up a merge conflict in en_US.lang
Wasn't there some sort of joke about programming languages where merge conflicts are still valid code?
2017-06-16 09:47:19 +02:00
malte0811 42c1021c88 Build 1.4-10
Removed a copyright header that Intellij put in build.gradle
2017-05-26 17:33:09 +02:00
malte0811 6c6a72ae03 Minor fixes to the previous commits 2017-05-26 17:02:07 +02:00
malte0811 0dd80c3e56 Added a key ring, holds up to 10 keys by default
texture might change, docs+recipe still to do
2017-05-26 16:34:38 +02:00
malte0811 9ba2dcb0b6 Added textures for the key+lock switch
Renaming a key to an empty name returns it to its unnamed state
2017-05-26 13:37:30 +02:00
malte0811 65ba8acbec Finished up the lock switch, just missing textures now
Added a recipe to copy settings from one panel component to another
Some internal changes
2017-05-26 13:33:24 +02:00
malte0811 b11ca376a3 Fixes for the previous commits 2017-05-26 13:26:15 +02:00
malte0811 55e03ab8a4 Started adding locks for panels
# Conflicts:
#	src/main/java/malte0811/industrialWires/CommonProxy.java
#	src/main/java/malte0811/industrialWires/IndustrialWires.java
#	src/main/java/malte0811/industrialWires/client/ClientProxy.java
#	src/main/java/malte0811/industrialWires/containers/ContainerPanelComponent.java
#	src/main/java/malte0811/industrialWires/items/ItemIC2Coil.java
#	src/main/java/malte0811/industrialWires/items/ItemPanelComponent.java
#	src/main/java/malte0811/industrialWires/network/MessageComponentSync.java
2017-05-26 13:25:16 +02:00
malte0811 fe7c44f298 Added some IC2 items to the Engineer's toolbox 2017-05-26 13:14:35 +02:00
malte0811 0c52514b15 Glowing components like the indicator light actuall glow in the dark now
Some bugfixes
Complete code reformatting

(Cherry-picked)

# Conflicts:
#	src/main/java/malte0811/industrialWires/IndustrialWires.java
#	src/main/java/malte0811/industrialWires/blocks/BlockIWBase.java
#	src/main/java/malte0811/industrialWires/blocks/EnergyAdapter.java
#	src/main/java/malte0811/industrialWires/blocks/ItemBlockIW.java
#	src/main/java/malte0811/industrialWires/blocks/TileEntityJacobsLadder.java
#	src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockPanel.java
#	src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanel.java
#	src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanelCreator.java
#	src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityRSPanelConn.java
#	src/main/java/malte0811/industrialWires/blocks/converter/BlockMechanicalConverter.java
#	src/main/java/malte0811/industrialWires/blocks/converter/TileEntityIEMotor.java
#	src/main/java/malte0811/industrialWires/blocks/converter/TileEntityMechICtoIE.java
#	src/main/java/malte0811/industrialWires/blocks/converter/TileEntityMechIEtoIC.java
#	src/main/java/malte0811/industrialWires/blocks/wire/BlockIC2Connector.java
#	src/main/java/malte0811/industrialWires/blocks/wire/TileEntityIC2ConnectorTin.java
#	src/main/java/malte0811/industrialWires/client/ClientEventHandler.java
#	src/main/java/malte0811/industrialWires/client/gui/GuiPanelComponent.java
#	src/main/java/malte0811/industrialWires/client/gui/GuiPanelCreator.java
#	src/main/java/malte0811/industrialWires/client/gui/elements/GuiIntChooser.java
#	src/main/java/malte0811/industrialWires/containers/ContainerPanelCreator.java
#	src/main/java/malte0811/industrialWires/containers/ContainerRSPanelConn.java
#	src/main/java/malte0811/industrialWires/controlpanel/CoveredToggleSwitch.java
#	src/main/java/malte0811/industrialWires/controlpanel/LightedButton.java
#	src/main/java/malte0811/industrialWires/controlpanel/PanelComponent.java
#	src/main/java/malte0811/industrialWires/controlpanel/PanelUtils.java
#	src/main/java/malte0811/industrialWires/controlpanel/Slider.java
#	src/main/java/malte0811/industrialWires/crafting/RecipeCoilLength.java
#	src/main/java/malte0811/industrialWires/items/ItemIC2Coil.java
#	src/main/java/malte0811/industrialWires/items/ItemPanelComponent.java
#	src/main/java/malte0811/industrialWires/network/MessageGUIInteract.java
#	src/main/java/malte0811/industrialWires/network/MessagePanelInteract.java
#	src/main/java/malte0811/industrialWires/util/MiscUtils.java
2017-05-26 13:11:15 +02:00
malte0811 0f0232469e Fixed energy loss when not transmitting any energy, closes #7 2017-05-26 12:31:19 +02:00
91 changed files with 3029 additions and 1033 deletions

View file

@ -1,23 +1,5 @@
def mainVersion = "1.4"
def buildNumber = "9"
/*
* 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 <http://www.gnu.org/licenses/>.
*/
def buildNumber = "18"
// For those who want the bleeding edge
buildscript {
@ -48,7 +30,7 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8
minecraft {
version = "12.18.3.2234"
version = "12.18.3.2281"
runDir = "run"
replace '${version}', project.version

View file

@ -1,6 +1,21 @@
#####Version 1.4-17
- Fixed a crash with SpongeForge, chunk loading issues without
- Fixed some components resetting on chunk unload
#####Version 1.4-16
- Backported a lot of fixes from 1.11 and 1.12
#####Version 1.4-10
- added lock switches for control panels (backport from 1.11)
- Can only be turned on by someone with the correct key to prevent unauthorized access
- up to 10 keys can be added to a keyring to reduce inventory spam
- IC2 items can be added to the appropriate sections of the engineers toolbox (backport from 1.11)
- Components (lighted button, indicator light, etc.) on panels now actually light up (backport from 1.11)
- Fixed power loss when no energy is being transmitted
#####Version 1.4-9
- added Control Panels
- They can be used to control and monitor a lot of redstone signals from a few blocks
#####Version 1.3-8
- the converters and the motor don't have missing textures any more when using Chisel
#####Version 1.3-7

View file

@ -23,6 +23,7 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.containers.ContainerPanelComponent;
import malte0811.industrialWires.containers.ContainerPanelCreator;
import malte0811.industrialWires.containers.ContainerRSPanelConn;
import malte0811.industrialWires.containers.ContainerRenameKey;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
@ -60,8 +61,12 @@ public class CommonProxy implements IGuiHandler {
} else if (ID == 1) {//ITEM GUI
EnumHand h = z == 1 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
ItemStack held = player.getHeldItem(h);
if (held != null && held.getItem() == IndustrialWires.panelComponent) {
if (held!=null) {
if (held.getItem() == IndustrialWires.panelComponent) {
return new ContainerPanelComponent(h);
} else if (held.getItem() == IndustrialWires.key) {
return new ContainerRenameKey(h);
}
}
}
return null;

View file

@ -0,0 +1,25 @@
package malte0811.industrialWires;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.tool.ToolboxHandler;
import ic2.api.item.IBoxable;
import ic2.api.item.IC2Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ExtraIC2Compat {
public static void addToolConmpat() {
Item tinnedFood = IC2Items.getItem("filled_tin_can").getItem();
ItemStack emptyMug = IC2Items.getItem("mug", "empty");
ToolboxHandler.addFoodType((s)->s.getItem()==tinnedFood);
ToolboxHandler.addFoodType((s)->
s.getItem()==emptyMug.getItem()&&!ItemStack.areItemStacksEqual(emptyMug, ApiUtils.copyStackWithAmount(s, 1))
);
Item cable = IC2Items.getItem("cable", "type:copper,insulation:0").getItem();
ToolboxHandler.addWiringType((s, w)->s.getItem()==cable);
ToolboxHandler.addToolType((s)-> {
Item a = s.getItem();
return a instanceof IBoxable && ((IBoxable) a).canBeStoredInToolbox(s);
});
}
}

View file

@ -30,7 +30,10 @@ public class IWConfig {
@Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"})
public static boolean enableConversion = true;
public static MechConversion mc = new MechConversion();
public static MechConversion mech = new MechConversion();
@Comment({"The highest number of keys that can be put on one key ring"})
public static int maxKeysOnRing = 10;
public static class MechConversion {
@Comment({"The amount of EU that would be produced by an ideal converter from 1 IF (default: 0.25)"})
public static double euPerIf = .25;
@ -52,10 +55,12 @@ public class IWConfig {
@Comment({"The efficiency of the conversion from IC2 kinetic energy to IE rotational energy"})
public static double kinToRotEfficiency = .8;
}
public static HVStuff hv = new HVStuff();
public static class HVStuff {
@Comment({"The amount of Eu a Jacobs Ladder uses per tick, sorted by size of the ladder"})
public static double[] jacobsUsageEU = {10, 20, 50};
@Comment({"The amount of EU a Jacobs Ladder uses per tick, sorted by size of the ladder"})
public static double[] jacobsUsageEU = {20, 50, 100};
@Comment({"The damage dealt by a small Jacobs Ladder. Normal Ladders deal twice this damage, huge ones 3 times as much"})
public static float jacobsBaseDmg = 5;
}

View file

@ -17,33 +17,26 @@
*/
package malte0811.industrialWires;
import blusunrize.immersiveengineering.api.tool.AssemblerHandler;
import blusunrize.immersiveengineering.api.tool.AssemblerHandler.IRecipeAdapter;
import blusunrize.immersiveengineering.api.tool.AssemblerHandler.RecipeQuery;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Connector;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDecoration;
import ic2.api.item.IC2Items;
import malte0811.industrialWires.blocks.BlockJacobsLadder;
import malte0811.industrialWires.blocks.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.controlpanel.*;
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.converter.BlockMechanicalConverter;
import malte0811.industrialWires.blocks.converter.TileEntityIEMotor;
import malte0811.industrialWires.blocks.converter.TileEntityMechICtoIE;
import malte0811.industrialWires.blocks.converter.TileEntityMechIEtoIC;
import malte0811.industrialWires.blocks.wire.*;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.crafting.RecipeCoilLength;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.network.MessageComponentSync;
import malte0811.industrialWires.network.MessageGUIInteract;
import malte0811.industrialWires.network.MessageItemSync;
import malte0811.industrialWires.network.MessagePanelInteract;
import malte0811.industrialWires.network.MessageTileSyncIW;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Mod;
@ -56,13 +49,6 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.oredict.RecipeSorter.Category;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import java.util.ArrayList;
import java.util.List;
@Mod(modid = IndustrialWires.MODID, version = IndustrialWires.VERSION, dependencies="required-after:immersiveengineering@[0.10-58,);required-after:IC2")
public class IndustrialWires {
@ -74,6 +60,7 @@ public class IndustrialWires {
public static BlockPanel panel;
public static ItemIC2Coil coil;
public static ItemPanelComponent panelComponent;
public static ItemKey key;
public static final SimpleNetworkWrapper packetHandler = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
@Mod.Instance(MODID)
public static IndustrialWires instance = new IndustrialWires();
@ -83,6 +70,7 @@ public class IndustrialWires {
public Item getTabIconItem() {
return null;
}
@Override
public ItemStack getIconItemStack() {
return new ItemStack(coil, 1, 2);
}
@ -97,10 +85,12 @@ public class IndustrialWires {
if (IWConfig.enableConversion)
mechConv = new BlockMechanicalConverter();
jacobsLadder = new BlockJacobsLadder();
panel = new BlockPanel();
coil = new ItemIC2Coil();
panelComponent = new ItemPanelComponent();
panel = new BlockPanel();
//TODO change to MODID+ when changing to a new MC version
key = new ItemKey();
GameRegistry.registerTileEntity(TileEntityIC2ConnectorTin.class, "ic2ConnectorTin");
GameRegistry.registerTileEntity(TileEntityIC2ConnectorCopper.class, "ic2ConnectorCopper");
GameRegistry.registerTileEntity(TileEntityIC2ConnectorGold.class, "ic2ConnectorGold");
@ -123,113 +113,20 @@ public class IndustrialWires {
@EventHandler
public void init(FMLInitializationEvent e) {
ItemStack glassCable = IC2Items.getItem("cable", "type:glass,insulation:0");
//CONNECTORS
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 0), " t ", "rtr", "rtr", 't', "ingotTin", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 2), " c ", "rcr", "rcr", 'c', "ingotCopper", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 4), " g ", "rgr", "rgr", 'g', "ingotGold", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 6), " i ", "rir", "rir", 'i', "ingotIron", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 8), " c ", "rcr", "rcr",'c', glassCable, 'r', "itemRubber"));
//RELAYS
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 1), " t ", "rtr", 't', "ingotTin", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 3), " c ", "rcr", 'c', "ingotCopper", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 5), " g ", "rgr", 'g', "ingotGold", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 7), " i ", "gig", "gig", 'i', "ingotIron", 'g', new ItemStack(IEContent.blockStoneDecoration, 1, BlockTypes_StoneDecoration.INSULATING_GLASS.getMeta())));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 2, 9), " c ", "grg", "grg", 'r', "itemRubber", 'c', glassCable, 'g', new ItemStack(IEContent.blockStoneDecoration, 1, BlockTypes_StoneDecoration.INSULATING_GLASS.getMeta())));
//WIRES
RecipeSorter.register("industrialwires:coilLength", RecipeCoilLength.class, Category.SHAPELESS, "after:forge:shapelessore");
for (int i = 0;i<IC2Wiretype.IC2_TYPES.length;i++) {
GameRegistry.addRecipe(new RecipeCoilLength(i));
}
AssemblerHandler.registerRecipeAdapter(RecipeCoilLength.class, new CoilLengthAdapter());
// MECH CONVERTERS
if (mechConv!=null) {
ItemStack shaftIron = IC2Items.getItem("crafting", "iron_shaft");
ItemStack shaftSteel = IC2Items.getItem("crafting", "steel_shaft");
ItemStack ironMechComponent = new ItemStack(IEContent.itemMaterial, 1, 8);
ItemStack steelMechComponent = new ItemStack(IEContent.itemMaterial, 1, 9);
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 0), " s ", "ici", "mum", 's', "stickIron",
'i', "ingotIron", 'c', new ItemStack(IEContent.blockMetalDecoration0, 1, BlockTypes_MetalDecoration0.COIL_LV.getMeta()),
'u', "ingotCopper", 'm', ironMechComponent));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 2), "iIi", "sbS", "mrm", 's', "blockSheetmetalIron",
'i', "plateIron", 'I', shaftIron,
'b', "ingotBronze", 'm', steelMechComponent,
'S', "blockSheetmetalSteel", 'r', "stickSteel"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 1), "mrm", "sbS", "iIi", 's', "blockSheetmetalIron",
'i', "plateSteel", 'I', shaftSteel,
'b', "ingotBronze", 'm', ironMechComponent,
'S', "blockSheetmetalSteel", 'r', "stickIron"));
}
// JACOB'S LADDERS
ItemStack mvTransformer = IC2Items.getItem("te", "mv_transformer");
ItemStack copperCable = IC2Items.getItem("cable", "type:copper,insulation:0");
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 0), "c c", " h ", "sts", 'c', copperCable, 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', mvTransformer));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 1), "c c", "h h", "sts", 'c', "ingotCopper", 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.TRANSFORMER.ordinal())));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 2), "c c", "hhh", "sts", 'c', "blockCopper", 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.TRANSFORMER_HV.ordinal())));
// CONTROL PANELS
ItemStack drillHeadIron = new ItemStack(IEContent.itemDrillhead, 1, 1);
ItemStack motor = IC2Items.getItem("crafting", "electric_motor");
ItemStack advAlloy = IC2Items.getItem("crafting", "alloy");
ItemStack coil = IC2Items.getItem("crafting", "coil");
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 1, BlockTypes_Panel.CREATOR.ordinal()),
"rmr", "rdr", "rar", 'r', "stickSteel", 'm', motor, 'd', drillHeadIron, 'a', advAlloy));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 8, BlockTypes_Panel.DUMMY.ordinal()),
" r ", "rmr", " r ", 'r', "dustRedstone", 'm', PanelUtils.getPanelBase()));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 1, BlockTypes_Panel.RS_WIRE.ordinal()),
"c", "d", 'd', new ItemStack(panel, 1, BlockTypes_Panel.DUMMY.ordinal()), 'c',
new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.CONNECTOR_REDSTONE.ordinal())));
// PANEL COMPONENTS
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 0),
"dustGlowstone", Blocks.STONE_BUTTON, "wireCopper"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 4, 1),
"paper", "plateIron"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 2),
"dustGlowstone", "dustRedstone", "wireCopper"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 3),
Blocks.STONE_BUTTON, new ItemStack(IEContent.itemWireCoil, 1, 2), "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panelComponent, 1, 4),
"r", "g", "c", 'r', "itemRubber", 'g', "ingotHOPGraphite", 'c', coil));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 5),
"stickIron", Blocks.LEVER, "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panelComponent, 1, 6),
"aaa", "asa", 'a', "plateAluminum", 's', new ItemStack(panelComponent, 2, 5)));
Recipes.addRecipes();
ExtraIC2Compat.addToolConmpat();
packetHandler.registerMessage(MessageTileSyncIW.HandlerClient.class, MessageTileSyncIW.class, 0, Side.CLIENT);
packetHandler.registerMessage(MessagePanelInteract.HandlerServer.class, MessagePanelInteract.class, 1, Side.SERVER);
packetHandler.registerMessage(MessageGUIInteract.HandlerServer.class, MessageGUIInteract.class, 2, Side.SERVER);
packetHandler.registerMessage(MessageComponentSync.HandlerServer.class, MessageComponentSync.class, 3, Side.SERVER);
packetHandler.registerMessage(MessageItemSync.HandlerServer.class, MessageItemSync.class, 3, Side.SERVER);
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
}
@EventHandler
public void postInit(FMLPostInitializationEvent e) {
proxy.postInit();
}
private class CoilLengthAdapter implements IRecipeAdapter<RecipeCoilLength> {
@Override
public RecipeQuery[] getQueriedInputs(RecipeCoilLength recipe, ItemStack[] in) {
List<RecipeQuery> ret = new ArrayList<>();
for (int i = 0;i<in.length-1;i++) {
boolean added = false;
for (int j = 0;j<ret.size();j++) {
if (ItemStack.areItemStacksEqual((ItemStack)ret.get(j).query, in[i])) {
ret.get(j).querySize++;
added = true;
break;
}
}
if (!added) {
ret.add(new RecipeQuery(in[i], 1));
}
}
return ret.toArray(new RecipeQuery[ret.size()]);
}
@Override
public RecipeQuery[] getQueriedInputs(RecipeCoilLength arg0) {
return new RecipeQuery[0];
}
}
}

View file

@ -0,0 +1,179 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires;
import blusunrize.immersiveengineering.api.tool.AssemblerHandler;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Connector;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDecoration;
import ic2.api.item.IC2Items;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.crafting.*;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialWires.IndustrialWires.*;
public class Recipes {
public static void addRecipes() {
addCustomRecipes();
addConnectors();
if (mechConv != null) {
addMechConverters();
}
addJacobs();
registerPanels();
}
private static void addConnectors() {
ItemStack glassCable = IC2Items.getItem("cable", "type:glass,insulation:0");
//CONNECTORS
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 0), " t ", "rtr", "rtr", 't', "ingotTin", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 2), " c ", "rcr", "rcr", 'c', "ingotCopper", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 4), " g ", "rgr", "rgr", 'g', "ingotGold", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 6), " i ", "rir", "rir", 'i', "ingotIron", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 8), " c ", "rcr", "rcr", 'c', glassCable, 'r', "itemRubber"));
//RELAYS
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 1), " t ", "rtr", 't', "ingotTin", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 3), " c ", "rcr", 'c', "ingotCopper", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 5), " g ", "rgr", 'g', "ingotGold", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 7), " i ", "gig", "gig", 'i', "ingotIron", 'g', new ItemStack(IEContent.blockStoneDecoration, 1, BlockTypes_StoneDecoration.INSULATING_GLASS.getMeta())));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 2, 9), " c ", "grg", "grg", 'r', "itemRubber", 'c', glassCable, 'g', new ItemStack(IEContent.blockStoneDecoration, 1, BlockTypes_StoneDecoration.INSULATING_GLASS.getMeta())));
}
private static void addMechConverters() {
ItemStack shaftIron = IC2Items.getItem("crafting", "iron_shaft");
ItemStack shaftSteel = IC2Items.getItem("crafting", "steel_shaft");
ItemStack ironMechComponent = new ItemStack(IEContent.itemMaterial, 1, 8);
ItemStack steelMechComponent = new ItemStack(IEContent.itemMaterial, 1, 9);
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 0), " s ", "ici", "mum", 's', "stickIron",
'i', "ingotIron", 'c', new ItemStack(IEContent.blockMetalDecoration0, 1, BlockTypes_MetalDecoration0.COIL_LV.getMeta()),
'u', "ingotCopper", 'm', ironMechComponent));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 2), "iIi", "sbS", "mrm", 's', "blockSheetmetalIron",
'i', "plateIron", 'I', shaftIron,
'b', "ingotBronze", 'm', steelMechComponent,
'S', "blockSheetmetalSteel", 'r', "stickSteel"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 1), "mrm", "sbS", "iIi", 's', "blockSheetmetalIron",
'i', "plateSteel", 'I', shaftSteel,
'b', "ingotBronze", 'm', ironMechComponent,
'S', "blockSheetmetalSteel", 'r', "stickIron"));
}
private static void addCustomRecipes() {
RecipeSorter.register("industrialwires:key_ring", RecipeKeyRing.class, RecipeSorter.Category.SHAPELESS, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:key_lock", RecipeKeyLock.class, RecipeSorter.Category.SHAPELESS, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:cmp_copy", RecipeComponentCopy.class, RecipeSorter.Category.SHAPED, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:coilLength", RecipeCoilLength.class, RecipeSorter.Category.SHAPELESS, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:init_pc", RecipeInitPC.class, RecipeSorter.Category.SHAPED, "after:forge:shapedore");
GameRegistry.addRecipe(new RecipeKeyLock());
GameRegistry.addRecipe(new RecipeKeyRing(true));
GameRegistry.addRecipe(new RecipeKeyRing(false));
GameRegistry.addRecipe(new RecipeComponentCopy());
for (int i = 0; i < IC2Wiretype.IC2_TYPES.length; i++) {
GameRegistry.addRecipe(new RecipeCoilLength(i));
}
AssemblerHandler.registerRecipeAdapter(RecipeCoilLength.class, new AllRecipeAdapter<>());
AssemblerHandler.registerRecipeAdapter(RecipeComponentCopy.class, new AllRecipeAdapter<>());
AssemblerHandler.registerRecipeAdapter(RecipeKeyLock.class, new AllRecipeAdapter<>());
AssemblerHandler.registerRecipeAdapter(RecipeKeyRing.class, new AllRecipeAdapter<>());
}
private static void registerPanels() {
// CONTROL PANELS
ItemStack drillHeadIron = new ItemStack(IEContent.itemDrillhead, 1, 1);
ItemStack motor = IC2Items.getItem("crafting", "electric_motor");
ItemStack advAlloy = IC2Items.getItem("crafting", "alloy");
ItemStack coil = IC2Items.getItem("crafting", "coil");
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 1, BlockTypes_Panel.CREATOR.ordinal()),
"rmr", "rdr", "rar", 'r', "stickSteel", 'm', motor, 'd', drillHeadIron, 'a', advAlloy));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 8, BlockTypes_Panel.DUMMY.ordinal()),
" r ", "rmr", " r ", 'r', "dustRedstone", 'm', PanelUtils.getPanelBase()));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 1, BlockTypes_Panel.RS_WIRE.ordinal()),
"c", "d", 'd', new ItemStack(panel, 1, BlockTypes_Panel.DUMMY.ordinal()), 'c',
new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.CONNECTOR_REDSTONE.ordinal())));
// PANEL COMPONENTS
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 0),
"dustGlowstone", Blocks.STONE_BUTTON, "wireCopper"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 4, 1),
"paper", "plateIron"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 2),
"dustGlowstone", "dustRedstone", "wireCopper"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 3),
Blocks.STONE_BUTTON, new ItemStack(IEContent.itemWireCoil, 1, 2), "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panelComponent, 1, 4),
"r", "g", "c", 'r', "itemRubber", 'g', "ingotHOPGraphite", 'c', coil));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 5),
"stickIron", Blocks.LEVER, "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panelComponent, 1, 6),
"aaa", "asa", 'a', "plateAluminum", 's', new ItemStack(panelComponent, 2, 5)));
GameRegistry.addRecipe(new RecipeInitPC(new ItemStack(panelComponent, 1, 7),
"rdr", " w ", 'r', "stickSteel", 'd', Items.IRON_DOOR, 'w', "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(key, 1, 0),
"rrp", 'r', "stickSteel", 'p', "plateSteel"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 8),
"wireCopper", new ItemStack(IEContent.itemTool, 1, 2)));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(key, 1, 2), " r ", "r r", " r ", 'r', "stickSteel"));
}
private static void addJacobs() {
ItemStack mvTransformer = IC2Items.getItem("te", "mv_transformer");
ItemStack copperCable = IC2Items.getItem("cable", "type:copper,insulation:0");
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 0), "c c", " h ", "sts", 'c', copperCable, 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', mvTransformer));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 1), "c c", "h h", "sts", 'c', "ingotCopper", 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.TRANSFORMER.ordinal())));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 2), "c c", "hhh", "sts", 'c', "blockCopper", 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.TRANSFORMER_HV.ordinal())));
}
private static class AllRecipeAdapter<T extends IRecipe> implements AssemblerHandler.IRecipeAdapter<T> {
@Override
public AssemblerHandler.RecipeQuery[] getQueriedInputs(T recipe,ItemStack[] in) {
List<AssemblerHandler.RecipeQuery> ret = new ArrayList<>();
for (int i = 0; i < in.length - 1; i++) {
boolean added = false;
for (AssemblerHandler.RecipeQuery aRet : ret) {
if (ItemStack.areItemStacksEqual((ItemStack) aRet.query, in[i])) {
aRet.querySize++;
added = true;
break;
}
}
if (!added) {
ret.add(new AssemblerHandler.RecipeQuery(in[i], 1));
}
}
return ret.toArray(new AssemblerHandler.RecipeQuery[ret.size()]);
}
@Override
public AssemblerHandler.RecipeQuery[] getQueriedInputs(T arg0) {
return new AssemblerHandler.RecipeQuery[0];
}
}
}

View file

@ -52,6 +52,7 @@ import java.util.Set;
public abstract class BlockIWBase extends Block {
private IProperty[] properties;
public BlockIWBase(Material mat, String name) {
super(mat);
setHardness(3.0F);
@ -216,5 +217,6 @@ public abstract class BlockIWBase extends Block {
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
protected abstract IProperty[] getProperties();
}

View file

@ -25,16 +25,15 @@ import net.minecraftforge.energy.IEnergyStorage;
public class EnergyAdapter implements IEnergyStorage {
/**
* 3 different copies of the same thing, the TE this adapter is mirroring.
* 2 different copies of the same thing, the TE this adapter is mirroring.
* rec and prov are null if the TE does not implement them
*/
IFluxConnection tile;
IFluxReceiver rec;
IFluxProvider prov;
private IFluxReceiver rec;
private IFluxProvider prov;
private EnumFacing dir;
EnumFacing dir;
public EnergyAdapter(IFluxConnection te, EnumFacing f) {
tile = te;
dir = f;
if (te instanceof IFluxReceiver) {
rec = (IFluxReceiver) te;

View file

@ -22,6 +22,8 @@ import net.minecraft.block.state.IBlockState;
public interface IHasDummyBlocksIW {
void placeDummies(IBlockState state);
void breakDummies();
boolean isDummy();
}

View file

@ -28,8 +28,11 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class ItemBlockIW extends ItemBlock {
private final Object[] values;
public ItemBlockIW(Block b) {
super(b);
if (b instanceof IMetaEnum) {
@ -48,13 +51,14 @@ public class ItemBlockIW extends ItemBlock {
return block.getUnlocalizedName();
}
}
@Override
public int getMetadata(int damage) {
return damage;
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) {
public boolean placeBlockAt(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull IBlockState newState) {
if (block instanceof IPlacementCheck&&!((IPlacementCheck) block).canPlaceBlockAt(world, pos, stack)) {
return false;
}

View file

@ -32,6 +32,7 @@ public abstract class TileEntityIWBase extends TileEntity {
writeNBT(nbt, true);
return nbt;
}
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
return new SPacketUpdateTileEntity(pos, getBlockMetadata(), getUpdateTag());
@ -48,11 +49,14 @@ public abstract class TileEntityIWBase extends TileEntity {
super.readFromNBT(compound);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
super.onDataPacket(net, pkt);
readNBT(pkt.getNbtCompound(), true);
}
public abstract void writeNBT(NBTTagCompound out, boolean updatePacket);
public abstract void readNBT(NBTTagCompound in, boolean updatePacket);
}

View file

@ -22,6 +22,8 @@ import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
@ -43,10 +45,12 @@ import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import javax.annotation.Nonnull;
import java.util.List;
public class BlockPanel extends BlockIWBase implements IMetaEnum {
public static final PropertyEnum<BlockTypes_Panel> type = PropertyEnum.create("type", BlockTypes_Panel.class);
public BlockPanel() {
super(Material.IRON, "control_panel");
lightOpacity = 0;
@ -65,7 +69,7 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
switch (state.getValue(type)) {
case TOP:
return new TileEntityPanel();
@ -143,18 +147,22 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
list.add(new ItemStack(itemIn, 1, 2));
list.add(new ItemStack(itemIn, 1, 3));
}
@Override
public boolean isFullBlock(IBlockState state) {
return false;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
@ -186,7 +194,8 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
@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) {
@ -195,4 +204,43 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
}
return super.getPickBlock(state, target, world, pos, player);
}
@Override
public void harvestBlock(@Nonnull World worldIn, EntityPlayer player, @Nonnull BlockPos pos, @Nonnull IBlockState state, TileEntity te, ItemStack stack) {
super.harvestBlock(worldIn, player, pos, state, te, stack);
if (te instanceof TileEntityPanel) {
for (PanelComponent pc:((TileEntityPanel) te).getComponents()) {
pc.dropItems((TileEntityPanel)te);
}
}
}
@Override
public void breakBlock(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
super.breakBlock(worldIn, pos, state);
//break connections
List<BlockPos> panels = PanelUtils.discoverPanelParts(worldIn, pos, 11 * 11 * 11);
for (BlockPos p : panels) {
if (!p.equals(pos)) {
TileEntity panelPart = worldIn.getTileEntity(p);
if (panelPart instanceof TileEntityPanel) {
((TileEntityPanel) panelPart).removeAllRSCons();
}
}
}
}
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
super.onBlockAdded(worldIn, pos, state);
List<BlockPos> panels = PanelUtils.discoverPanelParts(worldIn, pos, 11 * 11 * 11);
for (BlockPos p : panels) {
if (!p.equals(pos)) {
TileEntity panelPart = worldIn.getTileEntity(p);
if (panelPart instanceof TileEntityPanel) {
((TileEntityPanel) panelPart).firstTick = true;
}
}
}
}
}

View file

@ -32,4 +32,8 @@ public enum BlockTypes_Panel implements IStringSerializable {
public String getName() {
return toString().toLowerCase(Locale.ENGLISH);
}
public boolean isPanelConnector() {
return this != CREATOR;
}
}

View file

@ -27,6 +27,7 @@ import java.util.ArrayList;
public class PropertyComponents implements IUnlistedProperty<PropertyComponents.PanelRenderProperties> {
public static PropertyComponents INSTANCE = new PropertyComponents();
@Override
public String getName() {
return "components";
@ -51,12 +52,15 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
public EnumFacing facing = EnumFacing.NORTH;
public float height = .5F;
public EnumFacing top = EnumFacing.UP;
public PanelRenderProperties() {
super();
}
public PanelRenderProperties(int length) {
super(length);
}
@Override
public String toString() {
StringBuilder ret = new StringBuilder("[");
@ -68,9 +72,11 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
}
return ret + "]";
}
public Matrix4 getPanelTopTransform() {
return getPanelBaseTransform().translate(0, height, 0);
}
public Matrix4 getPanelBaseTransform() {
Matrix4 ret = new Matrix4();
ret.translate(.5, .5, .5);

View file

@ -27,7 +27,6 @@ import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.TileEntityIWBase;
import malte0811.industrialWires.controlpanel.*;
import malte0811.industrialWires.network.MessagePanelInteract;
import malte0811.industrialWires.util.MiscUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
@ -55,9 +54,10 @@ import java.util.Set;
public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTile, IBlockBoundsIW, IPlayerInteraction, ITickable, IEBlockInterfaces.ITileDrop {
private PropertyComponents.PanelRenderProperties components = new PropertyComponents.PanelRenderProperties();
private boolean firstTick = true;
public boolean firstTick = true;
// non-rendered properties
private Set<TileEntityRSPanelConn> rsPorts = new HashSet<>();
private boolean renderUpdate;
{
for (int i = 2; i < 14; i++) {
@ -92,7 +92,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
}
if (!worldObj.isRemote) {
if (firstTick) {
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
for (BlockPos bp : parts) {
TileEntity te = worldObj.getTileEntity(bp);
if (te instanceof TileEntityRSPanelConn&&!rsPorts.contains(te)) {
@ -101,6 +101,13 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
}
firstTick = false;
}
if (renderUpdate) {
IBlockState state = worldObj.getBlockState(pos);
worldObj.notifyBlockUpdate(pos, state, state, 3);
worldObj.addBlockEvent(pos, state.getBlock(), 255, 0);
markDirty();
renderUpdate = false;
}
}
}
@ -279,9 +286,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
}
public void triggerRenderUpdate() {
IBlockState state = worldObj.getBlockState(pos);
worldObj.notifyBlockUpdate(pos, state, state, 3);
worldObj.addBlockEvent(pos, state.getBlock(), 255, 0);
renderUpdate = true;
}
public void registerRS(TileEntityRSPanelConn te) {
@ -300,9 +305,15 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
for (PanelComponent pc : components) {
pc.invalidate(this);
}
for (TileEntityRSPanelConn rs : rsPorts) {
rs.unregisterPanel(this, true);
removeAllRSCons();
}
public void removeAllRSCons() {
for (TileEntityRSPanelConn rs : rsPorts) {
rs.unregisterPanel(this, true, false);
}
rsPorts.clear();
firstTick = true;
}
@Override
@ -311,8 +322,6 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
for (PanelComponent pc : components) {
pc.invalidate(this);
}
for (TileEntityRSPanelConn rs : rsPorts) {
rs.unregisterPanel(this, true);
}
removeAllRSCons();
}
}

View file

@ -18,10 +18,8 @@
package malte0811.industrialWires.blocks.controlpanel;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.common.util.IELogger;
import blusunrize.immersiveengineering.common.util.Utils;
import blusunrize.immersiveengineering.common.util.inventory.IIEInventory;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.INetGUI;
@ -41,23 +39,23 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInventory, INetGUI, IBlockBoundsIW {
public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI, IBlockBoundsIW {
public List<PanelComponent> components = new ArrayList<>();
public float height = 0.5F;
public ItemStack[] inv = new ItemStack[1];
public ItemStack inv = null;
@Override
public void readNBT(NBTTagCompound nbt, boolean updatePacket) {
NBTTagList l = nbt.getTagList("components", 10);
PanelUtils.readListFromNBT(l, components);
height = nbt.getFloat("height");
inv = Utils.readInventory(nbt.getTagList("inventory", 10), inv.length);
inv = Utils.readInventory(nbt.getTagList("inventory", 10), 1)[0];
}
@Override
public void writeNBT(NBTTagCompound nbt, boolean updatePacket) {
writeToItemNBT(nbt, false);
nbt.setTag("inventory", Utils.writeInventory(inv));
nbt.setTag("inventory", Utils.writeInventory(new ItemStack[]{inv}));
}
public void writeToItemNBT(NBTTagCompound nbt, boolean toItem) {
@ -71,29 +69,6 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
nbt.setFloat("height", height);
}
@Override
public ItemStack[] getInventory() {
return inv;
}
@Override
public boolean isStackValid(int slot, ItemStack stack) {
if (slot == 0) {
return ApiUtils.compareToOreName(stack, "plateIron");
}
return true;
}
@Override
public int getSlotLimit(int slot) {
return slot == 0 ? 1 : 64;
}
@Override
public void doGraphicalUpdates(int slot) {
}
@Override
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
int type = nbt.getInteger("type");
@ -128,12 +103,12 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
}
break;
case CREATE_PANEL:
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv[0])) {
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv) && !components.isEmpty()) {
NBTTagCompound panelNBT = new NBTTagCompound();
writeToItemNBT(panelNBT, true);
ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
panel.setTagCompound(panelNBT);
inv[0] = panel;
inv = panel;
components.clear();
}
break;
@ -152,12 +127,12 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
}
break;
case DISASSEMBLE:
if (components.size() == 0 && inv[0] != null && inv[0].getItem() == PanelUtils.PANEL_ITEM) {
if (components.size() == 0 && inv != null && inv.getItem() == PanelUtils.PANEL_ITEM) {
TileEntityPanel te = new TileEntityPanel();
te.readFromItemNBT(inv[0].getTagCompound());
te.readFromItemNBT(inv.getTagCompound());
components = new ArrayList<>(te.getComponents());
height = te.getComponents().height;
inv[0] = null;
inv = null;
}
break;
}
@ -167,6 +142,7 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
}
private static final AxisAlignedBB aabb = new AxisAlignedBB(0, 0, 0, 1, 14 / 16D, 1);
@Override
public AxisAlignedBB getBoundingBox() {
return aabb;

View file

@ -29,7 +29,8 @@ import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.INetGUI;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.util.MiscUtils;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@ -44,8 +45,8 @@ import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implements IRedstoneConnector, ITickable, INetGUI, IEBlockInterfaces.IDirectionalTile, IBlockBoundsIW {
@ -59,11 +60,13 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
private RedstoneWireNetwork network = new RedstoneWireNetwork().add(this);
private boolean hasConn = false;
private int id;
{
for (int i = 0; i < 16; i++) {
oldInput[i] = -1;
}
}
private boolean loaded = false;
@Override
@ -73,7 +76,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
loaded = true;
// completely reload the network
network.removeFromNetwork(null);
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
for (BlockPos bp : parts) {
TileEntity te = worldObj.getTileEntity(bp);
if (te instanceof TileEntityPanel) {
@ -87,6 +90,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
}
}
}
@Override
public void writeCustomNBT(NBTTagCompound out, boolean updatePacket) {
super.writeCustomNBT(out, updatePacket);
@ -106,19 +110,62 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
aabb = null;
}
private BiConsumer<Integer, Byte> rsOut = (channel, value)->{
if (value!=out[channel]) {
private final Map<PCWrapper, byte[]> outputs = new HashMap<>();
private TriConsumer<Integer, Byte, PanelComponent> rsOut = (channel, value, pc) -> {
PCWrapper wrapper = new PCWrapper(pc);
if (!outputs.containsKey(wrapper)) {
outputs.put(wrapper, new byte[16]);
}
if (outputs.get(wrapper)[channel] != value) {
outputs.get(wrapper)[channel] = value;
byte max = 0;
Iterator<Map.Entry<PCWrapper, byte[]>> it = outputs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<PCWrapper, byte[]> curr = it.next();
if (curr.getKey().pc.get() == null) {
it.remove();
continue;
}
if (curr.getValue()[channel] > max) {
max = curr.getValue()[channel];
}
}
dirty = true;
out[channel] = value;
out[channel] = max;
}
};
private class PCWrapper {
@Nonnull
private final WeakReference<PanelComponent> pc;
public PCWrapper(@Nonnull PanelComponent pc) {
this.pc = new WeakReference<>(pc);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PCWrapper pcWrapper = (PCWrapper) o;
return pcWrapper.pc.get() == pc.get();
}
@Override
public int hashCode() {
return System.identityHashCode(pc.get());
}
}
public void registerPanel(TileEntityPanel panel) {
PropertyComponents.PanelRenderProperties p = panel.getComponents();
for (PanelComponent pc : p) {
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
if (listener != null) {
changeListeners.add(listener);
listener.accept(network.channelValues);
}
pc.registerRSOutput(id, rsOut);
}
@ -126,19 +173,30 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
connectedPanels.add(panel);
}
public void unregisterPanel(TileEntityPanel panel, boolean remove) {
public void unregisterPanel(TileEntityPanel panel, boolean remove, boolean callPanel) {
out = new byte[16];
PropertyComponents.PanelRenderProperties p = panel.getComponents();
for (PanelComponent pc : p) {
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
if (listener != null) {
listener.accept(new byte[16]);
changeListeners.remove(listener);
}
pc.unregisterRSOutput(id, rsOut);
outputs.remove(new PCWrapper(pc));
}
if (callPanel) {
panel.unregisterRS(this);
}
if (remove) {
connectedPanels.remove(panel);
}
for (TileEntityPanel te : connectedPanels) {
for (PanelComponent pc : te.getComponents()) {
pc.registerRSOutput(id, rsOut);
}
}
network.updateValues();
}
@Override
@ -225,7 +283,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
public void onChunkUnload() {
super.onChunkUnload();
for (TileEntityPanel panel : connectedPanels) {
unregisterPanel(panel, false);
unregisterPanel(panel, false, true);
}
}
@ -233,20 +291,20 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
public void invalidate() {
super.invalidate();
for (TileEntityPanel panel : connectedPanels) {
unregisterPanel(panel, false);
unregisterPanel(panel, false, true);
}
}
@Override
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
if (nbt.hasKey("rsId")) {
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
List<TileEntityPanel> tes = new ArrayList<>(parts.size());
for (BlockPos bp:parts) {
TileEntity te = worldObj.getTileEntity(bp);
if (te instanceof TileEntityPanel) {
tes.add((TileEntityPanel) te);
unregisterPanel((TileEntityPanel) te, true);
unregisterPanel((TileEntityPanel) te, true, true);
}
}
id = nbt.getInteger("rsId");
@ -301,6 +359,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
}
private AxisAlignedBB aabb;
@Override
public AxisAlignedBB getBoundingBox() {
if (aabb == null) {

View file

@ -35,16 +35,18 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.List;
public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
private static PropertyEnum<MechanicalBlockType> type = PropertyEnum.create("type", MechanicalBlockType.class);
public BlockMechanicalConverter() {
super(Material.IRON, "mechanical_converter");
}
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, List<ItemStack> list) {
for (int i = 0; i < 3; i++) {
list.add(new ItemStack(itemIn, 1, i));
}
@ -87,6 +89,7 @@ public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
public int getMetaFromState(IBlockState state) {
return state.getValue(type).ordinal();
}
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
float hitZ, int meta, EntityLivingBase placer, ItemStack stack) {
@ -102,6 +105,7 @@ public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
EntityPlayer player) {
return new ItemStack(this, 1, damageDropped(state));
}
@Override
@SuppressWarnings("deprecation")
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {

View file

@ -34,6 +34,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import javax.annotation.Nonnull;
public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IFluxReceiver, IDirectionalTile {
public final double bufferMax = 2 * MechConversion.maxIfToMech * ConversionUtil.rotPerIf();
@ -41,6 +43,7 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
private FluxStorage energy = new FluxStorage(20 * MechConversion.maxIfToMech, 2 * MechConversion.maxIfToMech);
private EnumFacing dir = EnumFacing.DOWN;
private BlockPos receiver;
@Override
public void update() {
if (!worldObj.isRemote) {
@ -65,6 +68,7 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
}
}
}
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
@ -72,6 +76,7 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
receiver = null;
rotBuffer = in.getDouble(BUFFER_TAG);
}
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
out.setByte(DIR_TAG, (byte) dir.getIndex());
@ -86,6 +91,7 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
public boolean canConnectEnergy(EnumFacing from) {
return from == dir.getOpposite() || from == null;
}
@Override
public int receiveEnergy(EnumFacing from, int energyIn, boolean simulate) {
if (canConnectEnergy(from)) {
@ -96,10 +102,12 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
return 0;
}
}
@Override
public int getEnergyStored(EnumFacing from) {
return energy.getEnergyStored();
}
@Override
public int getMaxEnergyStored(EnumFacing from) {
return energy.getMaxEnergyStored();
@ -110,34 +118,41 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
public EnumFacing getFacing() {
return dir;
}
@Override
public void setFacing(EnumFacing facing) {
dir = facing;
receiver = null;
markDirty();
}
@Override
public int getFacingLimitation() {
return 1;
}
@Override
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
return false;
}
@Override
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
return true;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
public boolean hasCapability(@Nonnull Capability<?> capability, @Nonnull EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY && canConnectEnergy(facing)) {
return true;
}
return super.hasCapability(capability, facing);
}
@Nonnull
@Override
@SuppressWarnings("unchecked")
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
public <T> T getCapability(@Nonnull Capability<T> capability, @Nonnull EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY && canConnectEnergy(facing)) {
return (T) new EnergyAdapter(this, facing);
}

View file

@ -37,6 +37,7 @@ public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirection
private final double maxInsert = ConversionUtil.rotPerKin() * MechConversion.maxKinToRot;
BlockPos to;
BlockPos from;
@Override
public void update() {
if (!worldObj.isRemote) {
@ -76,11 +77,13 @@ public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirection
to = null;
from = null;
}
// Directional
@Override
public EnumFacing getFacing() {
return dir;
}
@Override
public void setFacing(EnumFacing facing) {
dir = facing;
@ -88,18 +91,22 @@ public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirection
from = null;
markDirty();
}
@Override
public int getFacingLimitation() {
return 1;
}
@Override
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
return false;
}
@Override
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
return true;
}
@Override
public boolean canRotate(EnumFacing axis) {
return true;

View file

@ -27,6 +27,8 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import javax.annotation.Nonnull;
public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirectionalTile, IRotationAcceptor, IKineticSource {
EnumFacing dir = EnumFacing.DOWN;
double rotBuffer = 0;
@ -44,28 +46,34 @@ public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirection
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
rotBuffer = in.getDouble(BUFFER_TAG);
}
// Directional
@Override
public EnumFacing getFacing() {
return dir;
}
@Override
public void setFacing(EnumFacing facing) {
dir = facing;
markDirty();
}
@Override
public int getFacingLimitation() {
return 1;
}
@Override
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
return false;
}
@Override
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
return true;
}
//IC2 kinetic
@Override
public int maxrequestkineticenergyTick(EnumFacing f) {
@ -91,11 +99,12 @@ public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirection
//IE rotation
@Override
public void inputRotation(double rotation, EnumFacing side) {
public void inputRotation(double rotation, @Nonnull EnumFacing side) {
if (side == dir) {
rotBuffer = Math.min(rotBufMax, rotBuffer + rotation);
}
}
@Override
public boolean canRotate(EnumFacing axis) {
return true;

View file

@ -21,13 +21,16 @@ import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -39,11 +42,13 @@ import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;
public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
private static PropertyEnum<BlockTypes_IC2_Connector> type = PropertyEnum.create("type", BlockTypes_IC2_Connector.class);
public BlockIC2Connector() {
super(Material.IRON, "ic2Connector");
setHardness(3.0F);
@ -64,7 +69,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
}
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, List<ItemStack> list) {
for (int i = 0;i<type.getAllowedValues().size();i++) {
list.add(new ItemStack(itemIn, 1, i));
}
@ -135,22 +140,37 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
}
return null;
}
@Override
public boolean canRenderInLayer(BlockRenderLayer layer) {
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (stack!=null && stack.getMetadata() % 2 == 0) {
int type = stack.getMetadata() / 2;
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.power_tier", type + 1));
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.eu_per_tick", IC2Wiretype.IC2_TYPES[type].getTransferRate() / 8));
}
}
@Override
public boolean canRenderInLayer(IBlockState state, @Nonnull BlockRenderLayer layer) {
return layer == BlockRenderLayer.TRANSLUCENT || layer == BlockRenderLayer.SOLID;
}
@Override
public boolean isFullBlock(IBlockState state) {
return false;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;

View file

@ -30,6 +30,7 @@ public enum BlockTypes_IC2_Connector implements IBlockEnum {
HV_RELAY,
GLASS_CONN,
GLASS_RELAY;
@Override
public String getName() {
return toString().toLowerCase();

View file

@ -26,12 +26,14 @@ public class TileEntityIC2ConnectorCopper extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorCopper() {}
public TileEntityIC2ConnectorCopper() {
}
{
tier = 2;
maxStored = IC2Wiretype.IC2_TYPES[1].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[1];

View file

@ -25,12 +25,14 @@ public class TileEntityIC2ConnectorGlass extends TileEntityIC2ConnectorHV {
super(rel);
}
public TileEntityIC2ConnectorGlass() {}
public TileEntityIC2ConnectorGlass() {
}
{
tier = 5;
maxStored = IC2Wiretype.IC2_TYPES[4].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[4];

View file

@ -30,12 +30,14 @@ public class TileEntityIC2ConnectorGold extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorGold() {}
public TileEntityIC2ConnectorGold() {
}
{
tier = 3;
maxStored = IC2Wiretype.IC2_TYPES[2].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[2];
@ -46,6 +48,7 @@ public class TileEntityIC2ConnectorGold extends TileEntityIC2ConnectorTin {
EnumFacing side = f.getOpposite();
return new Vec3d(.5 + side.getFrontOffsetX() * .125, .5 + side.getFrontOffsetY() * .125, .5 + side.getFrontOffsetZ() * .125);
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();

View file

@ -30,12 +30,14 @@ public class TileEntityIC2ConnectorHV extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorHV() {}
public TileEntityIC2ConnectorHV() {
}
{
tier = 4;
maxStored = IC2Wiretype.IC2_TYPES[3].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[3];
@ -50,6 +52,7 @@ public class TileEntityIC2ConnectorHV extends TileEntityIC2ConnectorTin {
return new Vec3d(.5 + side.getFrontOffsetX() * .3125, .5 + side.getFrontOffsetY() * .3125, .5 + side.getFrontOffsetZ() * .3125);
}
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();

View file

@ -17,16 +17,6 @@
*/
package malte0811.industrialWires.blocks.wire;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import net.minecraft.util.math.AxisAlignedBB;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.TargetingInfo;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
@ -35,7 +25,6 @@ import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Abst
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IBlockBounds;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
@ -44,13 +33,22 @@ import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergySource;
import malte0811.industrialWires.IIC2Connector;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.MinecraftForge;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable implements IEnergySource, IEnergySink, IDirectionalTile, ITickable, IIC2Connector, IBlockBoundsIW {
EnumFacing f = EnumFacing.NORTH;
@ -64,10 +62,14 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
private double maxToMachine = 0;
protected double maxStored = IC2Wiretype.IC2_TYPES[0].getTransferRate() / 8;
int tier = 1;
public TileEntityIC2ConnectorTin(boolean rel) {
relay = rel;
}
public TileEntityIC2ConnectorTin() {}
public TileEntityIC2ConnectorTin() {
}
@Override
public void update() {
if (first) {
@ -78,6 +80,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
if (!worldObj.isRemote&&inBuffer>.1)
transferPower();
}
public void transferPower() {
Set<AbstractConnection> conns = new HashSet<>(ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(pos, worldObj));
Map<AbstractConnection, Pair<IIC2Connector, Double>> maxOutputs = new HashMap<>();
@ -121,6 +124,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
}
}
public double getAverageLossRate(AbstractConnection conn) {
double f = 0;
for (Connection c : conn.subConnections) {
@ -128,6 +132,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
return f;
}
//Input through the net
@Override
public double insertEnergy(double eu, boolean simulate) {
@ -145,6 +150,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
return eu - insert;
}
@Override
public void invalidate() {
if (!worldObj.isRemote&&!first)
@ -152,6 +158,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
first = true;
super.invalidate();
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
@ -165,24 +172,29 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
EnumFacing side = f.getOpposite();
return new Vec3d(.5 + side.getFrontOffsetX() * .0625, .5 + side.getFrontOffsetY() * .0625, .5 + side.getFrontOffsetZ() * .0625);
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();
double conRadius = con.cableType.getRenderDiameter() / 2;
return new Vec3d(.5 - conRadius * side.getFrontOffsetX(), .5 - conRadius * side.getFrontOffsetY(), .5 - conRadius * side.getFrontOffsetZ());
}
@Override
public boolean canConnect() {
return true;
}
@Override
public boolean isEnergyOutput() {
return !relay;
}
@Override
public boolean canConnectCable(WireType cableType, TargetingInfo target) {
return (limitType == null || (this.isRelay() && limitType == cableType)) && canConnect(cableType);
}
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[0];
}
@ -204,7 +216,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public double getDemandedEnergy() {
double ret = maxStored-inBuffer;
double ret = maxStored + .5 - inBuffer;
if (ret < .1)
ret = 0;
return ret;
@ -307,8 +319,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
float length = this instanceof TileEntityIC2ConnectorHV ? (relay ? .875f : .75f) : this instanceof TileEntityIC2ConnectorGold ? .5625f : .5f;
float wMin = .3125f;
float wMax = .6875f;
switch(f.getOpposite() )
{
switch (f.getOpposite()) {
case UP:
return new AxisAlignedBB(wMin, 0, wMin, wMax, length, wMax);
case DOWN:
@ -324,6 +335,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
return new AxisAlignedBB(0, 0, 0, 1, 1, 1);
}
/*
* regarding equals+hashCode
* TE's are considered equal if they have the same pos+dimension id
@ -336,6 +348,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
ret = 31*ret+pos.hashCode();
return ret;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
@ -356,6 +369,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
return true;
}
@Override
public boolean canRotate(EnumFacing axis) {
return false;

View file

@ -62,7 +62,7 @@ public class ClientEventHandler {
s = I18n.format(Lib.DESC_INFO + "attachedTo", link[1], link[2], link[3]);
RayTraceResult focussedBlock = ClientUtils.mc().objectMouseOver;
double distSquared;
if (focussedBlock!=null&&focussedBlock.getBlockPos()!=null) {
if (focussedBlock != null && focussedBlock.typeOfHit == RayTraceResult.Type.BLOCK) {
distSquared = focussedBlock.getBlockPos().distanceSq(link[1], link[2], link[3]);
} else {
distSquared = player.getDistanceSq(link[1], link[2], link[3]);
@ -94,6 +94,7 @@ public class ClientEventHandler {
}
}
}
@SubscribeEvent
public void bakeModel(ModelBakeEvent event) {
event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID + ":control_panel", "inventory,type=top"), new PanelModel());

View file

@ -37,10 +37,12 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.client.gui.GuiPanelComponent;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.client.gui.GuiRSPanelConn;
import malte0811.industrialWires.client.gui.GuiRenameKey;
import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
import malte0811.industrialWires.client.render.TileRenderJacobsLadder;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
@ -117,6 +119,11 @@ public class ClientProxy extends CommonProxy {
ModelBakery.registerItemVariants(IndustrialWires.panelComponent, loc);
ModelLoader.setCustomModelResourceLocation(IndustrialWires.panelComponent, meta, new ModelResourceLocation(loc, "inventory"));
}
for (int meta = 0; meta < ItemKey.types.length; meta++) {
ResourceLocation loc = new ResourceLocation(IndustrialWires.MODID, "key/" + ItemKey.types[meta]);
ModelBakery.registerItemVariants(IndustrialWires.key, loc);
ModelLoader.setCustomModelResourceLocation(IndustrialWires.key, meta, new ModelResourceLocation(loc, "inventory"));
}
Block[] blocks = {IndustrialWires.ic2conn, IndustrialWires.mechConv, IndustrialWires.jacobsLadder, IndustrialWires.panel};
for (Block b : blocks) {
@ -205,9 +212,10 @@ public class ClientProxy extends CommonProxy {
);
}
Config.manual_doubleA.put("iwJacobsUsage", IWConfig.HVStuff.jacobsUsageEU);
m.addEntry("industrialWires.jacobs", "industrialWires",
new ManualPages.CraftingMulti(m, "industrialWires.jacobs0", new ItemStack(IndustrialWires.jacobsLadder, 1, 0), new ItemStack(IndustrialWires.jacobsLadder, 1, 1), new ItemStack(IndustrialWires.jacobsLadder, 1, 2)),
new ManualPages.Text(m, "industrialWires.jacobs1"));
Config.manual_int.put("iwKeysOnRing", IWConfig.maxKeysOnRing);
m.addEntry("industrialwires.jacobs", "industrialwires",
new ManualPages.CraftingMulti(m, "industrialwires.jacobs0", new ItemStack(IndustrialWires.jacobsLadder, 1, 0), new ItemStack(IndustrialWires.jacobsLadder, 1, 1), new ItemStack(IndustrialWires.jacobsLadder, 1, 2)),
new ManualPages.Text(m, "industrialwires.jacobs1"));
m.addEntry("industrialWires.intro", "control_panels",
@ -225,14 +233,17 @@ public class ClientProxy extends CommonProxy {
new ManualPages.Crafting(m, "industrialWires.redstone0", new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.RS_WIRE.ordinal())),
new ManualPages.Text(m, "industrialWires.redstone1")
);
m.addEntry("industrialWires.components", "control_panels",
new ManualPages.Crafting(m, "industrialWires.button", new ItemStack(IndustrialWires.panelComponent, 1, 0)),
new ManualPages.Crafting(m, "industrialWires.label", new ItemStack(IndustrialWires.panelComponent, 1, 1)),
new ManualPages.Crafting(m, "industrialWires.indicator_light", new ItemStack(IndustrialWires.panelComponent, 1, 2)),
new ManualPages.Crafting(m, "industrialWires.slider", new ItemStack(IndustrialWires.panelComponent, 1, 3)),
new ManualPages.CraftingMulti(m, "industrialWires.toggle_switch", new ItemStack(IndustrialWires.panelComponent, 1, 5), new ItemStack(IndustrialWires.panelComponent, 1, 6)),
new ManualPages.Text(m, "industrialWires.toggle_switch1"),
new ManualPages.Crafting(m, "industrialWires.variac", new ItemStack(IndustrialWires.panelComponent, 1, 4))
m.addEntry("industrialwires.components", "control_panels",
new ManualPages.Text(m, "industrialwires.components.general"),
new ManualPages.Crafting(m, "industrialwires.button", new ItemStack(IndustrialWires.panelComponent, 1, 0)),
new ManualPages.Crafting(m, "industrialwires.label", new ItemStack(IndustrialWires.panelComponent, 1, 1)),
new ManualPages.Crafting(m, "industrialwires.indicator_light", new ItemStack(IndustrialWires.panelComponent, 1, 2)),
new ManualPages.Crafting(m, "industrialwires.slider", new ItemStack(IndustrialWires.panelComponent, 1, 3)),
new ManualPages.CraftingMulti(m, "industrialwires.toggle_switch", new ItemStack(IndustrialWires.panelComponent, 1, 5), new ItemStack(IndustrialWires.panelComponent, 1, 6)),
new ManualPages.Text(m, "industrialwires.toggle_switch1"),
new ManualPages.Crafting(m, "industrialwires.variac", new ItemStack(IndustrialWires.panelComponent, 1, 4)),
new ManualPages.CraftingMulti(m, "industrialwires.lock", new ItemStack(IndustrialWires.panelComponent, 1, 7), new ItemStack(IndustrialWires.key)),
new ManualPages.Crafting(m, "industrialwires.lock1", new ItemStack(IndustrialWires.key, 1, 2))
);
}
@ -245,6 +256,7 @@ public class ClientProxy extends CommonProxy {
private static ResourceLocation jacobsStart = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_start");//~470 ms ~=9 ticks
private static ResourceLocation jacobsMiddle = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_middle");
private static ResourceLocation jacobsEnd = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_end");//~210 ms ~= 4 ticks
@Override
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
if (playingSounds.containsKey(te.getPos())) {
@ -283,8 +295,12 @@ public class ClientProxy extends CommonProxy {
} else if (ID == 1) {
EnumHand h = z == 1 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
ItemStack held = player.getHeldItem(h);
if (held != null && held.getItem() == IndustrialWires.panelComponent) {
if (held!=null) {
if (held.getItem() == IndustrialWires.panelComponent) {
return new GuiPanelComponent(h, ItemPanelComponent.componentFromStack(held));
} else if (held.getItem() == IndustrialWires.key) {
return new GuiRenameKey(h);
}
}
}
return null;

View file

@ -32,9 +32,17 @@ public class RawQuad {
public final float[] colorA;
public final Vector3f normal;
public final float[] uvs;
public int light;
public RawQuad(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3,
EnumFacing facing, TextureAtlasSprite tex, float[] colorA,
Vector3f normal, float[] uvs) {
this(v0, v1, v2, v3, facing, tex, colorA, normal, uvs, -1);
}
public RawQuad(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3,
EnumFacing facing, TextureAtlasSprite tex, float[] colorA,
Vector3f normal, float[] uvs, int light) {
vertices[0] = v0;
vertices[1] = v1;
vertices[2] = v2;
@ -49,7 +57,9 @@ public class RawQuad {
}
this.normal = normal;
this.uvs = uvs;
this.light = light;
}
public RawQuad apply(Matrix4 mat) {
Matrix4 matNormal = mat.copy().transpose();
matNormal.invert();

View file

@ -11,7 +11,8 @@ import malte0811.industrialWires.client.gui.elements.GuiIntChooser;
import malte0811.industrialWires.containers.ContainerPanelComponent;
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.network.MessageComponentSync;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.network.MessageItemSync;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
@ -91,6 +92,7 @@ public class GuiPanelComponent extends GuiContainer {
}
private ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/panel_component.png");
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1, 1, 1, 1);
@ -244,86 +246,93 @@ public class GuiPanelComponent extends GuiContainer {
private void sync(int id, String value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(MessageComponentSync.ID, id);
update.setString(MessageComponentSync.VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setString(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void sync(int id, boolean value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(MessageComponentSync.ID, id);
update.setBoolean(MessageComponentSync.VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setBoolean(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void sync(int id, byte value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(MessageComponentSync.ID, id);
update.setByte(MessageComponentSync.VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setByte(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void sync(int id, int value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(MessageComponentSync.ID, id);
update.setInteger(MessageComponentSync.VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setInteger(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void sync(int id, float value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(MessageComponentSync.ID, id);
update.setFloat(MessageComponentSync.VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setFloat(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void syncAll() {
NBTTagList list = new NBTTagList();
for (int i = 0; i < stringTexts.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setString(MessageComponentSync.VALUE, stringTexts.get(i).getText());
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setString(ItemPanelComponent.VALUE, stringTexts.get(i).getText());
list.appendTag(update);
}
for (int i = 0; i < boolButtons.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setBoolean(MessageComponentSync.VALUE, boolButtons.get(i).state);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setBoolean(ItemPanelComponent.VALUE, boolButtons.get(i).state);
list.appendTag(update);
}
for (int i = 0; i < rsChannelChoosers.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setByte(MessageComponentSync.VALUE, rsChannelChoosers.get(i).getSelected());
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setByte(ItemPanelComponent.VALUE, rsChannelChoosers.get(i).getSelected());
list.appendTag(update);
}
for (int i = 0; i < intChoosers.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setInteger(MessageComponentSync.VALUE, intChoosers.get(i).getValue());
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setInteger(ItemPanelComponent.VALUE, intChoosers.get(i).getValue());
list.appendTag(update);
}
for (int i = 0; i < floatSliders.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setFloat(MessageComponentSync.VALUE, (float) floatSliders.get(i).getValue());
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setFloat(ItemPanelComponent.VALUE, (float) floatSliders.get(i).getValue());
list.appendTag(update);
}
sync(list);
}
private void syncSingle(NBTTagCompound nbt) {
NBTTagList list = new NBTTagList();
list.appendTag(nbt);
sync(list);
}
private void sync(NBTTagList list) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("data", list);
IndustrialWires.packetHandler.sendToServer(new MessageComponentSync(container.hand, nbt));
IndustrialWires.packetHandler.sendToServer(new MessageItemSync(container.hand, nbt));
}
}

View file

@ -206,6 +206,7 @@ public class GuiPanelCreator extends GuiContainer {
}
private ItemStack lastFloating;
private PanelComponent lastFloatingPC;
private PanelComponent getFloatingPC() {
ItemStack floating = mc.thePlayer.inventory.getItemStack();
if (floating==null||floating.getItem()!=IndustrialWires.panelComponent) {

View file

@ -35,10 +35,12 @@ import java.io.IOException;
public class GuiRSPanelConn extends GuiContainer {
private TileEntityRSPanelConn te;
private GuiIntChooser chooser;
public GuiRSPanelConn(TileEntityRSPanelConn tile) {
super(new ContainerRSPanelConn(tile));
te = tile;
}
@Override
public void initGui() {
super.initGui();
@ -65,6 +67,7 @@ public class GuiRSPanelConn extends GuiContainer {
}
private ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/rs_wire_controller.png");
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1, 1, 1, 1);

View file

@ -0,0 +1,106 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.client.gui;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.containers.ContainerRenameKey;
import malte0811.industrialWires.network.MessageItemSync;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import java.io.IOException;
public class GuiRenameKey extends GuiContainer {
private EnumHand hand;
private GuiTextField field;
public GuiRenameKey(EnumHand h) {
super(new ContainerRenameKey(h));
hand = h;
}
@Override
public void initGui() {
super.initGui();
field = new GuiTextField(0, mc.fontRendererObj, (width-58)/2, (height-12)/2, 58, 12);
ItemStack held = mc.thePlayer.getHeldItem(hand);
if (held!=null) {
NBTTagCompound nbt = held.getTagCompound();
if (nbt != null && nbt.hasKey("name")) {
field.setText(nbt.getString("name"));
}
}
xSize = 68;
ySize = 22;
guiLeft = (width - xSize) / 2;
guiTop = (height - ySize) / 2;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
GlStateManager.color(1, 1, 1, 1);
RenderHelper.disableStandardItemLighting();
field.drawTextBox();
RenderHelper.enableStandardItemLighting();
}
private ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/key_rename.png");
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1, 1, 1, 1);
mc.getTextureManager().bindTexture(textureLoc);
Gui.drawModalRectWithCustomSizedTexture(guiLeft, guiTop, 0, 0, xSize, ySize, 68, 22);
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
field.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if (!field.textboxKeyTyped(typedChar, keyCode)) {
super.keyTyped(typedChar, keyCode);
}
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("name", field.getText());
IndustrialWires.packetHandler.sendToServer(new MessageItemSync(hand, nbt));
}
}

View file

@ -10,6 +10,7 @@ import javax.annotation.Nonnull;
public class GuiChannelPicker extends GuiButton {
protected byte selected;
protected byte currHovered;
public GuiChannelPicker(int id, int x, int y, int size, byte selectedChannel) {
super(id, x, y, size, size, "");
selected = selectedChannel;
@ -59,9 +60,11 @@ public class GuiChannelPicker extends GuiButton {
selected = currHovered;
}
}
public byte getSelected() {
return selected;
}
public boolean isHovered(int x, int y) {
return xPosition <= x && xPosition + width >= x && yPosition <= y && yPosition + height >= y;
}

View file

@ -27,6 +27,7 @@ import javax.annotation.Nonnull;
public class GuiChannelPickerSmall extends GuiChannelPicker {
private boolean open = false;
private int offSize, onSize;
public GuiChannelPickerSmall(int id, int x, int y, int offSize, int onSize, byte selectedChannel) {
super(id, x, y, offSize, selectedChannel);
selected = selectedChannel;

View file

@ -11,6 +11,7 @@ public class GuiIntChooser extends Gui {
private int max;
private String format;
private Minecraft mc = Minecraft.getMinecraft();
public GuiIntChooser(int x, int y, boolean neg, int initialValue, int digits) {
allowNegative = neg;
value = initialValue;
@ -20,6 +21,7 @@ public class GuiIntChooser extends Gui {
xPlus = x+mc.fontRendererObj.getCharWidth('0')*(digits+(allowNegative?1:0))+mc.fontRendererObj.getCharWidth('-')+2;
format = "%"+digits+"s";
}
public void drawChooser() {
int color = 0xE0E0E0;
String val = String.format(format, Integer.toString(value)).replace(' ', '0');

View file

@ -49,6 +49,7 @@ public class PanelModel implements IBakedModel {
.maximumSize(100)
.expireAfterAccess(60, TimeUnit.SECONDS)
.build();
static {
IEApi.renderCacheClearers.add(modelCache::invalidateAll);
IEApi.renderCacheClearers.add(PanelItemOverride.ITEM_MODEL_CACHE::invalidateAll);
@ -169,6 +170,7 @@ public class PanelModel implements IBakedModel {
.maximumSize(100)
.expireAfterAccess(60, TimeUnit.SECONDS)
.build();
public PanelItemOverride() {
super(ImmutableList.of());
}

View file

@ -62,10 +62,11 @@ public class RawModelFontRenderer extends FontRenderer {
Vector3f v3 = new Vector3f(posX + w, h0, posY);
v3.scale(scale);
builder.add(new RawQuad(v0, v1, v2, v3,
EnumFacing.UP, sprite, new float[]{1, 0, 0, 1}, new Vector3f(0, 1, 0),
EnumFacing.UP, sprite, colorA, new Vector3f(0, 1, 0),
new float[]{x, y, x + wt, y + ht}));
return charWidth[pos];
}
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
super.onResourceManagerReload(resourceManager);

View file

@ -0,0 +1,78 @@
package malte0811.industrialWires.client.panelmodel;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumType;
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
import net.minecraftforge.client.model.pipeline.LightUtil;
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
import net.minecraftforge.client.model.pipeline.VertexLighterFlat;
import java.lang.reflect.Field;
//Yes, this is copied from the IE version. But I wrote that one, so...
public class SmartLightingQuadIW extends BakedQuad {
private static Field parent;
static {
try {
parent = QuadGatheringTransformer.class.getDeclaredField("parent");
parent.setAccessible(true);
} catch (Exception x) {
x.printStackTrace();
}
}
private int brightness;
public SmartLightingQuadIW(int[] vertexDataIn, int tintIndexIn, EnumFacing faceIn, TextureAtlasSprite spriteIn, VertexFormat format, int brightness) {
super(vertexDataIn, tintIndexIn, faceIn, spriteIn, false, format);
this.brightness = brightness;
}
public SmartLightingQuadIW(BakedQuad ret, int light) {
super(ret.getVertexData(), ret.getTintIndex(), ret.getFace(), ret.getSprite(), false, ret.getFormat());
this.brightness = light;
}
@Override
public void pipe(IVertexConsumer consumer) {
if (consumer instanceof VertexLighterFlat) {
try {
consumer = (IVertexConsumer) parent.get(consumer);
} catch (Throwable e) {
e.printStackTrace();
}
}
consumer.setQuadOrientation(this.getFace());
if (this.hasTintIndex()) {
consumer.setQuadTint(this.getTintIndex());
}
float[] data = new float[4];
VertexFormat format = consumer.getVertexFormat();
int count = format.getElementCount();
int[] eMap = LightUtil.mapFormats(format, DefaultVertexFormats.ITEM);
int itemCount = DefaultVertexFormats.ITEM.getElementCount();
eMap[eMap.length - 1] = 2;
for (int v = 0; v < 4; v++) {
for (int e = 0; e < count; e++) {
if (eMap[e] != itemCount) {
if (format.getElement(e).getUsage() == EnumUsage.UV && format.getElement(e).getType() == EnumType.SHORT)//lightmap is UV with 2 shorts
{
data[0] = ((float) ((brightness >> 0x04) & 0xF) * 0x20) / 0xFFFF;
data[1] = ((float) ((brightness >> 0x14) & 0xF) * 0x20) / 0xFFFF;
} else {
LightUtil.unpack(this.getVertexData(), data, DefaultVertexFormats.ITEM, v, eMap[e]);
}
consumer.put(e, data);
} else {
consumer.put(e, 0);
}
}
}
}
}

View file

@ -25,11 +25,9 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.model.ModelLoader;
import org.lwjgl.opengl.GL11;
public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntityJacobsLadder> {
@ -103,8 +101,10 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
}
tes.draw();
}
private final float[] saltColor = {1, 190 / 255F, 50 / 255F};
private final float[] airColor = {1, .85F, 1};
private float[] getColor(double t, double salt, LadderSize size) {
salt = Math.min(salt, 1);
int factor = 20;
@ -126,6 +126,7 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
}
return interpolate(saltyness, saltColor, 1 - saltyness, airColor);
}
private float[] interpolate(double a, float[] cA, double b, float[] cB) {
float[] ret = new float[cA.length];
for (int i = 0; i < ret.length; i++) {
@ -145,6 +146,7 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
color(color0, vertexBuffer.pos(v0.xCoord - rad.xCoord, v0.yCoord - rad.yCoord, v0.zCoord - rad.zCoord)).endVertex();
color(color1, vertexBuffer.pos(v1.xCoord - rad.xCoord, v1.yCoord - rad.yCoord, v1.zCoord - rad.zCoord)).endVertex();
}
private VertexBuffer color(float[] color, VertexBuffer vb) {
vb.color(color[0], color[1], color[2], 1);
return vb;

View file

@ -26,9 +26,11 @@ import net.minecraft.util.EnumHand;
public class ContainerPanelComponent extends Container {
public EnumHand hand;
public ContainerPanelComponent(EnumHand h) {
hand = h;
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
ItemStack held = playerIn.getHeldItem(hand);

View file

@ -18,22 +18,32 @@
package malte0811.industrialWires.containers;
import blusunrize.immersiveengineering.common.gui.ContainerIEBase;
import blusunrize.immersiveengineering.api.ApiUtils;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.controlpanel.PanelUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
public class ContainerPanelCreator extends Container {
public TileEntityPanelCreator tile;
//TODO remove dependency on core IE
public class ContainerPanelCreator extends ContainerIEBase<TileEntityPanelCreator> {
public ContainerPanelCreator(InventoryPlayer inventoryPlayer, TileEntityPanelCreator tile) {
super(inventoryPlayer, tile);
int slotH = 150;
int slotX = 14;
slotCount = 1;
this.tile = tile;
IInventory inv = new SingleSlotInventory((i) -> tile.inv = i, () -> tile.inv, tile::markDirty, this::canInteractWith, "panel_creator");
addSlotToContainer(new Slot(inv, 0, 7, 37) {
@Override
public int getSlotStackLimit() {
@ -41,8 +51,10 @@ public class ContainerPanelCreator extends ContainerIEBase<TileEntityPanelCreato
}
@Override
public boolean isItemValid(@Nullable ItemStack stack) {
return stack != null && (ItemStack.areItemStacksEqual(stack, PanelUtils.getPanelBase()) || stack.getItem() == PanelUtils.PANEL_ITEM);
public boolean isItemValid(ItemStack stack) {
if (ItemStack.areItemStacksEqual(ApiUtils.copyStackWithAmount(stack, 1), PanelUtils.getPanelBase()))
return true;
return stack.getItem() == PanelUtils.PANEL_ITEM && stack.getMetadata() == BlockTypes_Panel.TOP.ordinal();
}
});
@ -52,4 +64,162 @@ public class ContainerPanelCreator extends ContainerIEBase<TileEntityPanelCreato
for (int i = 0; i < 9; i++)
addSlotToContainer(new Slot(inventoryPlayer, i, slotX + i * 18, slotH + 58));
}
@Override
public boolean canInteractWith(@Nonnull EntityPlayer player) {
return player.getDistanceSq(tile.getPos()) < 100;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
Slot clicked = getSlot(index);
if (index == 0 && clicked.getStack()!=null) {
boolean change = mergeItemStack(clicked.getStack(), 1, 37, false);
if (change) {
clicked.onSlotChanged();
}
if (clicked.getStack().stackSize<=0) {
clicked.putStack(null);
}
} else {
ItemStack inSlot = clicked.getStack();
Slot slot0 = getSlot(0);
ItemStack stack0 = slot0.getStack();
if (inSlot!=null && slot0.isItemValid(inSlot) && (stack0==null || stack0.stackSize < slot0.getSlotStackLimit())) {
slot0.putStack(inSlot.splitStack(slot0.getSlotStackLimit()));
clicked.onSlotChanged();
if (clicked.getStack()!=null&&clicked.getStack().stackSize<=0) {
clicked.putStack(null);
}
}
}
return null;
}
public static class SingleSlotInventory implements IInventory {
Consumer<ItemStack> set;
Supplier<ItemStack> get;
Runnable markDirty;
Predicate<EntityPlayer> isUsable;
String name;
public SingleSlotInventory(Consumer<ItemStack> set, Supplier<ItemStack> get, Runnable markDirty, Predicate<EntityPlayer> isUsable,
String name) {
this.set = set;
this.get = get;
this.markDirty = markDirty;
this.isUsable = isUsable;
this.name = name;
}
@Override
public int getSizeInventory() {
return 1;
}
@Override
public ItemStack getStackInSlot(int index) {
return index == 0 ? get.get() : null;
}
@Override
public ItemStack decrStackSize(int index, int count) {
if (index != 0) {
return null;
}
ItemStack stack = get.get();
if (stack==null) {
return null;
}
ItemStack ret = stack.splitStack(count);
if (stack.stackSize <= 0) {
set.accept(null);
}
return ret;
}
@Override
public ItemStack removeStackFromSlot(int index) {
if (index == 0) {
ItemStack ret = get.get();
set.accept(null);
return ret;
}
return null;
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
if (index == 0) {
set.accept(stack);
}
}
@Override
public int getInventoryStackLimit() {
return 1;
}
@Override
public void markDirty() {
markDirty.run();
}
@Override
public boolean isUseableByPlayer(@Nonnull EntityPlayer player) {
return isUsable.test(player);
}
@Override
public void openInventory(@Nonnull EntityPlayer player) {
}
@Override
public void closeInventory(@Nonnull EntityPlayer player) {
}
@Override
public boolean isItemValidForSlot(int index, @Nonnull ItemStack stack) {
return true;
}
@Override
public int getField(int id) {
return 0;
}
@Override
public void setField(int id, int value) {
}
@Override
public int getFieldCount() {
return 0;
}
@Override
public void clear() {
set.accept(null);
}
@Nonnull
@Override
public String getName() {
return name;
}
@Override
public boolean hasCustomName() {
return false;
}
@Nonnull
@Override
public ITextComponent getDisplayName() {
return new TextComponentString(name);
}
}
}

View file

@ -22,13 +22,17 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import javax.annotation.Nonnull;
public class ContainerRSPanelConn extends Container {
final TileEntityRSPanelConn te;
private final TileEntityRSPanelConn te;
public ContainerRSPanelConn(TileEntityRSPanelConn tile) {
te = tile;
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
public boolean canInteractWith(@Nonnull EntityPlayer playerIn) {
return playerIn.getDistanceSq(te.getPos()) < 64;
}
}

View file

@ -0,0 +1,39 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.containers;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.EnumHand;
import javax.annotation.Nonnull;
public class ContainerRenameKey extends Container {
private final EnumHand hand;
public ContainerRenameKey(EnumHand h) {
hand = h;
}
@Override
public boolean canInteractWith(@Nonnull EntityPlayer playerIn) {
return playerIn.getHeldItem(hand).getItem()== IndustrialWires.key;
}
}

View file

@ -60,16 +60,14 @@ public class CoveredToggleSwitch extends ToggleSwitch {
}
@Override
public boolean interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (player.isSneaking() && state == SwitchState.OPEN) {
state = SwitchState.CLOSED;
} else {
state = state.next();
}
setOut(state.active, tile);
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
@Override
@ -105,6 +103,7 @@ public class CoveredToggleSwitch extends ToggleSwitch {
ret.state = state;
ret.rsOutputChannel = rsOutputChannel;
ret.rsOutputId = rsOutputId;
ret.active = active;
ret.setX(getX());
ret.setY(getY());
ret.setPanelHeight(panelHeight);
@ -160,7 +159,6 @@ public class CoveredToggleSwitch extends ToggleSwitch {
CoveredToggleSwitch that = (CoveredToggleSwitch) o;
if (active != that.active) return false;
if (rsOutputId != that.rsOutputId) return false;
if (rsOutputChannel != that.rsOutputChannel) return false;
if (color != that.color) return false;
@ -184,10 +182,12 @@ public class CoveredToggleSwitch extends ToggleSwitch {
ACTIVE(true, true);
public boolean active;
public boolean open;
SwitchState(boolean active, boolean open) {
this.open = open;
this.active = active;
}
SwitchState next() {
return values()[(ordinal() + 1) % values().length];
}

View file

@ -85,9 +85,11 @@ public interface IConfigurableComponent {
class RSChannelConfig extends UniversalConfig<Byte> {
public boolean small;
public RSChannelConfig(String name, int x, int y, Byte value) {
this(name, x, y, value, false);
}
public RSChannelConfig(String name, int x, int y, Byte value, boolean small) {
super(name, x, y, value);
this.small = small;
@ -113,6 +115,7 @@ public interface IConfigurableComponent {
this.width = width;
}
}
enum ConfigType {
BOOL,
STRING,

View file

@ -44,9 +44,11 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
private byte rsInputChannel;
private int colorA = 0xff00;
private byte rsInput;
public IndicatorLight() {
super("indicator_light");
}
public IndicatorLight(int rsId, byte rsChannel, int color) {
this();
colorA = color;
@ -74,6 +76,7 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
private static final float size = .0625F;
private static final float antiZOffset = .001F;
@Override
public List<RawQuad> getQuads() {
float[] color = new float[4];
@ -83,6 +86,9 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
}
List<RawQuad> ret = new ArrayList<>(1);
PanelUtils.addColoredQuad(ret, new Vector3f(), new Vector3f(0, antiZOffset, size), new Vector3f(size, antiZOffset, size), new Vector3f(size, antiZOffset, 0), EnumFacing.UP, color);
if (rsInput>0) {
ret.get(ret.size()-1).light = 0xff0ff;
}
return ret;
}
@ -107,22 +113,23 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
}
@Override
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
return false;
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
}
@Override
public void update(TileEntityPanel tile) {
}
private TileEntityPanel panel;
private Consumer<byte[]> handler = (input) -> {
if (input[rsInputChannel] != rsInput) {
rsInput = input[rsInputChannel];
panel.markDirty();
panel.triggerRenderUpdate();
}
};
@Nullable
@Override
public Consumer<byte[]> getRSInputHandler(int id, TileEntityPanel panel) {

View file

@ -33,6 +33,8 @@ import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -49,6 +51,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
this.text = text;
this.color = color;
}
public Label() {
super("label");
}
@ -86,17 +89,21 @@ public class Label extends PanelComponent implements IConfigurableComponent {
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb == null) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
RawModelFontRenderer fr = fontRenderer();
float width = fr.getStringWidth(text) * fr.scale;
float height = fr.FONT_HEIGHT * fr.scale;
aabb = new AxisAlignedBB(getX(), 0, getY(), getX() + width, 0, getY() + height);
} else {
aabb = new AxisAlignedBB(getX(), 0, getY(), getX() + .001, 0, getY() + .001);
}
}
return aabb;
}
@Override
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
return false;
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
}
@Override
@ -184,4 +191,24 @@ public class Label extends PanelComponent implements IConfigurableComponent {
new FloatConfig("blue", 0, 70, color[2], 60)
};
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Label label = (Label) o;
if (color != label.color) return false;
return text.equals(label.text);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + text.hashCode();
result = 31 * result + color;
return result;
}
}

View file

@ -22,6 +22,7 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
@ -34,10 +35,7 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
public class LightedButton extends PanelComponent implements IConfigurableComponent {
public int color = 0xFF0000;
@ -46,10 +44,11 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
public int rsOutputId;
public int rsOutputChannel;
private int ticksTillOff;
private Set<BiConsumer<Integer, Byte>> rsOut = new HashSet<>();
public LightedButton() {
super("lighted_button");
}
public LightedButton(int color, boolean active, boolean latching, int rsOutputId, int rsOutputChannel) {
this();
this.color = color;
@ -62,8 +61,8 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
nbt.setInteger(COLOR, color);
nbt.setInteger("timeout", ticksTillOff);
if (!toItem) {
nbt.setInteger("timeout", ticksTillOff);
nbt.setBoolean("active", active);
}
nbt.setBoolean(LATCHING, latching);
@ -80,12 +79,18 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
rsOutputChannel = nbt.getInteger(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
private final static float size = .0625F;
@Override
public List<RawQuad> getQuads() {
float[] color = PanelUtils.getFloatColor(active, this.color);
List<RawQuad> ret = new ArrayList<>(5);
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(0, 0, 0), new Vector3f(size, size / 2, size), ret, false);
if (active) {
ret.get(0).light = 0xff0ff;
}
return ret;
}
@ -109,17 +114,18 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
public boolean interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (!latching && active) {
return false;
ticksTillOff = 10;
tile.markDirty();
tile.triggerRenderUpdate();
return;
}
setOut(!active, tile);
if (!latching) {
ticksTillOff = 10;
}
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
@Override
@ -134,17 +140,10 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsOutputId) {
rsOut.add(out);
out.accept(rsOutputChannel, (byte) (active?15:0));
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsOutputId) {
rsOut.remove(out);
super.registerRSOutput(id, out);
out.accept(rsOutputChannel, (byte) (active ? 15 : 0), this);
}
}
@ -160,16 +159,13 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
@Override
public void invalidate(TileEntityPanel te) {
setOut(false, te);
setOut(rsOutputChannel, 0);
}
private void setOut(boolean on, TileEntityPanel tile) {
active = on;
tile.markDirty();
tile.triggerRenderUpdate();
for (BiConsumer<Integer, Byte> rs:rsOut) {
rs.accept(rsOutputChannel, (byte)(active?15:0));
}
setOut(rsOutputChannel, active ? 15 : 0);
}
@Override

View file

@ -0,0 +1,358 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.block.Block;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Lock extends PanelComponent implements IConfigurableComponent {
private final static Random rand = new Random();
@Nullable
private NBTTagCompound keyNBT;
private boolean turned;
private boolean latching = false;
private int rsOutputId;
private int rsOutputChannel;
private int ticksTillOff;
private int lockID;
public Lock() {
super("lock");
while (lockID==0) {
lockID = rand.nextInt();
}
}
public Lock(boolean latching, int rsOutputId, int rsOutputChannel) {
this();
this.latching = latching;
this.rsOutputChannel = rsOutputChannel;
this.rsOutputId = rsOutputId;
}
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
if (!toItem) {
nbt.setInteger("timeout", ticksTillOff);
nbt.setBoolean("turned", turned);
if (keyNBT != null) {
nbt.setTag("key", keyNBT);
}
}
nbt.setInteger("lockId", lockID);
nbt.setBoolean(LATCHING, latching);
nbt.setInteger(RS_CHANNEL, rsOutputChannel);
nbt.setInteger(RS_ID, rsOutputId);
}
@Override
protected void readCustomNBT(NBTTagCompound nbt) {
ticksTillOff = nbt.getInteger("timeout");
if (nbt.hasKey("key", 10)) {
keyNBT = nbt.getCompoundTag("key");
} else {
keyNBT = null;
}
turned = nbt.getBoolean("turned");
if (nbt.hasKey("lockId")) {
lockID = nbt.getInteger("lockId");
}
latching = nbt.getBoolean(LATCHING);
rsOutputChannel = nbt.getInteger(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
private final static float size = .0625F;
private final static float keyWidth = .125F * size;
private final static float yOffset = size / 2 + .0001F;
private final static float xOffset = (size - keyWidth) / 2;
private final static float[] DARK_GRAY = {.4F, .4F, .4F};
private final static int DARK_GRAY_INT = 0xFF686868;
private final static float zOffset = keyWidth / 2;
private final static float keyOffset = keyWidth;
private final static float zOffsetLowerKey = size / 4;
@Override
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>(5);
PanelUtils.addColoredBox(GRAY, GRAY, null, new Vector3f(0, 0, 0), new Vector3f(size, size / 2, size), ret, false);
if (keyNBT != null) {
Matrix4 mat = null;
if (turned) {
mat = new Matrix4();
mat.translate(size / 2, 0, size / 2);
mat.rotate(Math.PI / 2, 0, 1, 0);
mat.translate(-size / 2, 0, -size / 2);
}
addKey(ret, mat);
} else {
PanelUtils.addColoredQuad(ret, new Vector3f(xOffset + keyWidth, yOffset, zOffsetLowerKey), new Vector3f(xOffset, yOffset, zOffsetLowerKey),
new Vector3f(xOffset, yOffset, size - zOffsetLowerKey), new Vector3f(xOffset + keyWidth, yOffset, size - zOffsetLowerKey),
EnumFacing.UP, DARK_GRAY);
}
return ret;
}
private void addKey(List<RawQuad> out, Matrix4 mat) {
PanelUtils.addColoredBox(DARK_GRAY, DARK_GRAY, null, new Vector3f(xOffset, size / 2, zOffsetLowerKey), new Vector3f(keyWidth, keyOffset, size / 2), out, false, mat);
PanelUtils.addColoredBox(DARK_GRAY, DARK_GRAY, null, new Vector3f(xOffset, size / 2 + keyOffset, zOffset), new Vector3f(keyWidth, size, size - 2 * zOffset), out, false, mat);
}
@Override
@Nonnull
public PanelComponent copyOf() {
Lock ret = new Lock(latching, rsOutputId, rsOutputChannel);
ret.turned = turned;
ret.keyNBT = keyNBT == null ? null : keyNBT.copy();
ret.ticksTillOff = ticksTillOff;
ret.setX(x);
ret.setY(y);
ret.panelHeight = panelHeight;
return ret;
}
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + size, getHeight(), y + size);
}
return aabb;
}
@Override
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
boolean update = false;
if (keyNBT == null) {
for (EnumHand hand : EnumHand.values()) {
ItemStack held = player.getHeldItem(hand);
if (held!=null && held.getItem() == IndustrialWires.key && ItemKey.idForKey(held) == lockID) {
keyNBT = held.serializeNBT();
player.setHeldItem(hand, null);
break;
}
}
} else if (!turned) {
if (player.isSneaking() && player.getHeldItemMainhand()== null) {
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.loadItemStackFromNBT(keyNBT));
keyNBT = null;
} else {
turned = true;
}
update = true;
} else {
if (latching) {
turned = false;
update = true;
} else {
ticksTillOff = 10;
}
}
if (update) {
setOut(tile);
if (!latching && turned) {
ticksTillOff = 10;
}
}
tile.triggerRenderUpdate();
}
@Override
public void update(TileEntityPanel tile) {
if (!latching && ticksTillOff > 0) {
ticksTillOff--;
tile.markDirty();
if (ticksTillOff == 0) {
turned = false;
tile.triggerRenderUpdate();
setOut(tile);
}
}
}
@Override
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsOutputId) {
super.registerRSOutput(id, out);
out.accept(rsOutputChannel, (byte) (turned ? 15 : 0), this);
}
}
@Override
public float getHeight() {
return size / 2;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, GRAY_INT);
AxisAlignedBB aabb = getBlockRelativeAABB();
int left = (int) (gui.getX0() + (aabb.minX+xOffset) * gui.panelSize);
int top = (int) (gui.getY0() + (aabb.minZ+zOffsetLowerKey) * gui.panelSize);
int right = (int) (gui.getX0() + (aabb.maxX-xOffset) * gui.panelSize);
int bottom = (int) (gui.getY0() + (aabb.maxZ-zOffsetLowerKey) * gui.panelSize);
Gui.drawRect(left, top, right, bottom, DARK_GRAY_INT);
}
@Override
public void invalidate(TileEntityPanel te) {
setOut(rsOutputChannel, 0);
}
private void setOut(TileEntityPanel tile) {
tile.triggerRenderUpdate();
setOut(rsOutputChannel, turned ? 15 : 0);
}
@Override
public void dropItems(TileEntityPanel te) {
super.dropItems(te);
if (keyNBT!=null) {
Block.spawnAsEntity(te.getWorld(), te.getPos(), ItemStack.loadItemStackFromNBT(keyNBT));
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Lock lock = (Lock) o;
if (turned != lock.turned) return false;
if (latching != lock.latching) return false;
if (rsOutputId != lock.rsOutputId) return false;
if (rsOutputChannel != lock.rsOutputChannel) return false;
if (ticksTillOff != lock.ticksTillOff) return false;
if (lockID != lock.lockID) return false;
return keyNBT != null ? keyNBT.equals(lock.keyNBT) : lock.keyNBT == null;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (keyNBT != null ? keyNBT.hashCode() : 0);
result = 31 * result + (turned ? 1 : 0);
result = 31 * result + (latching ? 1 : 0);
result = 31 * result + rsOutputId;
result = 31 * result + rsOutputChannel;
result = 31 * result + ticksTillOff;
result = 31 * result + lockID;
return result;
}
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case BOOL:
if (id == 0) {
latching = ((NBTTagByte) value).getByte() != 0;
}
break;
case RS_CHANNEL:
if (id == 0) {
rsOutputChannel = ((NBTTagByte) value).getByte();
}
break;
case INT:
if (id == 0) {
rsOutputId = ((NBTTagInt) value).getInt();
}
break;
}
}
@Override
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case BOOL:
return I18n.format(IndustrialWires.MODID + ".desc.latching");
case RS_CHANNEL:
case INT:
return null;
default:
return "INVALID";
}
}
@Override
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case BOOL:
return I18n.format(IndustrialWires.MODID + ".desc.latching_info");
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
default:
return "INVALID?";
}
}
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{new IntConfig("rsId", 0, 50, rsOutputId, 2, false)};
}
@Override
public BoolConfig[] getBooleanOptions() {
return new BoolConfig[]{new BoolConfig("latching", 0, 70, latching)};
}
@Override
public int getColor() {
return GRAY_INT;
}
public int getLockID() {
return lockID;
}
}

View file

@ -22,6 +22,7 @@ import blusunrize.immersiveengineering.common.util.IELogger;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
@ -30,13 +31,12 @@ 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.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Supplier;
@ -47,9 +47,12 @@ public abstract class PanelComponent {
private final String type;
protected final static float[] GRAY = {.8F, .8F, .8F};
protected final static int GRAY_INT = 0xFFD0D0D0;
private Set<TriConsumer<Integer, Byte, PanelComponent>> outputs = new HashSet<>();
protected PanelComponent(String type) {
this.type = type;
}
public static final Map<String, Supplier<PanelComponent>> baseCreaters = new HashMap<>();
public final static String COLOR = "color";
public final static String RS_CHANNEL = "rsChannel";
@ -58,6 +61,7 @@ public abstract class PanelComponent {
public static final String HORIZONTAL = "horizontal";
public static final String LENGTH = "length";
public static final String LATCHING = "latching";
static {
baseCreaters.put("lighted_button", LightedButton::new);
baseCreaters.put("label", Label::new);
@ -66,11 +70,16 @@ public abstract class PanelComponent {
baseCreaters.put("variac", Variac::new);
baseCreaters.put("toggle_switch", ToggleSwitch::new);
baseCreaters.put("toggle_switch_covered", CoveredToggleSwitch::new);
baseCreaters.put("lock", Lock::new);
}
protected abstract void writeCustomNBT(NBTTagCompound nbt, boolean toItem);
protected abstract void readCustomNBT(NBTTagCompound nbt);
// DON'T OFFSET BY x, y IN THIS METHOD!
public abstract List<RawQuad> getQuads();
@Nonnull
public abstract PanelComponent copyOf();
@ -78,7 +87,7 @@ public abstract class PanelComponent {
@Nonnull
public abstract AxisAlignedBB getBlockRelativeAABB();
public abstract boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player);
public abstract void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player);
public abstract void update(TileEntityPanel tile);
@ -89,11 +98,19 @@ public abstract class PanelComponent {
return null;
}
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {}
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
outputs.add(out);
}
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {}
public void unregisterRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
outputs.remove(out);
}
public void invalidate(TileEntityPanel te) {}
public void dropItems(TileEntityPanel te) {
}
public void invalidate(TileEntityPanel te) {
}
public float getX() {
return x;
@ -126,20 +143,27 @@ public abstract class PanelComponent {
nbt.setFloat("panelHeight", panelHeight);
nbt.setString("type", type);
}
public static PanelComponent read(NBTTagCompound nbt) {
String type = nbt.getString("type");
if (baseCreaters.containsKey(type)) {
PanelComponent ret = baseCreaters.get(type).get();
ret.readCustomNBT(nbt);
ret.setX(nbt.getFloat("x"));
ret.setY(nbt.getFloat("y"));
ret.setPanelHeight(nbt.getFloat("panelHeight"));
ret.readFromNBT(nbt);
return ret;
} else {
IELogger.info("(IndustrialWires) Unknown panel component: " + type);//TODO own logger?
return null;
}
}
public final void readFromNBT(NBTTagCompound nbt) {
readCustomNBT(nbt);
setX(nbt.getFloat("x"));
setY(nbt.getFloat("y"));
setPanelHeight(nbt.getFloat("panelHeight"));
}
@SideOnly(Side.CLIENT)
public void renderBox(TileEntityPanel te) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
@ -192,6 +216,12 @@ public abstract class PanelComponent {
return true;
}
void setOut(int channel, int level) {
for (TriConsumer<Integer, Byte, PanelComponent> out : outputs) {
out.accept(channel, (byte) level, this);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View file

@ -22,8 +22,12 @@ 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;
import malte0811.industrialWires.blocks.controlpanel.PropertyComponents.PanelRenderProperties;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.panelmodel.SmartLightingQuadIW;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@ -39,7 +43,9 @@ import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.obj.OBJModel;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
@ -51,8 +57,10 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import static malte0811.industrialWires.controlpanel.PanelComponent.*;
import static malte0811.industrialWires.util.MiscUtils.discoverLocal;
public final class PanelUtils {
public static TextureAtlasSprite PANEL_TEXTURE;
@ -72,8 +80,11 @@ public final class PanelUtils {
Matrix4 m4RotOnly = m4.copy();
m4RotOnly.invert();
m4RotOnly.transpose();
for (PanelComponent pc : components) {
Matrix4 m4Here = m4.copy().translate(pc.getX(), 0, pc.getY());
//Intentionally not a for-each to help with CME's
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < components.size(); i++) {
PanelComponent pc = components.get(i);
Matrix4 m4Here = m4.copy().translate(pc.getX(), .0001, pc.getY());
List<RawQuad> compQuads = pc.getQuads();
for (RawQuad bq : compQuads) {
ret.add(bakeQuad(bq, m4Here, m4RotOnly, false));
@ -130,7 +141,11 @@ public final class PanelUtils {
raw.colorA);
putVertexData(format, builder, transform.apply(vertices[3]), faceNormal, uvs[flip ? 0 : 2], uvs[flip ? 3 : 1], raw.tex,
raw.colorA);
return builder.build();
BakedQuad ret = builder.build();
if (raw.light>0) {
ret = new SmartLightingQuadIW(ret, raw.light);
}
return ret;
}
//mostly copied from IE's ClientUtils, it has protected access there...
@ -274,6 +289,12 @@ public final class PanelUtils {
case 6://Covered toggle switch
addCommonInfo(data, list, true, true);
break;
case 7://Lock
addCommonInfo(data, list, false, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
}
}
@ -311,12 +332,26 @@ public final class PanelUtils {
public static boolean intersectXZ(AxisAlignedBB aabb1, AxisAlignedBB aabb2) {
return aabb1.minX < aabb2.maxX && aabb1.maxX > aabb2.minX && aabb1.minZ < aabb2.maxZ && aabb1.maxZ > aabb2.minZ;
}
public static void readListFromNBT(NBTTagList list, @Nonnull List<PanelComponent> base) {
boolean allNew = list.tagCount() != base.size();
if (allNew) {
base.clear();
}
for (int i = 0; i < list.tagCount(); i++) {
PanelComponent pc = PanelComponent.read(list.getCompoundTagAt(i));
NBTTagCompound nbt = list.getCompoundTagAt(i);
PanelComponent pc = PanelComponent.read(nbt);
if (pc != null) {
if (allNew) {
base.add(pc);
} else {
PanelComponent oldPc = base.get(i);
if (pc.getClass() != oldPc.getClass()) {
base.set(i, pc);
} else {
oldPc.readFromNBT(nbt);
}
}
}
}
}
@ -327,4 +362,25 @@ public final class PanelUtils {
}
return panelBase;
}
public static List<BlockPos> discoverPanelParts(World w, BlockPos here, int maxCount) {
BiPredicate<BlockPos, Integer> isValid = (pos, count) -> {
if (pos.equals(here)) {
return true;
}
if (here.distanceSq(pos) > 25 || count > maxCount || !w.isBlockLoaded(pos)) {
return false;
}
IBlockState state = w.getBlockState(pos);
return state.getBlock() == IndustrialWires.panel && state.getValue(BlockPanel.type).isPanelConnector();
};
List<BlockPos> all = discoverLocal(w, here, isValid);
List<BlockPos> ret = new ArrayList<>();
for (BlockPos pos : all) {
if (w.getBlockState(pos).getBlock() == IndustrialWires.panel && w.getBlockState(pos).getValue(BlockPanel.type) != BlockTypes_Panel.DUMMY) {
ret.add(pos);
}
}
return ret;
}
}

View file

@ -22,6 +22,7 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
@ -33,10 +34,7 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
public class Slider extends PanelComponent implements IConfigurableComponent {
private static final float WIDTH = .0625F;
@ -46,7 +44,7 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
private byte out;
private byte rsChannel;
private int rsId;
private Set<BiConsumer<Integer, Byte>> outputs = new HashSet<>();
public Slider(float length, int color, boolean horizontal, int rsId, byte rsChannel) {
this();
this.color = color;
@ -55,9 +53,11 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
this.rsChannel = rsChannel;
this.rsId = rsId;
}
public Slider() {
super("slider");
}
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
nbt.setInteger(COLOR, color);
@ -101,6 +101,9 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(horizontal ? val : 0, 0, horizontal ? 0 : val),
new Vector3f(.0625F, getHeight(), .0625F), ret, false);
if (out>0) {
ret.get(1).light = 0xff0ff;
}
return ret;
}
@ -125,33 +128,21 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
double pos = horizontal ? hitRelative.xCoord : (length - hitRelative.zCoord);
byte newLevel = (byte) (Math.min(pos * 16 / length, 15));
if (newLevel != out) {
for (BiConsumer<Integer, Byte> output:outputs) {
output.accept((int)rsChannel, newLevel);
}
setOut(rsChannel, newLevel);
out = newLevel;
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
return false;
}
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsId) {
outputs.add(out);
out.accept((int)rsChannel, this.out);
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsId) {
outputs.remove(out);
super.registerRSOutput(id, out);
out.accept((int) rsChannel, this.out, this);
}
}
@ -179,9 +170,7 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public void invalidate(TileEntityPanel te) {
for (BiConsumer<Integer, Byte> out:outputs) {
out.accept((int)rsChannel, (byte) 0);
}
setOut(rsChannel, 0);
}
@Override

View file

@ -23,6 +23,7 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
@ -37,22 +38,21 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
public class ToggleSwitch extends PanelComponent implements IConfigurableComponent {
public boolean active;
public int rsOutputId;
public byte rsOutputChannel;
private Set<BiConsumer<Integer, Byte>> rsOut = new HashSet<>();
public ToggleSwitch() {
super("toggle_switch");
}
public ToggleSwitch(String name) {
super(name);
}
public ToggleSwitch(boolean active, int rsOutputId, byte rsOutputChannel) {
this();
this.active = active;
@ -75,11 +75,13 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
rsOutputChannel = nbt.getByte(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
protected float sizeX = .0625F;
protected float sizeY = 1.5F * sizeX;
protected float rodRadius = sizeX * .25F;
protected float rodLength = 3 / 32F;
protected float yOffset = .0001F;
@Override
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
@ -115,11 +117,9 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
}
@Override
public boolean interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
setOut(!active, tile);
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
@Override
@ -128,17 +128,10 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
}
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsOutputId) {
rsOut.add(out);
out.accept((int) rsOutputChannel, (byte) (active?15:0));
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsOutputId) {
rsOut.remove(out);
super.registerRSOutput(id, out);
out.accept((int) rsOutputChannel, (byte) (active ? 15 : 0), this);
}
}
@ -167,16 +160,13 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
@Override
public void invalidate(TileEntityPanel te) {
setOut(false, te);
setOut(rsOutputChannel, 0);
}
protected void setOut(boolean on, TileEntityPanel tile) {
active = on;
tile.markDirty();
tile.triggerRenderUpdate();
for (BiConsumer<Integer, Byte> rs:rsOut) {
rs.accept((int)rsOutputChannel, (byte)(active?15:0));
}
setOut(rsOutputChannel, active ? 15 : 0);
}
@Override

View file

@ -23,6 +23,7 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
@ -38,10 +39,7 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
public class Variac extends PanelComponent implements IConfigurableComponent {
private static final float SIZE = 3 / 16F;
@ -56,7 +54,6 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
private byte out;
private byte rsChannel;
private int rsId;
private Set<BiConsumer<Integer, Byte>> outputs = new HashSet<>();
public Variac(int rsId, byte rsChannel) {
this();
@ -131,7 +128,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
@Override
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
double xRel = hitRelative.xCoord - SIZE / 2;
double yRel = -(hitRelative.zCoord - SIZE / 2);
double angle = 1.5 * Math.PI - Math.atan2(yRel, xRel);
@ -143,7 +140,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
angle -= .5 * Math.PI / 17;
angle /= 2 * Math.PI;
if (angle < 0 || angle >= 16 / 17D) {
return true;
return;
}
byte newLevel = (byte) (angle * 17);
if (newLevel > out) {
@ -153,29 +150,17 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
newLevel = (byte) Math.max(0, Math.min(newLevel, 15));
if (newLevel != out) {
for (BiConsumer<Integer, Byte> output : outputs) {
output.accept((int) rsChannel, newLevel);
}
setOut(rsChannel, newLevel);
out = newLevel;
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
return false;
}
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id == rsId) {
outputs.add(out);
out.accept((int) rsChannel, this.out);
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsId) {
outputs.remove(out);
super.registerRSOutput(id, out);
out.accept((int) rsChannel, this.out, this);
}
}
@ -210,9 +195,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
@Override
public void invalidate(TileEntityPanel te) {
for (BiConsumer<Integer, Byte> out : outputs) {
out.accept((int) rsChannel, (byte) 0);
}
setOut(rsChannel, 0);
}
@Override

View file

@ -25,10 +25,13 @@ import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class RecipeCoilLength implements IRecipe {
public final ItemStack coil;
public final ItemStack cable;
final int maxLength;
private final ItemStack coil;
private final ItemStack cable;
private final int maxLength;
public RecipeCoilLength(int meta) {
coil = new ItemStack(IndustrialWires.coil, 1, meta);
cable = ItemIC2Coil.getUninsulatedCable(coil);
@ -36,13 +39,13 @@ public class RecipeCoilLength implements IRecipe {
}
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
int l = getLength(inv);
return l > 0;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack ret = new ItemStack(IndustrialWires.coil, 1, coil.getItemDamage());
ItemIC2Coil.setLength(ret, Math.min(maxLength, getLength(inv)));
return ret;
@ -50,7 +53,7 @@ public class RecipeCoilLength implements IRecipe {
@Override
public int getRecipeSize() {
return 0;
return 1;
}
@Override
@ -58,8 +61,9 @@ public class RecipeCoilLength implements IRecipe {
return null;
}
@Nonnull
@Override
public ItemStack[] getRemainingItems(InventoryCrafting inv) {
public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
ItemStack[] ret = new ItemStack[inv.getSizeInventory()];
int length = Math.min(getLength(inv), maxLength);
for (int i = 0;i<ret.length&&length>0;i++) {
@ -67,7 +71,7 @@ public class RecipeCoilLength implements IRecipe {
if (OreDictionary.itemMatches(curr, coil, false)) {
length-=ItemIC2Coil.getLength(curr);
if (length<0) {
ret[i] = new ItemStack(IndustrialWires.coil, 1);
ret[i] = coil.copy();
ItemIC2Coil.setLength(ret[i], -length);
}
} else if (OreDictionary.itemMatches(curr, cable, false)) {
@ -76,6 +80,7 @@ public class RecipeCoilLength implements IRecipe {
}
return ret;
}
private int getLength(InventoryCrafting inv) {
int cableLength = 0;
for (int i = 0; i < inv.getSizeInventory(); i++) {

View file

@ -0,0 +1,106 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.crafting;
import blusunrize.immersiveengineering.api.ApiUtils;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class RecipeComponentCopy implements IRecipe {
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
boolean found = false;
int foundX = -1;
int foundY = -1;
for (int x = 0; x < inv.getWidth(); x++) {
for (int y = 0; y < inv.getHeight(); y++) {
ItemStack here = inv.getStackInRowAndColumn(x, y);
PanelComponent pc1 = ItemPanelComponent.componentFromStack(here);
if (pc1!=null) {
if (x==foundX&&y==foundY) {
continue;
}
if (found) {
return false;
}
if (y+1<inv.getHeight()) {
ItemStack below = inv.getStackInRowAndColumn(x, y + 1);
PanelComponent pc2 = ItemPanelComponent.componentFromStack(below);
if (pc2 == null || pc2.getClass() != pc1.getClass()) {
return false;
}
found = true;
foundX = x;
foundY = y + 1;
} else {
return false;
}
}
}
}
return found;
}
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
int[] pos = getTopComponent(inv);
if (pos != null) {
return ApiUtils.copyStackWithAmount(inv.getStackInRowAndColumn(pos[0], pos[1]), 2);
} else {
return null;
}
}
@Override
public int getRecipeSize() {
return 2;
}
@Override
public ItemStack getRecipeOutput() {
return null;
}
@Nonnull
@Override
public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
return new ItemStack[inv.getSizeInventory()];
}
@Nullable
private int[] getTopComponent(@Nonnull InventoryCrafting inv) {
for (int x = 0; x < inv.getWidth(); x++) {
for (int y = 0; y < inv.getHeight() - 1; y++) {
ItemStack here = inv.getStackInRowAndColumn(x, y);
if (here!=null && here.getItem() == IndustrialWires.panelComponent) {
return new int[]{x, y};
}
}
}
return null;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.crafting;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe;
import javax.annotation.Nonnull;
public class RecipeInitPC extends ShapedOreRecipe {
public RecipeInitPC(ItemStack result, Object... recipe) {
super(result, recipe);
}
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) {
ItemStack ret = super.getCraftingResult(var1);
if (ret.getItem()== IndustrialWires.panelComponent) {
//implicitely initialize the component, relevant for locks with random ID's
ItemPanelComponent.getTagCompound(ret);
}
return ret;
}
@Override
public boolean matches(InventoryCrafting inv, World world) {
return super.matches(inv, world);
}
}

View file

@ -0,0 +1,116 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.crafting;
import blusunrize.immersiveengineering.api.ApiUtils;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.controlpanel.Lock;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
//TODO JEI
public class RecipeKeyLock implements IRecipe {
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
return getLockId(inv) != 0;
}
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack key = getKey(inv);
if (key==null) {
return null;
}
ItemStack ret = new ItemStack(IndustrialWires.key, 1, 1);
ItemKey.setId(ret, getLockId(inv));
return ret;
}
@Override
public int getRecipeSize() {
return 2;
}
@Nonnull
@Override
public ItemStack getRecipeOutput() {
return new ItemStack(IndustrialWires.key, 1, 1);
}
@Nonnull
@Override
public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
ItemStack[] ret = new ItemStack[inv.getSizeInventory()];
for (int i = 0; i < ret.length; i++) {
ItemStack here = inv.getStackInSlot(i);
if (here!=null && here.getItem() == IndustrialWires.panelComponent) {
ret[i] = ApiUtils.copyStackWithAmount(here, 1);
}
}
return ret;
}
private int getLockId(@Nonnull InventoryCrafting inv) {
int id = 0;
boolean hasKey = false;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack here = inv.getStackInSlot(i);
if (here!=null && here.getItem() == IndustrialWires.key && here.getMetadata()==0) {
if (hasKey) {//too many keys
return 0;
}
hasKey = true;
} else if (here != null && here.getItem() == IndustrialWires.panelComponent) {
if (id != 0) {//too many locks/components
return 0;
}
PanelComponent pc = ItemPanelComponent.componentFromStack(here);
if (pc instanceof Lock) {
id = ((Lock) pc).getLockID();
} else {
return 0;
}
}
}
if (!hasKey) {
return 0;
}
return id;
}
@Nullable
//assumes that the recipe is valid
private ItemStack getKey(@Nonnull InventoryCrafting inv) {
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack here = inv.getStackInSlot(i);
if (here!=null && here.getItem() == IndustrialWires.key) {
return here;
}
}
return null;
}
}

View file

@ -0,0 +1,168 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.crafting;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import static malte0811.industrialWires.items.ItemKey.*;
public class RecipeKeyRing implements IRecipe {
private final boolean addToRing;
public RecipeKeyRing(boolean add) {
addToRing = add;
}
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
return isValid(inv);
}
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
if (isValid(inv)) {
if (addToRing) {//add key to ring
ItemStack ring = inv.getStackInSlot(getRingPos(inv)).copy();
NBTTagCompound nbt = ring.getTagCompound();
ItemStack key = inv.getStackInSlot(getKeyPos(inv));
NBTTagCompound keyNBT = key.getTagCompound();
if (nbt == null) {
nbt = new NBTTagCompound();
ring.setTagCompound(nbt);
}
if (!nbt.hasKey(RING_KEYS)) {
nbt.setTag(RING_KEYS, new NBTTagList());
}
if (keyNBT != null) {
NBTTagList keys = nbt.getTagList(RING_KEYS, 10);
if (keys.tagCount() >= IWConfig.maxKeysOnRing) {
return null;
}
keys.appendTag(keyNBT.copy());
nbt.setInteger(LOCK_ID, keyNBT.getInteger(LOCK_ID));
nbt.setString(NAME, keyNBT.getString(NAME));
}
return ring;
} else {//remove key from ring
ItemStack ring = inv.getStackInSlot(getRingPos(inv)).copy();
NBTTagCompound nbt = ring.getTagCompound();
ItemStack key = new ItemStack(IndustrialWires.key, 1, 1);
if (nbt != null) {
NBTTagList keys = nbt.getTagList(RING_KEYS, 10);
if (keys.tagCount() > 0) {
NBTTagCompound first = keys.getCompoundTagAt(keys.tagCount() - 1);
key.setTagCompound(first);
return key;
}
}
}
}
return null;
}
@Override
public int getRecipeSize() {
return 1;
}
@Nonnull
@Override
public ItemStack getRecipeOutput() {
return new ItemStack(IndustrialWires.key, 1, addToRing?2:1);
}
@Nonnull
@Override
public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
ItemStack[] ret = new ItemStack[inv.getSizeInventory()];
if (!addToRing) {
int ringId = getRingPos(inv);
ItemStack ring = inv.getStackInSlot(ringId).copy();
NBTTagCompound nbt = ring.getTagCompound();
if (nbt!=null) {
NBTTagList keys = nbt.getTagList(RING_KEYS, 10);
keys.removeTag(keys.tagCount()-1);
if (keys.tagCount() > 0) {
NBTTagCompound first = keys.getCompoundTagAt(0);
keys.removeTag(0);
keys.appendTag(first);
nbt.setInteger(LOCK_ID, first.getInteger(LOCK_ID));
nbt.setString(NAME, first.getString(NAME));
} else {
nbt.removeTag(LOCK_ID);
nbt.removeTag(NAME);
}
ret[ringId] = ring;
}
}
return ret;
}
private boolean isValid(@Nonnull InventoryCrafting inv) {
boolean hasRing = false;
boolean hasKey = false;
for (int i = 0;i<inv.getSizeInventory();i++) {
ItemStack here = inv.getStackInSlot(i);
if (here!=null&&here.getItem()==IndustrialWires.key) {
if (here.getMetadata()==1 && !hasKey) {//key
hasKey = true;
continue;
} else if (here.getMetadata()==2 && !hasRing) {//ring
hasRing = true;
continue;
}
return false;
} else if (here!=null) {
return false;
}
}
if (addToRing) {
return hasKey&&hasRing;
} else {
return !hasKey&&hasRing;
}
}
private int getRingPos(@Nonnull InventoryCrafting inv) {
for (int i = 0;i<inv.getSizeInventory();i++) {
ItemStack here = inv.getStackInSlot(i);
if (here!=null&&here.getItem()==IndustrialWires.key&&here.getMetadata()==2) {
return i;
}
}
return -1;
}
private int getKeyPos(@Nonnull InventoryCrafting inv) {
for (int i = 0;i<inv.getSizeInventory();i++) {
ItemStack here = inv.getStackInSlot(i);
if (here!=null&&here.getItem()==IndustrialWires.key&&here.getMetadata()==1) {
return i;
}
}
return -1;
}
}

View file

@ -0,0 +1,27 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
public interface INetGUIItem {
void onChange(NBTTagCompound nbt, EntityPlayer p, EnumHand hand);
}

View file

@ -17,11 +17,6 @@
*/
package malte0811.industrialWires.items;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import blusunrize.immersiveengineering.ImmersiveEngineering;
import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.api.TargetingInfo;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
@ -48,10 +43,17 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ItemIC2Coil extends Item implements IWireCoil {
public final static String[] subNames = {"tin", "copper", "gold", "hv", "glass"};
@ -62,10 +64,12 @@ public class ItemIC2Coil extends Item implements IWireCoil{
setHasSubtypes(true);
this.setCreativeTab(IndustrialWires.creativeTab);
setMaxStackSize(64);
ImmersiveEngineering.registerByFullName(this, IndustrialWires.MODID+":"+"ic2WireCoil");
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "ic2WireCoil"));
GameRegistry.register(this);
}
@Override
public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
public void getSubItems(@Nonnull Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
for (int i = 0; i < subNames.length; i++) {
ItemStack tmp = new ItemStack(this, 1, i);
setLength(tmp, getMaxWireLength(tmp));
@ -76,21 +80,27 @@ public class ItemIC2Coil extends Item implements IWireCoil{
public String getUnlocalizedName(ItemStack stack) {
return this.getUnlocalizedName() + "." + subNames[stack.getMetadata()];
}
@Override
public WireType getWireType(ItemStack stack) {
return IC2Wiretype.IC2_TYPES[stack.getMetadata()];
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean adv) {
list.add(I18n.format(IndustrialWires.MODID + ".desc.wireLength", getLength(stack)));
list.add(I18n.format(IndustrialWires.MODID+".desc.recipe"));
int transferRate = IC2Wiretype.IC2_TYPES[stack.getMetadata()].getTransferRate();
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.transfer_rate", transferRate));
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.input_rate", transferRate / 8));
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("linkingPos")) {
int[] link = stack.getTagCompound().getIntArray("linkingPos");
if(link!=null&&link.length>3) {
if (link.length > 3) {
list.add(I18n.format(Lib.DESC_INFO + "attachedToDim", link[1], link[2], link[3], link[0]));
}
}
list.add(I18n.format(IndustrialWires.MODID + ".desc.recipe"));
}
//mostly copied from IE
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
@ -108,7 +118,6 @@ public class ItemIC2Coil extends Item implements IWireCoil{
if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect()) {
return EnumActionResult.PASS;
}
if( !((IImmersiveConnectable)tileEntity).canConnectCable(wire, target)) {
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN+"wrongCable"));
return EnumActionResult.FAIL;
@ -198,18 +207,22 @@ public class ItemIC2Coil extends Item implements IWireCoil{
}
return EnumActionResult.PASS;
}
public static void setLength(ItemStack i, int blocks) {
i.setTagInfo(lengthKey, new NBTTagInt(blocks));
}
public static int getLength(ItemStack i) {
if (i.getTagCompound() == null) {
setLength(i, 4);
}
return i.getTagCompound().getInteger(lengthKey);
}
public static int getMaxWireLength(ItemStack i) {
return IWConfig.maxLengthOnCoil[i.getItemDamage()];
}
public static ItemStack getUninsulatedCable(ItemStack i) {
switch (i.getMetadata()) {
case 0:

View file

@ -0,0 +1,146 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.items;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ItemKey extends Item implements INetGUIItem {
public static final String LOCK_ID = "lockId";
public static final String RING_KEYS = "ringkeys";
public static final String NAME = "name";
public static final String[] types = {"blank_key", "key", "key_ring"};
public ItemKey() {
setUnlocalizedName(IndustrialWires.MODID + ".key");
setHasSubtypes(true);
this.setCreativeTab(IndustrialWires.creativeTab);
setMaxStackSize(64);
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "key"));
GameRegistry.register(this);
}
@Nonnull
@Override
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
NBTTagCompound nbt = stack.getTagCompound();
if (nbt!=null&&nbt.hasKey(NAME)&&!nbt.getString(NAME).trim().isEmpty()) {
return I18n.format("item."+IndustrialWires.MODID+".key.key_named.name")+" "+nbt.getString(NAME);
}
return super.getItemStackDisplayName(stack);
}
@Override
public void getSubItems(@Nonnull Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
subItems.add(new ItemStack(this, 1, 0));
subItems.add(new ItemStack(this, 1, 2));
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (stack.getMetadata()==2&&stack.getTagCompound()!=null) {
NBTTagList keys = stack.getTagCompound().getTagList(RING_KEYS, 10);
for (int i = 0;i< keys.tagCount()-1;i++) {
tooltip.add(I18n.format("item."+IndustrialWires.MODID+".key.key_named.name")+" "+keys.getCompoundTagAt(i).getString(NAME));
}
}
}
@Nonnull
@Override
public String getUnlocalizedName(ItemStack stack) {
return "item."+IndustrialWires.MODID+".key."+types[stack.getMetadata()];
}
public static void setId(ItemStack stack, int lockID) {
stack.setTagInfo(LOCK_ID, new NBTTagInt(lockID));
}
public static int idForKey(@Nullable ItemStack held) {
if (held==null||held.getItem()!=IndustrialWires.key||held.getMetadata()==0) {
return 0;
}
NBTTagCompound nbt = held.getTagCompound();
if (nbt!=null) {
return nbt.getInteger(LOCK_ID);
}
return 0;
}
@Override
public int getItemStackLimit(ItemStack stack) {
return 1;
}
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
ItemStack held = playerIn.getHeldItem(hand);
if (!worldIn.isRemote) {
if (playerIn.isSneaking()&&held.getMetadata()==2) {
//select next key
NBTTagCompound nbt = held.getTagCompound();
if (nbt!=null) {
NBTTagList allKeys = nbt.getTagList(RING_KEYS, 10);
if (allKeys.tagCount()>1) {
NBTTagCompound next = allKeys.getCompoundTagAt(0);
allKeys.removeTag(0);
allKeys.appendTag(next);
nbt.setInteger(LOCK_ID, next.getInteger(LOCK_ID));
nbt.setString(NAME, next.getString(NAME));
playerIn.inventory.markDirty();
}
}
} else if (idForKey(held)!=0&&held.getMetadata()==1) {
playerIn.openGui(IndustrialWires.MODID, 1, worldIn, 0, 0, hand == EnumHand.MAIN_HAND ? 1 : 0);
}
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
@Override
public void onChange(NBTTagCompound nbt, EntityPlayer p, EnumHand hand) {
ItemStack held = p.getHeldItem(hand);
String name = nbt.getString(NAME);
if (!name.trim().isEmpty()) {
held.setTagInfo(NAME, new NBTTagString(name));
} else {
NBTTagCompound heldNBT = held.getTagCompound();
if (heldNBT!=null) {
heldNBT.removeTag(NAME);
}
}
}
}

View file

@ -18,8 +18,10 @@
package malte0811.industrialWires.items;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.client.ClientProxy;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import net.minecraft.client.gui.FontRenderer;
@ -30,6 +32,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
@ -43,10 +46,13 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ItemPanelComponent extends Item {
public class ItemPanelComponent extends Item implements INetGUIItem {
public static final String[] types = {
"lighted_button", "label", "indicator_light", "slider", "variac", "toggle_switch", "toggle_switch_covered"
"lighted_button", "label", "indicator_light", "slider", "variac", "toggle_switch", "toggle_switch_covered", "lock"
};
public static final String TYPE = "type";
public static final String ID = "cfgId";
public static final String VALUE = "value";
public ItemPanelComponent() {
setUnlocalizedName(IndustrialWires.MODID + ".panel_component");
@ -89,7 +95,10 @@ public class ItemPanelComponent extends Item {
}
@Nullable
public static PanelComponent componentFromStack(ItemStack stack) {
public static PanelComponent componentFromStack(@Nullable ItemStack stack) {
if (stack==null||stack.getItem()!=IndustrialWires.panelComponent) {
return null;
}
NBTTagCompound loadFrom = getTagCompound(stack).getCompoundTag("data").copy();
loadFrom.setString("type", types[stack.getMetadata()]);
return PanelComponent.read(loadFrom);
@ -154,4 +163,27 @@ public class ItemPanelComponent extends Item {
}
return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
}
@Override
public void onChange(NBTTagCompound data, EntityPlayer player, EnumHand hand) {
ItemStack held = player.getHeldItem(hand);
if (held!=null && held.getItem() == IndustrialWires.panelComponent) {
PanelComponent old = ItemPanelComponent.componentFromStack(held);
if (old instanceof IConfigurableComponent) {
NBTTagList changes = data.getTagList("data", 10);
IConfigurableComponent cmp = (IConfigurableComponent) old;
for (int i = 0; i < changes.tagCount(); i++) {
NBTTagCompound curr = changes.getCompoundTagAt(i);
IConfigurableComponent.ConfigType type = IConfigurableComponent.ConfigType.values()[curr.getInteger(TYPE)];
try {
cmp.applyConfigOption(type, curr.getInteger(ID), curr.getTag(VALUE));
} catch (Exception x) {
x.printStackTrace();
}
}
ItemStack newCmp = ApiUtils.copyStackWithAmount(ItemPanelComponent.stackFromComponent(old), held.stackSize);
player.setHeldItem(hand, newCmp);
}
}
}
}

View file

@ -46,7 +46,8 @@ public class MessageComponentSync implements IMessage {
this.data = data;
}
public MessageComponentSync() {}
public MessageComponentSync() {
}
@Override
public void fromBytes(ByteBuf buf) {
@ -66,6 +67,7 @@ public class MessageComponentSync implements IMessage {
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(()->handle(message, ctx.getServerHandler().playerEntity));
return null;
}
private void handle(MessageComponentSync msg, EntityPlayerMP player) {
ItemStack held = player.getHeldItem(msg.hand);
if (held!=null&&held.getItem()== IndustrialWires.panelComponent) {

View file

@ -38,7 +38,8 @@ public class MessageGUIInteract implements IMessage {
this.data = data;
}
public MessageGUIInteract() {}
public MessageGUIInteract() {
}
@Override
public void fromBytes(ByteBuf buf) {
@ -60,6 +61,7 @@ public class MessageGUIInteract implements IMessage {
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(()->handle(message, ctx.getServerHandler().playerEntity));
return null;
}
private void handle(MessageGUIInteract msg, EntityPlayerMP player) {
if (player.getDistanceSqToCenter(msg.pos)<100) {//closer than 10 blocks
TileEntity te = player.worldObj.getTileEntity(msg.pos);

View file

@ -0,0 +1,68 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.network;
import io.netty.buffer.ByteBuf;
import malte0811.industrialWires.items.INetGUIItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class MessageItemSync implements IMessage {
private EnumHand hand;
private NBTTagCompound data;
public MessageItemSync(EnumHand h, NBTTagCompound data) {
hand = h;
this.data = data;
}
public MessageItemSync() {
}
@Override
public void fromBytes(ByteBuf buf) {
hand = EnumHand.values()[buf.readInt()];
data = ByteBufUtils.readTag(buf);
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(hand.ordinal());
ByteBufUtils.writeTag(buf, data);
}
public static class HandlerServer implements IMessageHandler<MessageItemSync, IMessage> {
@Override
public IMessage onMessage(MessageItemSync message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().playerEntity;
ItemStack held = player.getHeldItem(message.hand);
if (held!=null && held.getItem() instanceof INetGUIItem) {
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(() ->
((INetGUIItem)held.getItem()).onChange(message.data, player, message.hand));
}
return null;
}
}
}

View file

@ -41,7 +41,8 @@ public class MessagePanelInteract implements IMessage {
hitRelative = hit;
}
public MessagePanelInteract() {}
public MessagePanelInteract() {
}
@Override
public void fromBytes(ByteBuf buf) {
@ -67,6 +68,7 @@ public class MessagePanelInteract implements IMessage {
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(()->handle(message, ctx.getServerHandler().playerEntity));
return null;
}
private void handle(MessagePanelInteract msg, EntityPlayerMP player) {
if (player.getDistanceSqToCenter(msg.pos)<100) {//closer than 10 blocks
TileEntity te = player.worldObj.getTileEntity(msg.pos);

View file

@ -41,7 +41,8 @@ public class MessageTileSyncIW implements IMessage {
this.nbt = nbt;
}
public MessageTileSyncIW() {}
public MessageTileSyncIW() {
}
@Override
public void fromBytes(ByteBuf buf) {

View file

@ -21,7 +21,9 @@ package malte0811.industrialWires.util;
import net.minecraft.util.math.Vec3d;
public final class Beziers {
private Beziers() {}
private Beziers() {
}
public static Vec3d getPoint(double t, Vec3d[] controls) {
if (t == 0) {
return controls[0];
@ -36,9 +38,11 @@ public final class Beziers {
}
return ret;
}
public static int binomialCoeff(int n, int k) {
return factorial(n - k + 1, n) / factorial(2, k);
}
public static int factorial(int start, int end) {
int ret = 1;
for (int i = start; i <= end; i++) {

View file

@ -21,28 +21,37 @@ import blusunrize.immersiveengineering.common.Config;
import malte0811.industrialWires.IWConfig.MechConversion;
public class ConversionUtil {
private ConversionUtil() {}
private ConversionUtil() {
}
public static double rotPerIf() {
return 1 / Config.IEConfig.Machines.dynamo_output;
}
public static double ifPerRot() {
return Config.IEConfig.Machines.dynamo_output;
}
public static double euPerIfIdeal() {
return MechConversion.euPerIf;
}
public static double ifPerEuIdeal() {
return 1 / MechConversion.euPerIf;
}
public static double euPerKin() {
return 1 / euPerKin();
}
public static double kinPerEu() {
return MechConversion.kinPerEu;
}
public static double kinPerRot() {
return kinPerEu() * euPerIfIdeal() * ifPerRot();
}
public static double rotPerKin() {
return 1 / kinPerRot();
}

View file

@ -29,6 +29,7 @@ public class DualEnergyStorage {
public DualEnergyStorage(double maxEU, double maxInEU, double maxOutEU) {
this(0, maxEU, maxInEU, maxOutEU);
}
public DualEnergyStorage(double storedEU, double maxEU, double maxInEU, double maxOutEU) {
this.maxEU = maxEU;
this.maxInEU = maxInEU;
@ -112,6 +113,7 @@ public class DualEnergyStorage {
nbtOuter.setTag(key, nbt);
}
}
public static DualEnergyStorage readFromNBT(NBTTagCompound nbt) {
return new DualEnergyStorage(nbt.getDouble("stored"), nbt.getDouble("maxStored"), nbt.getDouble("maxIn"), nbt.getDouble("maxOut"));
}

View file

@ -22,10 +22,6 @@ import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.BlockPanel;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -37,16 +33,15 @@ import java.util.Set;
import java.util.function.BiPredicate;
public final class MiscUtils {
private MiscUtils() {}
public static Set<ImmersiveNetHandler.Connection> genConnBlockstate(Set<ImmersiveNetHandler.Connection> conns, World world)
{
private MiscUtils() {
}
public static Set<ImmersiveNetHandler.Connection> genConnBlockstate(Set<ImmersiveNetHandler.Connection> conns, World world) {
if (conns == null)
return ImmutableSet.of();
Set<ImmersiveNetHandler.Connection> ret = new HashSet<ImmersiveNetHandler.Connection>()
{
Set<ImmersiveNetHandler.Connection> ret = new HashSet<ImmersiveNetHandler.Connection>() {
@Override
public boolean equals(Object o)
{
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof HashSet))
@ -60,8 +55,7 @@ public final class MiscUtils {
return true;
}
};
for (ImmersiveNetHandler.Connection c : conns)
{
for (ImmersiveNetHandler.Connection c : conns) {
IImmersiveConnectable end = ApiUtils.toIIC(c.end, world, false);
if (end == null)
continue;
@ -72,23 +66,7 @@ public final class MiscUtils {
return ret;
}
public static List<BlockPos> discoverPanelParts(World w, BlockPos here) {
BiPredicate<BlockPos, Integer> isValid = (pos, count)->{
if (here.distanceSq(pos)>25||count>100||!w.isBlockLoaded(pos)) {
return false;
}
IBlockState state = w.getBlockState(pos);
return state.getBlock() == IndustrialWires.panel && state.getValue(BlockPanel.type) != BlockTypes_Panel.CREATOR;
};
List<BlockPos> all = discoverLocal(w, here, isValid);
List<BlockPos> ret = new ArrayList<>();
for (BlockPos pos:all) {
if (w.getBlockState(pos).getValue(BlockPanel.type)!= BlockTypes_Panel.DUMMY) {
ret.add(pos);
}
}
return ret;
}
public static List<BlockPos> discoverLocal(World w, BlockPos here, BiPredicate<BlockPos, Integer> isValid) {
List<BlockPos> ret = new ArrayList<>();
List<BlockPos> open = new ArrayList<>();

View file

@ -0,0 +1,23 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.util;
public interface TriConsumer<A, B, C> {
void accept(A a, B b, C c);
}

View file

@ -36,10 +36,12 @@ public class IC2Wiretype extends WireType{
final double[] lossPerBlock = {.2, .2, .4, .8, .025};
final double[] ic2RenderDiameter = {.03125, .03125, .046875, .0625, .75 * .03125};
public static final IC2Wiretype[] IC2_TYPES = {new IC2Wiretype(0), new IC2Wiretype(1), new IC2Wiretype(2), new IC2Wiretype(3), new IC2Wiretype(4)};
public IC2Wiretype(int ordinal) {
super();
this.type = ordinal;
}
/**
* In this case, this does not return the loss RATIO but the loss PER BLOCK
*/
@ -47,45 +49,55 @@ public class IC2Wiretype extends WireType{
public double getLossRatio() {
return lossPerBlock[type];
}
@Override
public int getTransferRate() {
return ic2Rates[type];
}
@Override
public int getColour(Connection connection) {
return ic2Colors[type];
}
@Override
public double getSlack() {
return type == 2 ? 1.03 : 1.005;
}
@Override
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getIcon(Connection connection) {
return iconDefaultWire;
}
@Override
public int getMaxLength() {
return IWConfig.maxLengthPerConn[type];
}
@Override
public ItemStack getWireCoil(ImmersiveNetHandler.Connection con) {
ItemStack ret = getWireCoil();
ItemIC2Coil.setLength(ret, con.length);
return ret;
}
@Override
public ItemStack getWireCoil() {
return new ItemStack(IndustrialWires.coil, 1, type);
}
@Override
public String getUniqueName() {
return ic2Names[type];
}
@Override
public double getRenderDiameter() {
return ic2RenderDiameter[type];
}
@Override
public boolean isEnergyWire() {
return true;

View file

@ -35,6 +35,11 @@ item.industrialwires.panel_component.slider.name=Slider
item.industrialwires.panel_component.variac.name=Variac®
item.industrialwires.panel_component.toggle_switch.name=Toggle Switch
item.industrialwires.panel_component.toggle_switch_covered.name=Covered Toggle Switch
item.industrialwires.panel_component.lock.name=Lock Switch
item.industrialwires.key.key.name=Key
item.industrialwires.key.key_named.name=Key for
item.industrialwires.key.blank_key.name=Blank Key
item.industrialwires.key.key_ring.name=Key Ring
industrialwires.desc.wireLength=Wire length: %1s block(s)
@ -48,11 +53,13 @@ industrialwires.desc.latching_info=Does this button stay on indefinitely?
industrialwires.desc.latching_info=Does this button stay on indefinitely?
industrialwires.desc.disassemble=Disassemble the panel
industrialwires.desc.rsid_info=The ID of the redstone wire controller to output a signal to
industrialwires.desc.rschannel_info=The color of the redstone channel to output a signal to
industrialwires.desc.label_text=The text in this label
industrialwires.desc.red=Red
industrialwires.desc.green=Green
industrialwires.desc.blue=Blue
industrialwires.desc.length=Length
industrialwires.tooltip.rschannel_info=The color of the channel to output the signal to
industrialwires.tooltip.horizontal=Horizontal
industrialwires.tooltip.vertical=Vertical
@ -61,6 +68,11 @@ industrialwires.tooltip.text=Text: %1s
industrialwires.tooltip.latching=Stays on indefinitely
industrialwires.tooltip.instantaneous=Turns off after half a second
industrialwires.tooltip.length=Length: %1s
industrialwires.tooltip.power_tier=Power Tier: %s
industrialwires.tooltip.eu_per_tick=%s EU/t
industrialwires.tooltip.transfer_rate=Burns at %s EU/t
industrialwires.tooltip.input_rate=%s EU/t per connector
industrialwires.chat.tooLong=This coil does not contain enough wire for this connection
industrialwires.chat.stackSize=Linking is only possible with a stack of size 1
@ -97,7 +109,7 @@ ie.manual.entry.industrialWires.intro.subtext=
ie.manual.entry.industrialWires.intro0=Control Panels allow you to monitor and control a large amount of redstone signals using only a few blocks. Those signals can currently be connected using redstone wires and connectors.<br>Buttons, switches, indicator lights and other things that can be placed on a control panel are called §l(Panel) Components§r<br>To create a control panel you will need a Panel Creator, the individual components and a basic machine casing as the enclosure of the panel. Each
ie.manual.entry.industrialWires.intro1=component is described in the entry "Panel Components". Right-clicking with a panel component opens up a GUI in which the properties of the component, like the redstone channel and ID or the color, can be configured.
ie.manual.entry.industrialWires.intro2=A §l(panel) network§r is formed by panel blocks connected to each other, directly or through other panel blocks. Panel blocks include the control panel itself, the panel connector and the Redstone Wire Controller. If multiple components in one network are configured to modify the same
ie.manual.entry.industrialWires.intro3=redstone signal, the resulting behavior is undefined (but won't crash the game). Having multiple components accepting the same signal on a network is valid though.
ie.manual.entry.industrialWires.intro3=redstone signal, the resulting signal will be the highest of the individual signals. Having multiple components accepting the same signal on a network is valid as well.
ie.manual.entry.industrialWires.panel_creator.name=Panel Creator
ie.manual.entry.industrialWires.panel_creator.subtext=
@ -110,12 +122,15 @@ ie.manual.entry.industrialWires.redstone.subtext=Could also be blood vessels
ie.manual.entry.industrialWires.redstone0=A panel network can contain any amount of §lRedstone Wire Controllers§r. Each controller should be assigned a different ID in its GUI. Each component that interacts with redstone signals has two settings in its GUI: A redstone channel color and a controller ID. To get the redstone signals out of and into the controller it needs to be connected to redstone
ie.manual.entry.industrialWires.redstone1=connectors from Immersive Engineering.
ie.manual.entry.industrialWires.components.name=Panel Components
ie.manual.entry.industrialWires.components.subtext=More than just two
ie.manual.entry.industrialWires.button=A simple button that activates a redstone signal when pressed. Its color can be changed. The button either stays on until clicked again (latching) or tuns off after half a second (non-latching).
ie.manual.entry.industrialWires.label=A text that can be placed on the control panel, for example to indicate the purpose of some other component. The color and obviously the text can be edited.
ie.manual.entry.industrialWires.indicator_light=A small indicator that brightens as the input redstone signal is increased. The color can be changed.
ie.manual.entry.industrialWires.slider=A sliding switch that can set an output redstone signal to any desired signal strength. It can be either vertically or horizontally aligned and can have any length between one eighth of a block and one block. The color of the sliding knob can be changed.
ie.manual.entry.industrialWires.toggle_switch=A switch to turn a signal on or off. The covered version includes a cover to prevent accidental activation: When clicked for the first time the cover will open, the signal will be turned on by clicking once again. Another click will close the cover and turn off the output signal. If the cover was opened by accident it can be closed by shift-right-clicking
ie.manual.entry.industrialWires.toggle_switch1=the switch. The color of the cover can be configured.
ie.manual.entry.industrialWires.variac=A Variac® is a variable autotransformer. The output signal of the transformer increases as the knob is turned to the right. The signal strenght can only be increased by one unit per click.
ie.manual.entry.industrialwires.components.name=Panel Components
ie.manual.entry.industrialwires.components.subtext=More than just two
ie.manual.entry.industrialwires.components.general=The settings of any component can be copied to a component of the same type by placing the components directly above each other in a crafting bench. The settings of the upper component will be copied to the lower.
ie.manual.entry.industrialwires.button=A simple button that activates a redstone signal when pressed. Its color can be changed. The button either stays on until clicked again (latching) or tuns off after half a second (non-latching).
ie.manual.entry.industrialwires.label=A text that can be placed on the control panel, for example to indicate the purpose of some other component. The color and obviously the text can be edited.
ie.manual.entry.industrialwires.indicator_light=A small indicator that brightens as the input redstone signal is increased. The color can be changed.
ie.manual.entry.industrialwires.slider=A sliding switch that can set an output redstone signal to any desired signal strength. It can be either vertically or horizontally aligned and can have any length between one eighth of a block and one block. The color of the sliding knob can be changed.
ie.manual.entry.industrialwires.toggle_switch=A switch to turn a signal on or off. The covered version includes a cover to prevent accidental activation: When clicked for the first time the cover will open, the signal will be turned on by clicking once again. Another click will close the cover and turn off the output signal. If the cover was opened by accident it can be closed by shift-right-clicking
ie.manual.entry.industrialwires.toggle_switch1=the switch. The color of the cover can be configured.
ie.manual.entry.industrialwires.variac=A Variac® is a variable autotransformer. The output signal of the transformer increases as the knob is turned to the right. The signal strenght can only be increased by one unit per click.
ie.manual.entry.industrialwires.lock=A lock switch activates a redstone signal when a key is inserted and turned. A newly crafted lock will have a unique key configuration. By placing a blank key and a lock in a crafting table a key for the lock can be created. Multiple locks fitting the same key can be created using component copying (see page 1). Keys can be named in a GUI opened by right-clicking with them.
ie.manual.entry.industrialwires.lock1=Up to <config;I;iwKeysOnRing> can be combined on a key ring. Keys are added to the ring by placing both in a crafting table. Shift-right-click the key ring to cycle through the keys on the ring. The selected key can be removed from the ring by placing the ring in a crafting table. The key ring will work just as the selected key would on lock switches.

View file

@ -0,0 +1,6 @@
{
"parent":"item/generated",
"textures": {
"layer0":"industrialwires:items/blank_key"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"item/generated",
"textures": {
"layer0":"industrialwires:items/key"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"item/generated",
"textures": {
"layer0":"industrialwires:items/key_ring"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"item/generated",
"textures": {
"layer0":"industrialwires:items/lock_switch"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B