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) {
return new ContainerPanelComponent(h);
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

@ -20,7 +20,7 @@ package malte0811.industrialWires;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
@Config(modid=IndustrialWires.MODID)
@Config(modid = IndustrialWires.MODID)
public class IWConfig {
@Comment({"The maximum length of a single connection.", "Order: Tin, Copper, Gold, HV, Glass Fiber"})
public static int[] maxLengthPerConn = {16, 16, 16, 32, 32};
@ -29,14 +29,17 @@ 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;
@Comment({"The amount of IC2 kinetic energy that an ideal converter produces from 1 EU"})
public static double kinPerEu = 4;
@Comment({"The maximum amount of IF that can be converted to rotational energy", "by one motor in one tick (default: 100)"})
public static int maxIfToMech = 100;
@Comment({"The efficiency of the IF motor. The default value of 0.9 means that 10% of the energy are lost in the conversion."})
@ -46,16 +49,18 @@ public class IWConfig {
public static double maxRotToKin = 50;
@Comment({"The efficiency of the conversion from IE rotational energy to IC2 kinetic energy"})
public static double rotToKinEfficiency = .7;
@Comment({"The maximum amount of IC2 kinetic energy that can be converted into IE rotational energy", "by one converter in one tick"})
public static int maxKinToRot = 2400;
@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 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,11 +70,12 @@ public class IndustrialWires {
public Item getTabIconItem() {
return null;
}
@Override
public ItemStack getIconItemStack() {
return new ItemStack(coil, 1, 2);
}
};
@SidedProxy(clientSide="malte0811.industrialWires.client.ClientProxy", serverSide="malte0811.industrialWires.CommonProxy")
@SidedProxy(clientSide = "malte0811.industrialWires.client.ClientProxy", serverSide = "malte0811.industrialWires.CommonProxy")
public static CommonProxy proxy;
@EventHandler
@ -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");
@ -115,7 +105,7 @@ public class IndustrialWires {
GameRegistry.registerTileEntity(TileEntityMechICtoIE.class, MODID+":mechIcToIe");
GameRegistry.registerTileEntity(TileEntityMechIEtoIC.class, MODID+":mechIeToIc");
}
if (IC2Wiretype.IC2_TYPES==null) {
if (IC2Wiretype.IC2_TYPES == null) {
throw new IllegalStateException("No IC2 wires registered");
}
proxy.preInit();
@ -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) {
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,19 +52,20 @@ import java.util.Set;
public abstract class BlockIWBase extends Block {
private IProperty[] properties;
public BlockIWBase(Material mat, String name) {
super(mat);
setHardness(3.0F);
setResistance(15.0F);
GameRegistry.register(this, new ResourceLocation(IndustrialWires.MODID, name));
GameRegistry.register(new ItemBlockIW(this), new ResourceLocation(IndustrialWires.MODID, name));
setUnlocalizedName(IndustrialWires.MODID+"."+name);
setUnlocalizedName(IndustrialWires.MODID + "." + name);
setCreativeTab(IndustrialWires.creativeTab);
}
@Override
protected BlockStateContainer createBlockState() {
if (properties==null) {
if (properties == null) {
properties = getProperties();
}
BlockStateContainer cont = super.createBlockState();
@ -82,8 +83,8 @@ public abstract class BlockIWBase extends Block {
if (tile instanceof IHasDummyBlocksIW) {
state = applyProperty(state, IEProperties.MULTIBLOCKSLAVE, ((IHasDummyBlocksIW) tile).isDummy());
}
if (tile instanceof IEBlockInterfaces.IDirectionalTile&&((IEBlockInterfaces.IDirectionalTile) tile).getFacingLimitation()>=0) {
if (((IEBlockInterfaces.IDirectionalTile) tile).getFacingLimitation()==2) {
if (tile instanceof IEBlockInterfaces.IDirectionalTile && ((IEBlockInterfaces.IDirectionalTile) tile).getFacingLimitation() >= 0) {
if (((IEBlockInterfaces.IDirectionalTile) tile).getFacingLimitation() == 2) {
state = state.withProperty(IEProperties.FACING_HORIZONTAL, ((IEBlockInterfaces.IDirectionalTile) tile).getFacing());
} else {
state = state.withProperty(IEProperties.FACING_ALL, ((IEBlockInterfaces.IDirectionalTile) tile).getFacing());
@ -105,7 +106,7 @@ public abstract class BlockIWBase extends Block {
return state;
}
protected <V extends Comparable<V>> IBlockState applyProperty(IBlockState in, IProperty<V> prop, V val) {
protected <V extends Comparable<V>> IBlockState applyProperty(IBlockState in, IProperty<V> prop, V val) {
return in.withProperty(prop, val);
}
@ -115,9 +116,9 @@ public abstract class BlockIWBase extends Block {
if (te instanceof IHasDummyBlocksIW) {
((IHasDummyBlocksIW) te).breakDummies();
}
if(te instanceof IImmersiveConnectable) {
if(!worldIn.isRemote||!Minecraft.getMinecraft().isSingleplayer())
ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(te), worldIn, !worldIn.isRemote&&worldIn.getGameRules().getBoolean("doTileDrops"));
if (te instanceof IImmersiveConnectable) {
if (!worldIn.isRemote || !Minecraft.getMinecraft().isSingleplayer())
ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(te), worldIn, !worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops"));
}
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
@ -142,7 +143,7 @@ public abstract class BlockIWBase extends Block {
TileEntity te = source.getTileEntity(pos);
if (te instanceof IBlockBoundsIW) {
AxisAlignedBB ret = ((IBlockBoundsIW) te).getBoundingBox();
if (ret!=null) {
if (ret != null) {
return ret;
}
}
@ -154,24 +155,24 @@ public abstract class BlockIWBase extends Block {
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof IEBlockInterfaces.IDirectionalTile && Utils.isHammer(heldItem) && !world.isRemote) {
if (te instanceof IEBlockInterfaces.IDirectionalTile && Utils.isHammer(heldItem) && !world.isRemote) {
IEBlockInterfaces.IDirectionalTile directionalTe = (IEBlockInterfaces.IDirectionalTile) te;
if (directionalTe.canHammerRotate(side, hitX, hitY, hitZ, player)) {
EnumFacing f = directionalTe.getFacing();
final EnumFacing original = f;
int limit = directionalTe.getFacingLimitation();
if(limit==0) {
if (limit == 0) {
f = EnumFacing.VALUES[(f.ordinal() + 1) % EnumFacing.VALUES.length];
} else if(limit==1) {
f = player.isSneaking()?f.rotateAround(side.getAxis()).getOpposite():f.rotateAround(side.getAxis());
} else if(limit == 2 || limit == 5) {
f = player.isSneaking()?f.rotateYCCW():f.rotateY();
} else if (limit == 1) {
f = player.isSneaking() ? f.rotateAround(side.getAxis()).getOpposite() : f.rotateAround(side.getAxis());
} else if (limit == 2 || limit == 5) {
f = player.isSneaking() ? f.rotateYCCW() : f.rotateY();
}
if (f!=original) {
if (f != original) {
directionalTe.setFacing(f);
te.markDirty();
world.notifyBlockUpdate(pos,state,state,3);
world.notifyBlockUpdate(pos, state, state, 3);
world.addBlockEvent(pos, this, 255, 0);
}
return true;
@ -187,7 +188,7 @@ public abstract class BlockIWBase extends Block {
@Override
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
boolean def = super.eventReceived(state, worldIn, pos, id, param);
if ((id&255)==255) {
if ((id & 255) == 255) {
IBlockState s = worldIn.getBlockState(pos);
worldIn.notifyBlockUpdate(pos, s, s, 3);
return true;
@ -216,5 +217,6 @@ public abstract class BlockIWBase extends Block {
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
protected abstract IProperty[] getProperties();
}

View File

@ -159,7 +159,7 @@ public class BlockJacobsLadder extends BlockIWBase implements IMetaEnum, IPlacem
@Override
public boolean canPlaceBlockAt(World w, BlockPos pos, ItemStack stack) {
int dummyCount = LadderSize.values()[stack.getMetadata()].dummyCount;
for (int i = 1;i<=dummyCount;i++) {
for (int i = 1; i <= dummyCount; i++) {
if (!w.isAirBlock(pos.up(i))) {
return false;
}

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;
EnumFacing dir;
private IFluxReceiver rec;
private IFluxProvider prov;
private EnumFacing dir;
public EnergyAdapter(IFluxConnection te, EnumFacing f) {
tile = te;
dir = f;
if (te instanceof IFluxReceiver) {
rec = (IFluxReceiver) te;
@ -43,10 +42,10 @@ public class EnergyAdapter implements IEnergyStorage {
prov = (IFluxProvider) te;
}
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
if (rec==null) {
if (rec == null) {
return 0;
} else {
return rec.receiveEnergy(dir, maxReceive, simulate);
@ -55,7 +54,7 @@ public class EnergyAdapter implements IEnergyStorage {
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
if (prov==null) {
if (prov == null) {
return 0;
} else {
return prov.extractEnergy(dir, maxExtract, simulate);
@ -64,9 +63,9 @@ public class EnergyAdapter implements IEnergyStorage {
@Override
public int getEnergyStored() {
if (prov!=null) {
if (prov != null) {
return prov.getEnergyStored(dir);
} else if (rec!=null) {
} else if (rec != null) {
return rec.getEnergyStored(dir);
} else {
return 0;
@ -75,9 +74,9 @@ public class EnergyAdapter implements IEnergyStorage {
@Override
public int getMaxEnergyStored() {
if (prov!=null) {
if (prov != null) {
return prov.getMaxEnergyStored(dir);
} else if (rec!=null) {
} else if (rec != null) {
return rec.getMaxEnergyStored(dir);
} else {
return 0;
@ -86,11 +85,11 @@ public class EnergyAdapter implements IEnergyStorage {
@Override
public boolean canExtract() {
return prov!=null;
return prov != null;
}
@Override
public boolean canReceive() {
return rec!=null;
return rec != null;
}
}

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,12 +28,15 @@ 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) {
values = ((IMetaEnum)b).getValues();
values = ((IMetaEnum) b).getValues();
} else {
values = null;
}
@ -42,19 +45,20 @@ public class ItemBlockIW extends ItemBlock {
@Override
public String getUnlocalizedName(ItemStack stack) {
int meta = stack.getMetadata();
if (values!=null) {
if (values != null) {
return block.getUnlocalizedName() + "." + values[meta].toString().toLowerCase();
} else {
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());
@ -41,18 +42,21 @@ public abstract class TileEntityIWBase extends TileEntity {
writeNBT(compound, false);
return super.writeToNBT(compound);
}
@Override
public void readFromNBT(NBTTagCompound compound) {
readNBT(compound, false);
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

@ -159,7 +159,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
} else if (timeTillActive == 0 && t < 1) {
t += tStep;
if (salt > 0) {
salt -= 1D/(20*20);//20 seconds per item of salt
salt -= 1D / (20 * 20);//20 seconds per item of salt
} else if (salt < 0) {
salt = 0;
}
@ -370,7 +370,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
}
if (!worldObj.isRemote) {
EnumFacing targetDir = facing.rotateAround(EnumFacing.Axis.Y);
for (int i = -dummy;i<size.dummyCount-dummy+1;i++) {
for (int i = -dummy; i < size.dummyCount - dummy + 1; i++) {
BlockPos currPos = pos.up(i);
TileEntity te = world.getTileEntity(currPos);
if (te instanceof TileEntityJacobsLadder) {
@ -378,7 +378,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
teJacobs.facing = targetDir;
teJacobs.markDirty();
IBlockState state = world.getBlockState(currPos).getActualState(world, currPos);
world.notifyBlockUpdate(currPos,state,state,3);
world.notifyBlockUpdate(currPos, state, state, 3);
world.addBlockEvent(currPos, state.getBlock(), 255, 0);
world.notifyBlockOfStateChange(currPos, state.getBlock());
}

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;
@ -56,17 +60,17 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) {
switch (state.getValue(type)) {
case TOP:
return layer==BlockRenderLayer.CUTOUT;
return layer == BlockRenderLayer.CUTOUT;
case RS_WIRE:
return layer==BlockRenderLayer.TRANSLUCENT||layer==BlockRenderLayer.SOLID;
return layer == BlockRenderLayer.TRANSLUCENT || layer == BlockRenderLayer.SOLID;
default:
return super.canRenderInLayer(state, layer);
}
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
switch(state.getValue(type)) {
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
switch (state.getValue(type)) {
case TOP:
return new TileEntityPanel();
case RS_WIRE:
@ -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;
@ -168,7 +176,7 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!super.onBlockActivated(world, pos, state, player, hand, heldItem, side, hitX, hitY, hitZ)&&hand==EnumHand.MAIN_HAND) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityRSPanelConn){
if (te instanceof TileEntityRSPanelConn) {
if (!world.isRemote) {
player.openGui(IndustrialWires.instance, 0, te.getWorld(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
}
@ -182,12 +190,13 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
}
return false;
}
return state.getValue(type)==BlockTypes_Panel.TOP;
return state.getValue(type) == BlockTypes_Panel.TOP;
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
if (state.getValue(type)==BlockTypes_Panel.TOP) {
@Nonnull
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) {
if (state.getValue(type) == BlockTypes_Panel.TOP) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityPanel) {
return ((TileEntityPanel) te).getTileDrop(player, state);
@ -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

@ -22,7 +22,7 @@ import net.minecraft.util.IStringSerializable;
import java.util.Locale;
public enum BlockTypes_Panel implements IStringSerializable {
public enum BlockTypes_Panel implements IStringSerializable {
TOP,
RS_WIRE,
DUMMY,
@ -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";
@ -34,7 +35,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
@Override
public boolean isValid(PanelRenderProperties value) {
return value!=null;
return value != null;
}
@Override
@ -51,26 +52,31 @@ 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("[");
for (int i = 0;i<size();i++) {
for (int i = 0; i < size(); i++) {
ret.append(get(i));
if (i<size()-1) {
if (i < size() - 1) {
ret.append(", ");
}
}
return ret+"]";
return ret + "]";
}
public Matrix4 getPanelTopTransform() {
return getPanelBaseTransform().translate(0, height, 0);
}
public Matrix4 getPanelBaseTransform() {
Matrix4 ret = new Matrix4();
ret.translate(.5, .5, .5);
@ -84,7 +90,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
case SOUTH:
case WEST:
case EAST:
ret.rotate(Math.PI/2, 1, 0, 0);
ret.rotate(Math.PI / 2, 1, 0, 0);
ret.rotate(top.getHorizontalAngle() * Math.PI / 180, 0, 0, 1);
break;
}
@ -94,18 +100,18 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
public float getMaxHeight() {
float ret = 0;
for (PanelComponent pc:this) {
for (PanelComponent pc : this) {
float hHere = pc.getHeight();
if (hHere>ret) {
if (hHere > ret) {
ret = hHere;
}
}
return ret+height;
return ret + height;
}
public PanelRenderProperties copyOf() {
PanelRenderProperties ret = new PanelRenderProperties(size());
for (PanelComponent pc:this) {
for (PanelComponent pc : this) {
ret.add(pc.copyOf());
}
ret.facing = facing;

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;
}
}
}
@ -135,7 +142,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
}
public void readFromItemNBT(@Nullable NBTTagCompound nbt) {
if (nbt!=null) {
if (nbt != null) {
NBTTagList l = nbt.getTagList("components", 10);
PanelUtils.readListFromNBT(l, components);
components.height = nbt.getFloat("height");
@ -233,7 +240,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
Vec3d playerPos = Minecraft.getMinecraft().thePlayer.getPositionVector().addVector(-pos.getX(), player.getEyeHeight() - pos.getY(), -pos.getZ());
for (PanelComponent pc : components) {
AxisAlignedBB box = pc.getBlockRelativeAABB();
if (box.maxY>box.minY) {
if (box.maxY > box.minY) {
box = apply(mat, box.expandXyz(.002));
Vec3d hitVec = hitAbs ? hit.addVector(-pos.getX(), -pos.getY(), -pos.getZ()) : hit;
hitVec = hitVec.scale(2).subtract(playerPos);
@ -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) {
@ -297,22 +302,26 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
@Override
public void onChunkUnload() {
super.onChunkUnload();
for (PanelComponent pc:components) {
for (PanelComponent pc : components) {
pc.invalidate(this);
}
removeAllRSCons();
}
public void removeAllRSCons() {
for (TileEntityRSPanelConn rs : rsPorts) {
rs.unregisterPanel(this, true);
rs.unregisterPanel(this, true, false);
}
rsPorts.clear();
firstTick = true;
}
@Override
public void invalidate() {
super.invalidate();
for (PanelComponent pc:components) {
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;
}
@ -166,7 +141,8 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
worldObj.notifyBlockUpdate(pos, state, state, 3);
}
private static final AxisAlignedBB aabb = new AxisAlignedBB(0, 0,0, 1, 14/16D, 1);
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++) {
for (int i = 0; i < 16; i++) {
oldInput[i] = -1;
}
}
private boolean loaded = false;
@Override
@ -73,8 +76,8 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
loaded = true;
// completely reload the network
network.removeFromNetwork(null);
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
for (BlockPos bp:parts) {
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
for (BlockPos bp : parts) {
TileEntity te = worldObj.getTileEntity(bp);
if (te instanceof TileEntityPanel) {
registerPanel(((TileEntityPanel) te));
@ -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) {
for (PanelComponent pc : p) {
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
if (listener!=null) {
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) {
for (PanelComponent pc : p) {
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
if (listener!=null) {
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);
}
panel.unregisterRS(this);
if (remove) {
connectedPanels.remove(panel);
}
for (TileEntityPanel te : connectedPanels) {
for (PanelComponent pc : te.getComponents()) {
pc.registerRSOutput(id, rsOut);
}
}
network.updateValues();
}
@Override
@ -156,7 +214,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
public void onChange() {
if (!Arrays.equals(oldInput, network.channelValues)) {
oldInput = Arrays.copyOf(network.channelValues, 16);
for (Consumer<byte[]> c:changeListeners) {
for (Consumer<byte[]> c : changeListeners) {
c.accept(oldInput);
}
}
@ -164,7 +222,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
@Override
public void updateInput(byte[] currIn) {
for (int i = 0;i<16;i++) {
for (int i = 0; i < 16; i++) {
currIn[i] = (byte) Math.max(currIn[i], out[i]);
}
}
@ -176,13 +234,13 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
@Override
public boolean canConnectCable(WireType wire, TargetingInfo targetingInfo) {
return wire==WireType.REDSTONE&&!hasConn;
return wire == WireType.REDSTONE && !hasConn;
}
@Override
public void connectCable(WireType wireType, TargetingInfo targetingInfo, IImmersiveConnectable other) {
hasConn = true;
if (other instanceof IRedstoneConnector&&((IRedstoneConnector) other).getNetwork()!=network) {
if (other instanceof IRedstoneConnector && ((IRedstoneConnector) other).getNetwork() != network) {
network.mergeNetwork(((IRedstoneConnector) other).getNetwork());
}
}
@ -224,34 +282,34 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
@Override
public void onChunkUnload() {
super.onChunkUnload();
for (TileEntityPanel panel:connectedPanels) {
unregisterPanel(panel, false);
for (TileEntityPanel panel : connectedPanels) {
unregisterPanel(panel, false, true);
}
}
@Override
public void invalidate() {
super.invalidate();
for (TileEntityPanel panel:connectedPanels) {
unregisterPanel(panel, false);
for (TileEntityPanel panel : connectedPanels) {
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");
out = new byte[16];
for (TileEntityPanel panel:tes) {
for (TileEntityPanel panel : tes) {
registerPanel(panel);
}
network.updateValues();
@ -301,28 +359,29 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
}
private AxisAlignedBB aabb;
@Override
public AxisAlignedBB getBoundingBox() {
if (aabb==null) {
if (aabb == null) {
double h = 9 / 16D;
switch (facing) {
case DOWN:
aabb = new AxisAlignedBB(0, 0, 0, 1, h, 1);
break;
case UP:
aabb = new AxisAlignedBB(0, 1-h, 0, 1, 1, 1);
aabb = new AxisAlignedBB(0, 1 - h, 0, 1, 1, 1);
break;
case NORTH:
aabb = new AxisAlignedBB(0, 0, 0, 1, 1, h);
break;
case SOUTH:
aabb = new AxisAlignedBB(0, 0, 1-h, 1, 1, 1);
aabb = new AxisAlignedBB(0, 0, 1 - h, 1, 1, 1);
break;
case WEST:
aabb = new AxisAlignedBB(0, 0, 0, h, 1, 1);
break;
case EAST:
aabb = new AxisAlignedBB(1-h, 0, 0, 1, 1, 1);
aabb = new AxisAlignedBB(1 - h, 0, 0, 1, 1, 1);
break;
}
}

View File

@ -35,17 +35,19 @@ 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) {
for (int i = 0;i<3;i++) {
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,11 +105,12 @@ 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) {
boolean def = super.eventReceived(state, worldIn, pos, id, param);
if ((id&255)==255) {
if ((id & 255) == 255) {
IBlockState s = worldIn.getBlockState(pos);
worldIn.notifyBlockUpdate(pos, s, s, 3);
return true;

View File

@ -34,13 +34,16 @@ 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();
public final double bufferMax = 2 * MechConversion.maxIfToMech * ConversionUtil.rotPerIf();
private double rotBuffer = 0;
private FluxStorage energy = new FluxStorage(20*MechConversion.maxIfToMech, 2*MechConversion.maxIfToMech);
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) {
@ -49,14 +52,14 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
}
int max = MechConversion.maxIfToMech;
boolean dirty = false;
if (rotBuffer<bufferMax&&energy.extractEnergy(max, true)>0) {
if (rotBuffer < bufferMax && energy.extractEnergy(max, true) > 0) {
int extracted = energy.extractEnergy(max, false);
rotBuffer += extracted*ConversionUtil.rotPerIf()*MechConversion.ifMotorEfficiency;
rotBuffer += extracted * ConversionUtil.rotPerIf() * MechConversion.ifMotorEfficiency;
dirty = true;
}
TileEntity te = worldObj.getTileEntity(receiver);
if (te instanceof IRotationAcceptor) {
((IRotationAcceptor)te).inputRotation(rotBuffer, dir);
((IRotationAcceptor) te).inputRotation(rotBuffer, dir);
rotBuffer = 0;
dirty = true;
}
@ -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());
@ -84,8 +89,9 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
// Flux energy
@Override
public boolean canConnectEnergy(EnumFacing from) {
return from==dir.getOpposite()||from==null;
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,35 +118,42 @@ 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) {
if (capability==CapabilityEnergy.ENERGY&&canConnectEnergy(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) {
if (capability==CapabilityEnergy.ENERGY&&canConnectEnergy(facing)) {
public <T> T getCapability(@Nonnull Capability<T> capability, @Nonnull EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY && canConnectEnergy(facing)) {
return (T) new EnergyAdapter(this, facing);
}
return super.getCapability(capability, facing);

View File

@ -33,32 +33,33 @@ import net.minecraft.util.math.BlockPos;
public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirectionalTile, ITickable {
EnumFacing dir = EnumFacing.DOWN;
int kinBuffer = 0;
private final int kinBufMax = 2*MechConversion.maxKinToRot;
private final double maxInsert = ConversionUtil.rotPerKin()*MechConversion.maxKinToRot;
private final int kinBufMax = 2 * MechConversion.maxKinToRot;
private final double maxInsert = ConversionUtil.rotPerKin() * MechConversion.maxKinToRot;
BlockPos to;
BlockPos from;
@Override
public void update() {
if (!worldObj.isRemote) {
if (to==null) {
to = pos.offset(dir);
}
if (from==null) {
if (from == null) {
from = pos.offset(dir, -1);
}
TileEntity teFrom = worldObj.getTileEntity(from);
if (teFrom instanceof IKineticSource) {
int sourceMax = ((IKineticSource) teFrom).maxrequestkineticenergyTick(dir);
int draw = Math.min(kinBufMax-kinBuffer, sourceMax);
if (draw>0) {
kinBuffer += ((IKineticSource) teFrom).requestkineticenergy(dir, draw)*MechConversion.kinToRotEfficiency;
int draw = Math.min(kinBufMax - kinBuffer, sourceMax);
if (draw > 0) {
kinBuffer += ((IKineticSource) teFrom).requestkineticenergy(dir, draw) * MechConversion.kinToRotEfficiency;
}
}
TileEntity teTo = worldObj.getTileEntity(to);
if (kinBuffer>0&&teTo instanceof IRotationAcceptor) {
double out = Math.min(maxInsert, ConversionUtil.rotPerKin()*kinBuffer);
((IRotationAcceptor) teTo).inputRotation(out, dir);
kinBuffer -= out*ConversionUtil.kinPerRot();
kinBuffer -= out * ConversionUtil.kinPerRot();
}
}
}
@ -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,12 +27,14 @@ 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;
private final double rotBufMax = 2*MechConversion.maxRotToKin;
private final int maxOutput = (int)(ConversionUtil.kinPerRot()*MechConversion.maxRotToKin);
private final double rotBufMax = 2 * MechConversion.maxRotToKin;
private final int maxOutput = (int) (ConversionUtil.kinPerRot() * MechConversion.maxRotToKin);
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
out.setByte(DIR_TAG, (byte) dir.getIndex());
@ -44,32 +46,38 @@ 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) {
if (f==dir) {
if (f == dir) {
return maxOutput;
} else {
return 0;
@ -78,24 +86,25 @@ public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirection
@Override
public int requestkineticenergy(EnumFacing f, int requested) {
if (f==dir) {
int stored = (int) (ConversionUtil.kinPerRot()*rotBuffer);
if (f == dir) {
int stored = (int) (ConversionUtil.kinPerRot() * rotBuffer);
int out = Math.min(maxOutput, stored);
out = Math.min(requested, out);
rotBuffer -= out*ConversionUtil.rotPerKin();
return (int)(out*MechConversion.rotToKinEfficiency);
rotBuffer -= out * ConversionUtil.rotPerKin();
return (int) (out * MechConversion.rotToKinEfficiency);
} else {
return 0;
}
}
//IE rotation
@Override
public void inputRotation(double rotation, EnumFacing side) {
if (side==dir) {
rotBuffer = Math.min(rotBufMax, rotBuffer+rotation);
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);
@ -54,9 +59,9 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileEntityIC2ConnectorTin) {
if (te instanceof TileEntityIC2ConnectorTin) {
TileEntityIC2ConnectorTin connector = (TileEntityIC2ConnectorTin) te;
if(world.isAirBlock(pos.offset(connector.f))) {
if (world.isAirBlock(pos.offset(connector.f))) {
this.dropBlockAsItem(connector.getWorld(), pos, world.getBlockState(pos), 0);
connector.getWorld().setBlockToAir(pos);
}
@ -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));
}
@ -74,8 +79,8 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
protected BlockStateContainer createBlockState() {
BlockStateContainer base = super.createBlockState();
IUnlistedProperty<?>[] unlisted = (base instanceof ExtendedBlockState) ? ((ExtendedBlockState) base).getUnlistedProperties().toArray(new IUnlistedProperty[0]) : new IUnlistedProperty[0];
unlisted = Arrays.copyOf(unlisted, unlisted.length+1);
unlisted[unlisted.length-1] = IEProperties.CONNECTIONS;
unlisted = Arrays.copyOf(unlisted, unlisted.length + 1);
unlisted[unlisted.length - 1] = IEProperties.CONNECTIONS;
return new ExtendedBlockState(this, base.getProperties().toArray(new IProperty[0]), unlisted);
}
@ -135,22 +140,37 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
}
return null;
}
@Override
public boolean canRenderInLayer(BlockRenderLayer layer) {
return layer==BlockRenderLayer.TRANSLUCENT||layer==BlockRenderLayer.SOLID;
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,15 +26,17 @@ public class TileEntityIC2ConnectorCopper extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorCopper() {}
public TileEntityIC2ConnectorCopper() {
}
{
tier = 2;
maxStored = IC2Wiretype.IC2_TYPES[1].getTransferRate()/8;
maxStored = IC2Wiretype.IC2_TYPES[1].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[1];
return t == IC2Wiretype.IC2_TYPES[1];
}
}

View File

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

View File

@ -30,26 +30,29 @@ public class TileEntityIC2ConnectorGold extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorGold() {}
public TileEntityIC2ConnectorGold() {
}
{
tier = 3;
maxStored = IC2Wiretype.IC2_TYPES[2].getTransferRate()/8;
maxStored = IC2Wiretype.IC2_TYPES[2].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[2];
return t == IC2Wiretype.IC2_TYPES[2];
}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
return new Vec3d(.5+side.getFrontOffsetX()*.125, .5+side.getFrontOffsetY()*.125, .5+side.getFrontOffsetZ()*.125);
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();
double conRadius = con.cableType.getRenderDiameter()/2;
return new Vec3d(.5+side.getFrontOffsetX()*(.0625-conRadius), .5+side.getFrontOffsetY()*(.0625-conRadius), .5+side.getFrontOffsetZ()*(.0625-conRadius));
double conRadius = con.cableType.getRenderDiameter() / 2;
return new Vec3d(.5 + side.getFrontOffsetX() * (.0625 - conRadius), .5 + side.getFrontOffsetY() * (.0625 - conRadius), .5 + side.getFrontOffsetZ() * (.0625 - conRadius));
}
}

View File

@ -30,34 +30,37 @@ public class TileEntityIC2ConnectorHV extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorHV() {}
public TileEntityIC2ConnectorHV() {
}
{
tier = 4;
maxStored = IC2Wiretype.IC2_TYPES[3].getTransferRate()/8;
maxStored = IC2Wiretype.IC2_TYPES[3].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[3];
return t == IC2Wiretype.IC2_TYPES[3];
}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
if (relay) {
return new Vec3d(.5+side.getFrontOffsetX()*.4375, .5+side.getFrontOffsetY()*.4375, .5+side.getFrontOffsetZ()*.4375);
return new Vec3d(.5 + side.getFrontOffsetX() * .4375, .5 + side.getFrontOffsetY() * .4375, .5 + side.getFrontOffsetZ() * .4375);
} else {
return new Vec3d(.5+side.getFrontOffsetX()*.3125, .5+side.getFrontOffsetY()*.3125, .5+side.getFrontOffsetZ()*.3125);
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();
double conRadius = con.cableType.getRenderDiameter()/2;
double conRadius = con.cableType.getRenderDiameter() / 2;
if (relay) {
return new Vec3d(.5+side.getFrontOffsetX()*(.375-conRadius), .5+side.getFrontOffsetY()*(.375-conRadius), .5+side.getFrontOffsetZ()*(.375-conRadius));
return new Vec3d(.5 + side.getFrontOffsetX() * (.375 - conRadius), .5 + side.getFrontOffsetY() * (.375 - conRadius), .5 + side.getFrontOffsetZ() * (.375 - conRadius));
} else {
return new Vec3d(.5+side.getFrontOffsetX()*(.25-conRadius), .5+side.getFrontOffsetY()*(.25-conRadius), .5+side.getFrontOffsetZ()*(.25-conRadius));
return new Vec3d(.5 + side.getFrontOffsetX() * (.25 - conRadius), .5 + side.getFrontOffsetY() * (.25 - conRadius), .5 + side.getFrontOffsetZ() * (.25 - conRadius));
}
}
}

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;
@ -62,12 +60,16 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
//IE net to IC2 net buffer
private double outBuffer = 0;
private double maxToMachine = 0;
protected double maxStored = IC2Wiretype.IC2_TYPES[0].getTransferRate()/8;
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,32 +80,33 @@ 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<>();
double outputMax = Math.min(inBuffer, maxToNet);
double sum = 0;
for (AbstractConnection c:conns) {
for (AbstractConnection c : conns) {
IImmersiveConnectable iic = ApiUtils.toIIC(c.end, worldObj);
if (iic instanceof IIC2Connector) {
double tmp = inBuffer-((IIC2Connector)iic).insertEnergy(outputMax, true);
if (tmp>.00000001) {
maxOutputs.put(c, new ImmutablePair<>((IIC2Connector)iic, tmp));
sum+=tmp;
double tmp = inBuffer - ((IIC2Connector) iic).insertEnergy(outputMax, true);
if (tmp > .00000001) {
maxOutputs.put(c, new ImmutablePair<>((IIC2Connector) iic, tmp));
sum += tmp;
}
}
}
if (sum<.0001) {
if (sum < .0001) {
return;
}
final double oldInBuf = outputMax;
HashMap<Connection, Integer> transferedPerConn = ImmersiveNetHandler.INSTANCE.getTransferedRates(worldObj.provider.getDimension());
for (AbstractConnection c:maxOutputs.keySet()) {
Pair<IIC2Connector, Double> p = maxOutputs.get(c);
double out = oldInBuf*p.getRight()/sum;
double out = oldInBuf * p.getRight() / sum;
double loss = getAverageLossRate(c);
double inserted = out-p.getLeft().insertEnergy(out-loss, false);
inBuffer-=inserted;
double inserted = out - p.getLeft().insertEnergy(out - loss, false);
inBuffer -= inserted;
float intermediaryLoss = 0;
HashSet<IImmersiveConnectable> passedConnectors = new HashSet<>();
double energyAtConn = inserted+loss;
@ -121,30 +124,33 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
}
}
public double getAverageLossRate(AbstractConnection conn) {
double f = 0;
for(Connection c : conn.subConnections) {
f += c.length*c.cableType.getLossRatio();
for (Connection c : conn.subConnections) {
f += c.length * c.cableType.getLossRatio();
}
return f;
}
//Input through the net
@Override
public double insertEnergy(double eu, boolean simulate) {
final double insert = Math.min(maxStored-outBuffer, eu);
if (insert>0) {
if (outBuffer<maxToMachine) {
final double insert = Math.min(maxStored - outBuffer, eu);
if (insert > 0) {
if (outBuffer < maxToMachine) {
maxToMachine = outBuffer;
}
if (eu>maxToMachine) {
if (eu > maxToMachine) {
maxToMachine = eu;
}
}
if (!simulate) {
outBuffer+=insert;
outBuffer += insert;
}
return eu-insert;
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();
@ -163,28 +170,33 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
return new Vec3d(.5+side.getFrontOffsetX()*.0625, .5+side.getFrontOffsetY()*.0625, .5+side.getFrontOffsetZ()*.0625);
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());
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);
return (limitType == null || (this.isRelay() && limitType == cableType)) && canConnect(cableType);
}
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[0];
return t == IC2Wiretype.IC2_TYPES[0];
}
@Override
@ -194,18 +206,18 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing side) {
return !relay&&side==f;
return !relay && side == f;
}
@Override
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing side) {
return !relay&&side==f;
return !relay && side == f;
}
@Override
public double getDemandedEnergy() {
double ret = maxStored-inBuffer;
if (ret<.1)
double ret = maxStored + .5 - inBuffer;
if (ret < .1)
ret = 0;
return ret;
}
@ -217,12 +229,12 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
if (inBuffer<maxStored) {
if (inBuffer<maxToNet) {
if (inBuffer < maxStored) {
if (inBuffer < maxToNet) {
maxToNet = inBuffer;
}
inBuffer += amount;
if (amount>maxToNet) {
if (amount > maxToNet) {
maxToNet = amount;
}
markDirty();
@ -304,26 +316,26 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public AxisAlignedBB getBoundingBox() {
float length = this instanceof TileEntityIC2ConnectorHV?(relay?.875f:.75f): this instanceof TileEntityIC2ConnectorGold?.5625f: .5f;
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);
return new AxisAlignedBB(wMin, 0, wMin, wMax, length, wMax);
case DOWN:
return new AxisAlignedBB(wMin,1-length,wMin, wMax,1,wMax);
return new AxisAlignedBB(wMin, 1 - length, wMin, wMax, 1, wMax);
case SOUTH:
return new AxisAlignedBB(wMin,wMin,0, wMax,wMax,length);
return new AxisAlignedBB(wMin, wMin, 0, wMax, wMax, length);
case NORTH:
return new AxisAlignedBB(wMin,wMin,1-length, wMax,wMax,1);
return new AxisAlignedBB(wMin, wMin, 1 - length, wMax, wMax, 1);
case EAST:
return new AxisAlignedBB(0,wMin,wMin, length,wMax,wMax);
return new AxisAlignedBB(0, wMin, wMin, length, wMax, wMax);
case WEST:
return new AxisAlignedBB(1-length,wMin,wMin, 1,wMax,wMax);
return new AxisAlignedBB(1 - length, wMin, wMin, 1, wMax, wMax);
}
return new AxisAlignedBB(0,0,0,1,1,1);
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,15 +348,16 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
ret = 31*ret+pos.hashCode();
return ret;
}
@Override
public boolean equals(Object obj) {
if (obj==this) {
if (obj == this) {
return true;
}
if (!(obj instanceof TileEntityIC2ConnectorTin)) {
return false;
}
if (obj.getClass()!=getClass()) {
if (obj.getClass() != getClass()) {
return false;
}
TileEntityIC2ConnectorTin te = (TileEntityIC2ConnectorTin) obj;
@ -356,6 +369,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
return true;
}
@Override
public boolean canRotate(EnumFacing axis) {
return false;

View File

@ -51,27 +51,27 @@ public class ClientEventHandler {
for(EnumHand hand : EnumHand.values()) {
if(player.getHeldItem(hand)!=null) {
ItemStack equipped = player.getHeldItem(hand);
if(OreDictionary.itemMatches(new ItemStack(IndustrialWires.coil, 1, OreDictionary.WILDCARD_VALUE), equipped, false)) {
if (OreDictionary.itemMatches(new ItemStack(IndustrialWires.coil, 1, OreDictionary.WILDCARD_VALUE), equipped, false)) {
IC2Wiretype type = IC2Wiretype.IC2_TYPES[equipped.getItemDamage()];
int color = type.getColour(null);
String s = I18n.format(IndustrialWires.MODID+".desc.wireLength", ItemIC2Coil.getLength(equipped));
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth()/2 - ClientUtils.font().getStringWidth(s)/2, e.getResolution().getScaledHeight()-GuiIngameForge.left_height-40, color, true);
if(ItemNBTHelper.hasKey(equipped, "linkingPos")) {
String s = I18n.format(IndustrialWires.MODID + ".desc.wireLength", ItemIC2Coil.getLength(equipped));
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, e.getResolution().getScaledHeight() - GuiIngameForge.left_height - 40, color, true);
if (ItemNBTHelper.hasKey(equipped, "linkingPos")) {
int[] link = ItemNBTHelper.getIntArray(equipped, "linkingPos");
if(link!=null&&link.length>3) {
s = I18n.format(Lib.DESC_INFO+"attachedTo", link[1],link[2],link[3]);
if (link != null && link.length > 3) {
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) {
distSquared = focussedBlock.getBlockPos().distanceSq(link[1],link[2],link[3]);
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]);
distSquared = player.getDistanceSq(link[1], link[2], link[3]);
}
int length = Math.min(ItemIC2Coil.getLength(equipped), type.getMaxLength());
if (length*length<distSquared) {
if (length * length < distSquared) {
color = 0xdd3333;
}
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth()/2 - ClientUtils.font().getStringWidth(s)/2, e.getResolution().getScaledHeight()-GuiIngameForge.left_height-20, color, true);
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, e.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, color, true);
}
}
}
@ -94,8 +94,9 @@ public class ClientEventHandler {
}
}
}
@SubscribeEvent
public void bakeModel(ModelBakeEvent event) {
event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID+":control_panel", "inventory,type=top"), new PanelModel());
event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID + ":control_panel", "inventory,type=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) {
@ -182,7 +189,7 @@ public class ClientProxy extends CommonProxy {
}
ClientUtils.mc().getItemColors().registerItemColorHandler((stack, pass) -> {
if (pass==1) {
if (pass == 1) {
PanelComponent pc = ItemPanelComponent.componentFromStack(stack);
if (pc != null) {
return 0xff000000 | pc.getColor();
@ -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())) {
@ -265,14 +277,14 @@ public class ClientProxy extends CommonProxy {
default:
return;
}
PositionedSoundRecord sound = new PositionedSoundRecord(event, SoundCategory.BLOCKS, te.size.soundVolume, 1, false, 0, ISound.AttenuationType.LINEAR, (float)soundPos.xCoord, (float)soundPos.yCoord, (float) soundPos.zCoord);
PositionedSoundRecord sound = new PositionedSoundRecord(event, SoundCategory.BLOCKS, te.size.soundVolume, 1, false, 0, ISound.AttenuationType.LINEAR, (float) soundPos.xCoord, (float) soundPos.yCoord, (float) soundPos.zCoord);
ClientUtils.mc().getSoundHandler().playSound(sound);
playingSounds.put(te.getPos(), sound);
}
@Override
public Gui getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID==0) {
if (ID == 0) {
TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
if (te instanceof TileEntityRSPanelConn) {
return new GuiRSPanelConn((TileEntityRSPanelConn) te);
@ -280,11 +292,15 @@ public class ClientProxy extends CommonProxy {
if (te instanceof TileEntityPanelCreator) {
return new GuiPanelCreator(player.inventory, (TileEntityPanelCreator) te);
}
} else if (ID==1) {
} 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) {
return new GuiPanelComponent(h, ItemPanelComponent.componentFromStack(held));
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,16 +32,24 @@ 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;
vertices[3] = v3;
this.facing = facing;
this.tex = tex;
if (colorA.length==3) {
if (colorA.length == 3) {
this.colorA = Arrays.copyOf(colorA, 4);
this.colorA[3] = 1;
} else {
@ -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;
@ -53,9 +54,9 @@ public class GuiPanelComponent extends GuiContainer {
confComp = (IConfigurableComponent) component;
IConfigurableComponent.BoolConfig[] bools = confComp.getBooleanOptions();
boolButtons.clear();
int componentLeft = this.guiLeft+5;
int componentTop = this.guiTop+5;
for (int i = 0;i<bools.length;i++) {
int componentLeft = this.guiLeft + 5;
int componentTop = this.guiTop + 5;
for (int i = 0; i < bools.length; i++) {
IConfigurableComponent.BoolConfig bc = bools[i];
boolButtons.add(new GuiButtonCheckbox(0, componentLeft + bc.x, componentTop + bc.y, confComp.fomatConfigName(IConfigurableComponent.ConfigType.BOOL, i), bc.value));
}
@ -78,22 +79,23 @@ public class GuiPanelComponent extends GuiContainer {
intChoosers.clear();
IConfigurableComponent.IntConfig[] is = confComp.getIntegerOptions();
for (IConfigurableComponent.IntConfig ic : is) {
intChoosers.add(new GuiIntChooser(componentLeft+ic.x, componentTop+ic.y, ic.allowNegative, ic.value, ic.digits));
intChoosers.add(new GuiIntChooser(componentLeft + ic.x, componentTop + ic.y, ic.allowNegative, ic.value, ic.digits));
}
floatSliders.clear();
IConfigurableComponent.FloatConfig[] fs = confComp.getFloatOptions();
for (int i = 0;i<fs.length;i++) {
for (int i = 0; i < fs.length; i++) {
IConfigurableComponent.FloatConfig fc = fs[i];
floatSliders.add(new GuiSliderIE(0, componentLeft+fc.x, componentTop+fc.y, fc.width,
floatSliders.add(new GuiSliderIE(0, componentLeft + fc.x, componentTop + fc.y, fc.width,
confComp.fomatConfigName(IConfigurableComponent.ConfigType.FLOAT, i), fc.value));
}
}
}
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);
GlStateManager.color(1, 1, 1, 1);
mc.getTextureManager().bindTexture(textureLoc);
Gui.drawModalRectWithCustomSizedTexture(guiLeft, guiTop, 0, 0, xSize, ySize, 150, 150);
}
@ -108,7 +110,7 @@ public class GuiPanelComponent extends GuiContainer {
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
boolean superCall = true;
for (int i = 0;i<stringTexts.size();i++) {
for (int i = 0; i < stringTexts.size(); i++) {
GuiTextField field = stringTexts.get(i);
if (field.isFocused() && keyCode == 28) {
sync(i, field.getText());
@ -125,7 +127,7 @@ public class GuiPanelComponent extends GuiContainer {
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
for (int i = 0;i<rsChannelChoosers.size();i++) {
for (int i = 0; i < rsChannelChoosers.size(); i++) {
GuiChannelPicker picker = rsChannelChoosers.get(i);
int old = picker.getSelected();
boolean stopNow = picker.click(mouseX, mouseY);
@ -136,35 +138,35 @@ public class GuiPanelComponent extends GuiContainer {
return;
}
}
for (int i = 0;i<stringTexts.size();i++) {
for (int i = 0; i < stringTexts.size(); i++) {
GuiTextField field = stringTexts.get(i);
boolean focus = field.isFocused();
field.mouseClicked(mouseX, mouseY, mouseButton);
if (focus&&!field.isFocused()) {
if (focus && !field.isFocused()) {
sync(i, field.getText());
}
}
for (int i = 0;i<boolButtons.size();i++) {
for (int i = 0; i < boolButtons.size(); i++) {
GuiButtonCheckbox box = boolButtons.get(i);
boolean on = box.state;
box.mousePressed(mc, mouseX, mouseY);
if (on!=box.state) {
if (on != box.state) {
sync(i, box.state);
}
}
for (int i = 0;i<intChoosers.size();i++) {
for (int i = 0; i < intChoosers.size(); i++) {
GuiIntChooser chooser = intChoosers.get(i);
int oldV = chooser.getValue();
chooser.click(mouseX, mouseY);
if (oldV!=chooser.getValue()) {
if (oldV != chooser.getValue()) {
sync(i, chooser.getValue());
}
}
for (int i = 0;i<floatSliders.size();i++) {
for (int i = 0; i < floatSliders.size(); i++) {
GuiSliderIE slider = floatSliders.get(i);
double oldV = slider.getValue();
slider.mousePressed(mc, mouseX, mouseY);
if (oldV!=slider.getValue()) {
if (oldV != slider.getValue()) {
sync(i, (float) slider.getValue());
}
}
@ -173,11 +175,11 @@ public class GuiPanelComponent extends GuiContainer {
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
for (int i = 0;i<floatSliders.size();i++) {
for (int i = 0; i < floatSliders.size(); i++) {
GuiSliderIE slider = floatSliders.get(i);
double oldV = slider.getValue();
slider.mouseReleased(mouseX, mouseY);
if (oldV!=slider.getValue()) {
if (oldV != slider.getValue()) {
sync(i, (float) slider.getValue());
}
}
@ -204,21 +206,21 @@ public class GuiPanelComponent extends GuiContainer {
choose.drawButton(mc, mouseX, mouseY);
}
//TOOLTIPS
for (int i = 0;i<rsChannelChoosers.size();i++) {
for (int i = 0; i < rsChannelChoosers.size(); i++) {
GuiChannelPicker pick = rsChannelChoosers.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.RS_CHANNEL, i);
if (tooltip!=null&&pick.isHovered(mouseX, mouseY)) {
if (tooltip != null && pick.isHovered(mouseX, mouseY)) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
}
}
for (int i = 0;i<boolButtons.size();i++) {
for (int i = 0; i < boolButtons.size(); i++) {
GuiButtonCheckbox box = boolButtons.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.BOOL, i);
if (tooltip!=null&&box.isMouseOver()) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
}
}
for (int i = 0;i<stringTexts.size();i++) {
for (int i = 0; i < stringTexts.size(); i++) {
GuiTextField field = stringTexts.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.STRING, i);
if (tooltip!=null&&mouseX>=field.xPosition&&mouseX<field.xPosition+field.width&&
@ -226,14 +228,14 @@ public class GuiPanelComponent extends GuiContainer {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
}
}
for (int i = 0;i<intChoosers.size();i++) {
for (int i = 0; i < intChoosers.size(); i++) {
GuiIntChooser choose = intChoosers.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.INT, i);
if (tooltip!=null&&choose.isMouseOver(mouseX, mouseY)) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
}
}
for (int i = 0;i<floatSliders.size();i++) {
for (int i = 0; i < floatSliders.size(); i++) {
GuiSliderIE choose = floatSliders.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.FLOAT, i);
if (tooltip!=null&&choose.isMouseOver()) {
@ -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++) {
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++) {
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++) {
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++) {
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++) {
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

@ -55,22 +55,22 @@ public class GuiPanelCreator extends GuiContainer {
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1,1,1,1);
GlStateManager.color(1, 1, 1, 1);
mc.getTextureManager().bindTexture(textureLoc);
this.drawTexturedModalRect(guiLeft,guiTop, 0, 0, xSize, ySize);
this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
int x0 = getX0();
int y0 = getY0();
int xRel = mouseX - x0;
int yRel = mouseY - y0;
if (snapToGrid) {
xRel = (int) Math.floor(xRel*16/panelSize)*panelSize/16;
yRel = (int) Math.floor(yRel*16/panelSize)*panelSize/16;
xRel = (int) Math.floor(xRel * 16 / panelSize) * panelSize / 16;
yRel = (int) Math.floor(yRel * 16 / panelSize) * panelSize / 16;
}
for (PanelComponent pc : container.tile.components) {
drawPanelComponent(pc, -1, -1);
}
PanelComponent curr = getFloatingPC();
if (curr!=null && 0 <= xRel && xRel <= panelSize && 0 <= yRel && yRel <= panelSize) {
if (curr != null && 0 <= xRel && xRel <= panelSize && 0 <= yRel && yRel <= panelSize) {
drawPanelComponent(curr, xRel, yRel);
}
}
@ -83,15 +83,15 @@ public class GuiPanelCreator extends GuiContainer {
tooltip = I18n.format(IndustrialWires.MODID+".desc.create_panel");
ClientUtils.drawHoveringText(ImmutableList.of("Create a new panel"), mouseX, mouseY, mc.fontRendererObj);
} else if (buttonList.get(1).isMouseOver()) {
tooltip = I18n.format(IndustrialWires.MODID+".desc.remove_all");
tooltip = I18n.format(IndustrialWires.MODID + ".desc.remove_all");
} else if (buttonList.get(2).isMouseOver()) {
if (snapToGrid) {
tooltip = I18n.format(IndustrialWires.MODID+".desc.disable_snap");
tooltip = I18n.format(IndustrialWires.MODID + ".desc.disable_snap");
} else {
tooltip = I18n.format(IndustrialWires.MODID+".desc.enable_snap");
tooltip = I18n.format(IndustrialWires.MODID + ".desc.enable_snap");
}
} else if (buttonList.get(3).isMouseOver()) {
tooltip = I18n.format(IndustrialWires.MODID+".desc.disassemble");
tooltip = I18n.format(IndustrialWires.MODID + ".desc.disassemble");
}
if (tooltip!=null) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
@ -105,10 +105,10 @@ public class GuiPanelCreator extends GuiContainer {
}
if (!pc.isValidPos(container.tile.components)) {
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
int left = (int) (getX0()+aabb.minX*panelSize)-1;
int top = (int) (getY0()+aabb.minZ*panelSize)-1;
int right = (int) (getX0()+aabb.maxX*panelSize)+1;
int bottom = (int) (getY0()+aabb.maxZ*panelSize)+1;
int left = (int) (getX0() + aabb.minX * panelSize) - 1;
int top = (int) (getY0() + aabb.minZ * panelSize) - 1;
int right = (int) (getX0() + aabb.maxX * panelSize) + 1;
int bottom = (int) (getY0() + aabb.maxZ * panelSize) + 1;
Gui.drawRect(left, top, right, bottom, 0xffff0000);
}
pc.renderInGUI(this);
@ -119,11 +119,11 @@ public class GuiPanelCreator extends GuiContainer {
public void initGui() {
super.initGui();
buttonList.clear();
int buttonTop = guiTop+62;
buttonList.add(new GuiButton(0, guiLeft+2, buttonTop, 20, 20, "C"));
buttonList.add(new GuiButton(1, guiLeft+2, buttonTop+22, 20, 20, "R"));
buttonList.add(new GuiButton(2, guiLeft+2, buttonTop+44, 20, 20, "S"));
buttonList.add(new GuiButton(3, guiLeft+2, buttonTop-54, 20, 20, "D"));
int buttonTop = guiTop + 62;
buttonList.add(new GuiButton(0, guiLeft + 2, buttonTop, 20, 20, "C"));
buttonList.add(new GuiButton(1, guiLeft + 2, buttonTop + 22, 20, 20, "R"));
buttonList.add(new GuiButton(2, guiLeft + 2, buttonTop + 44, 20, 20, "S"));
buttonList.add(new GuiButton(3, guiLeft + 2, buttonTop - 54, 20, 20, "D"));
}
@Override
@ -159,7 +159,7 @@ public class GuiPanelCreator extends GuiContainer {
for (int i = 0;i<components.size();i++) {
PanelComponent pc = components.get(i);
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
if (aabb.minX<=xRelFloat&&aabb.maxX>xRelFloat&&aabb.minZ<=yRelFloat&&aabb.maxZ>yRelFloat) {
if (aabb.minX <= xRelFloat && aabb.maxX > xRelFloat && aabb.minZ <= yRelFloat && aabb.maxZ > yRelFloat) {
PanelComponent removed = components.get(i);
ItemStack remItem = ItemPanelComponent.stackFromComponent(removed);
mc.thePlayer.inventory.setItemStack(remItem);
@ -175,11 +175,11 @@ public class GuiPanelCreator extends GuiContainer {
}
public int getX0() {
return 30+guiLeft;
return 30 + guiLeft;
}
public int getY0() {
return 6+guiTop;
return 6 + guiTop;
}
@Override
@ -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,18 +35,20 @@ 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();
chooser = new GuiIntChooser((width-32)/2, (height-4)/2, false, te.getRsId(), 2);
chooser = new GuiIntChooser((width - 32) / 2, (height - 4) / 2, false, te.getRsId(), 2);
xSize = 64;
ySize = 64;
guiLeft = (width-xSize)/2;
guiTop = (height-ySize)/2;
guiLeft = (width - xSize) / 2;
guiTop = (height - ySize) / 2;
}
@Override
@ -65,9 +67,10 @@ 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);
GlStateManager.color(1, 1, 1, 1);
mc.getTextureManager().bindTexture(textureLoc);
Gui.drawModalRectWithCustomSizedTexture(guiLeft, guiTop, 0, 0, xSize, ySize, 64, 64);
}
@ -84,7 +87,7 @@ public class GuiRSPanelConn extends GuiContainer {
}
private void onChange() {
if (chooser.getValue()!=te.getRsId()) {
if (chooser.getValue() != te.getRsId()) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("rsId", chooser.getValue());
IndustrialWires.packetHandler.sendToServer(new MessageGUIInteract(te, nbt));

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;
@ -21,33 +22,33 @@ public class GuiChannelPicker extends GuiButton {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
mouseX-=xPosition;
mouseY-=yPosition;
mouseX -= xPosition;
mouseY -= yPosition;
currHovered = -1;
for (byte i = 0;i<16;i++) {
int xMin = width/4*(i%4);
int yMin = height/4*(i/4);
int xMax = xMin+width/4;
int yMax = yMin+height/4;
for (byte i = 0; i < 16; i++) {
int xMin = width / 4 * (i % 4);
int yMin = height / 4 * (i / 4);
int xMax = xMin + width / 4;
int yMax = yMin + height / 4;
EnumDyeColor color = EnumDyeColor.byMetadata(i);
int colorVal = color.getMapColor().colorValue|0xff000000;
if (mouseX>=xMin&&mouseX<xMax&&mouseY>=yMin&&mouseY<yMax) {
int colorVal = color.getMapColor().colorValue | 0xff000000;
if (mouseX >= xMin && mouseX < xMax && mouseY >= yMin && mouseY < yMax) {
currHovered = i;
}
if (selected==i) {
drawRect(xMin+xPosition, yMin+yPosition, xMax+xPosition, yMax+yPosition, 0xff000000|~colorVal);
if (selected == i) {
drawRect(xMin + xPosition, yMin + yPosition, xMax + xPosition, yMax + yPosition, 0xff000000 | ~colorVal);
}
if (currHovered==i) {
drawRect(xMin+xPosition, yMin+yPosition, xMax+xPosition, yMax+yPosition, colorVal);
if (currHovered == i) {
drawRect(xMin + xPosition, yMin + yPosition, xMax + xPosition, yMax + yPosition, colorVal);
} else {
final int offset = width/20;
drawRect(xMin+offset+xPosition, yMin+offset+yPosition, xMax-offset+xPosition, yMax-offset+yPosition, colorVal);
final int offset = width / 20;
drawRect(xMin + offset + xPosition, yMin + offset + yPosition, xMax - offset + xPosition, yMax - offset + yPosition, colorVal);
}
}
}
public boolean click(int x, int y) {
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
if (xPosition <= x && xPosition + width >= x && yPosition <= y && yPosition + height >= y) {
select();
return true;
}
@ -55,14 +56,16 @@ public class GuiChannelPicker extends GuiButton {
}
protected void select() {
if (currHovered>=0) {
if (currHovered >= 0) {
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;
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;
@ -45,14 +46,14 @@ public class GuiChannelPickerSmall extends GuiChannelPicker {
} else {
EnumDyeColor color = EnumDyeColor.byMetadata(selected);
int colorVal = color.getMapColor().colorValue | 0xff000000;
drawRect(xPosition, yPosition, xPosition+width, yPosition+height, colorVal);
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, colorVal);
}
}
@Override
public boolean click(int x, int y) {
if (!open) {
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
if (xPosition <= x && xPosition + width >= x && yPosition <= y && yPosition + height >= y) {
open = true;
width = onSize;
height = onSize;
@ -61,7 +62,7 @@ public class GuiChannelPickerSmall extends GuiChannelPicker {
return false;
} else {
boolean ret = false;
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
if (xPosition <= x && xPosition + width >= x && yPosition <= y && yPosition + height >= y) {
select();
ret = true;
}

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,11 +21,12 @@ 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');
if (value>=0&&allowNegative) {
val = "+"+val;
if (value >= 0 && allowNegative) {
val = "+" + val;
}
mc.fontRendererObj.drawStringWithShadow(val, xPos+mc.fontRendererObj.getCharWidth('-')+1, yPos, color);
mc.fontRendererObj.drawStringWithShadow("-", xPos, yPos, color);

View File

@ -49,13 +49,14 @@ 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);
}
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (side!=null) {
if (side != null) {
return ImmutableList.of();
}
if (state instanceof IExtendedBlockState) {
@ -169,6 +170,7 @@ public class PanelModel implements IBakedModel {
.maximumSize(100)
.expireAfterAccess(60, TimeUnit.SECONDS)
.build();
public PanelItemOverride() {
super(ImmutableList.of());
}
@ -178,7 +180,7 @@ public class PanelModel implements IBakedModel {
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) {
if (stack != null && stack.getItem() == PanelUtils.PANEL_ITEM && stack.getMetadata() == BlockTypes_Panel.TOP.ordinal()) {
try {
return ITEM_MODEL_CACHE.get(stack, ()-> {
return ITEM_MODEL_CACHE.get(stack, () -> {
TileEntityPanel te = new TileEntityPanel();
te.readFromItemNBT(stack.getTagCompound());
return new AssembledBakedModel(te.getComponents());

View File

@ -49,7 +49,7 @@ public class PanelModelLoader implements ICustomModelLoader {
@Override
public boolean accepts(ResourceLocation modelLocation) {
return modelLocation.getResourcePath().contains(RESOURCE_BASE+RESOURCE_LOCATION);
return modelLocation.getResourcePath().contains(RESOURCE_BASE + RESOURCE_LOCATION);
}
@Override
@ -57,7 +57,7 @@ public class PanelModelLoader implements ICustomModelLoader {
String resourcePath = modelLocation.getResourcePath();
int pos = resourcePath.indexOf(RESOURCE_LOCATION);
if (pos >= 0) {
return new PanelModelBase();
return new PanelModelBase();
}
return ModelLoaderRegistry.getMissingModel();
}
@ -82,7 +82,7 @@ public class PanelModelLoader implements ICustomModelLoader {
}
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
try {
return new PanelModel();
} catch (Exception e) {

View File

@ -40,7 +40,7 @@ public class RawModelFontRenderer extends FontRenderer {
public RawModelFontRenderer(GameSettings settings, ResourceLocation font, TextureManager manager, boolean isUnicode, float scale) {
super(settings, font, manager, isUnicode);
this.scale = scale/(9*16);
this.scale = scale / (9 * 16);
onResourceManagerReload(null);
}
@ -50,22 +50,23 @@ public class RawModelFontRenderer extends FontRenderer {
float y = (pos / 16);
float w = charWidth[pos] - 1.01f;
float h = FONT_HEIGHT - 1.01f;
float wt = w / 128f*16;
float ht = h / 128f*16;
float wt = w / 128f * 16;
float ht = h / 128f * 16;
float h0 = .01F;
Vector3f v0 = new Vector3f(posX, h0, posY);
v0.scale(scale);
Vector3f v1 = new Vector3f(posX, h0, posY+h);
Vector3f v1 = new Vector3f(posX, h0, posY + h);
v1.scale(scale);
Vector3f v2 = new Vector3f(posX+w, h0, posY+h);
Vector3f v2 = new Vector3f(posX + w, h0, posY + h);
v2.scale(scale);
Vector3f v3 = new Vector3f(posX+w, h0, posY);
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),
new float[]{x, y, x+wt, y+ht}));
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,23 +25,21 @@ 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> {
@Override
public void renderTileEntityAt(TileEntityJacobsLadder tile, double x, double y, double z, float partialTicks, int destroyStage) {
super.renderTileEntityAt(tile, x, y, z, partialTicks, destroyStage);
if (!tile.isDummy()&&tile.timeTillActive==0&&tile.controls[0] != null) {
if (!tile.isDummy() && tile.timeTillActive == 0 && tile.controls[0] != null) {
GlStateManager.pushMatrix();
GlStateManager.translate(x + .5, y + tile.size.heightOffset, z + .5);
GlStateManager.rotate(tile.facing.getHorizontalAngle(), 0, 1, 0);
GlStateManager.translate( - tile.size.bottomDistance / 2, 0, 0);
GlStateManager.translate(-tile.size.bottomDistance / 2, 0, 0);
GlStateManager.disableTexture2D();
GlStateManager.disableLighting();
@ -89,47 +87,50 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
Vec3d radZ = new Vec3d(0, 0, diameter / 2);
Tessellator tes = Tessellator.getInstance();
VertexBuffer vertBuffer = tes.getBuffer();
float[][] colors = new float[steps+1][];
float[][] colors = new float[steps + 1][];
vertBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
Vec3d last = Beziers.getPoint(0, controls);
colors[0] = getColor(0, salt, size);
for (int i = 1;i<=steps;i++) {
double d = i/(double)steps;
for (int i = 1; i <= steps; i++) {
double d = i / (double) steps;
colors[i] = getColor(d, salt, size);
Vec3d pos = Beziers.getPoint(d, controls);
drawQuad(last, pos, radY, colors[i-1], colors[i], vertBuffer);
drawQuad(last, pos, radZ, colors[i-1], colors[i], vertBuffer);
drawQuad(last, pos, radY, colors[i - 1], colors[i], vertBuffer);
drawQuad(last, pos, radZ, colors[i - 1], colors[i], vertBuffer);
last = pos;
}
tes.draw();
}
private final float[] saltColor = {1, 190/255F, 50/255F};
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;
double smallMin = Math.exp(-.5);
double normalMin = Math.exp(-.25*factor);
double hugeMin = Math.exp(-.75*factor);
double normalMin = Math.exp(-.25 * factor);
double hugeMin = Math.exp(-.75 * factor);
double saltyness = 0;
double t2 = t-.5;
double t2 = t - .5;
switch (size) {
case SMALL:
saltyness = salt*(1-.9*(Math.exp(-Math.abs(t2))-smallMin));
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(t2)) - smallMin));
break;
case NORMAL:
saltyness = salt*(1-.9*(Math.exp(-factor*t2*t2)-normalMin));
saltyness = salt * (1 - .9 * (Math.exp(-factor * t2 * t2) - normalMin));
break;
case HUGE:
saltyness = salt*(1-.9*(Math.exp(-Math.abs(factor*t2*t2*t2))-hugeMin));
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(factor * t2 * t2 * t2)) - hugeMin));
break;
}
return interpolate(saltyness, saltColor, 1-saltyness, airColor);
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++) {
ret[i] = (float) (a*cA[i]+b*cB[i]);
for (int i = 0; i < ret.length; i++) {
ret[i] = (float) (a * cA[i] + b * cB[i]);
}
return ret;
}
@ -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,15 +51,175 @@ 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();
}
});
for (int i = 0; i < 3; i++)
for (int j = 0; j < 9; j++)
addSlotToContainer(new Slot(inventoryPlayer, j+i*9+9, slotX+j*18, slotH+i*18));
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, slotX + j * 18, slotH + i * 18));
for (int i = 0; i < 9; i++)
addSlotToContainer(new Slot(inventoryPlayer, i, slotX+i*18, slotH+58));
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) {
return playerIn.getDistanceSq(te.getPos())<64;
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

@ -50,31 +50,29 @@ public class CoveredToggleSwitch extends ToggleSwitch {
Matrix4 rot = null;
if (state.open) {
rot = new Matrix4();
rot.rotate(-Math.PI*.4, 1, 0, 0);
rot.rotate(-Math.PI * .4, 1, 0, 0);
}
PanelUtils.addColoredBox(color, color, null, new Vector3f(0, 0, 0), new Vector3f(sizeX, getHeight(), sizeY), ret,
false, rot, true);
ret.remove(ret.size()-2);//remove front face
ret.remove(ret.size()-1);//remove front face
ret.remove(ret.size() - 2);//remove front face
ret.remove(ret.size() - 1);//remove front face
return ret;
}
@Override
public boolean interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (player.isSneaking()&&state==SwitchState.OPEN) {
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
public void renderInGUI(GuiPanelCreator gui) {
super.renderInGUIDefault(gui, 0xff000000|this.color);
super.renderInGUIDefault(gui, 0xff000000 | this.color);
super.renderInGUI(gui);
}
@ -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);
@ -118,30 +117,30 @@ public class CoveredToggleSwitch extends ToggleSwitch {
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset, color[0], 60),
new FloatConfig("green", x, yOffset+20, color[1], 60),
new FloatConfig("blue", x, yOffset+40, color[2], 60)
new FloatConfig("green", x, yOffset + 20, color[1], 60),
new FloatConfig("blue", x, yOffset + 40, color[2], 60)
};
}
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
super.applyConfigOption(type, id, value);
if (type==ConfigType.FLOAT) {
if (type == ConfigType.FLOAT) {
color = PanelUtils.setColor(color, id, value);
}
}
@Override
public String fomatConfigName(ConfigType type, int id) {
if (type==ConfigType.FLOAT) {
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
if (type == ConfigType.FLOAT) {
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
}
return super.fomatConfigName(type, id);
}
@Override
public String fomatConfigDescription(ConfigType type, int id) {
if (type==ConfigType.FLOAT) {
if (type == ConfigType.FLOAT) {
return null;
}
return super.fomatConfigDescription(type, id);
@ -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,12 +182,14 @@ 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];
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,15 +76,19 @@ 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];
color[3] = 1;
for (int i = 0;i<3;i++) {
color[i] = ((this.colorA>>(8*(2-i)))&255)/255F*(rsInput+15F)/30F;
for (int i = 0; i < 3; i++) {
color[i] = ((this.colorA >> (8 * (2 - i))) & 255) / 255F * (rsInput + 15F) / 30F;
}
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;
}
@ -100,33 +106,34 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb==null) {
aabb = new AxisAlignedBB(x, 0, y, x+size, 0, y+size);
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + size, 0, y + size);
}
return aabb;
}
@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) {
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) {
if (id==rsInputId) {
if (id == rsInputId) {
this.panel = panel;
return handler;
}
@ -167,10 +174,10 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
rsInputChannel = ((NBTTagByte)value).getByte();
rsInputChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsInputId = ((NBTTagInt)value).getInt();
rsInputId = ((NBTTagInt) value).getInt();
break;
case FLOAT:
colorA = PanelUtils.setColor(colorA, id, value);
@ -183,7 +190,7 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
case RS_CHANNEL:
case INT:
default:
@ -198,9 +205,9 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
case FLOAT:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID+".desc.rschannel_info");
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID+".desc.rsid_info");
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
default:
return null;
}
@ -208,14 +215,14 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[] {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsInputChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[] {
return new IntConfig[]{
new IntConfig("rsId", 0, 45, rsInputId, 2, false)
};
}
@ -227,8 +234,8 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset, color[0], 60),
new FloatConfig("green", x, yOffset+20, color[1], 60),
new FloatConfig("blue", x, yOffset+40, color[2], 60)
new FloatConfig("green", x, yOffset + 20, color[1], 60),
new FloatConfig("blue", x, yOffset + 40, color[2], 60)
};
}

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");
}
@ -68,7 +71,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
@Override
public List<RawQuad> getQuads() {
RawModelFontRenderer render = fontRenderer();
render.drawString(text, 0, 0, 0xff000000|color);
render.drawString(text, 0, 0, 0xff000000 | color);
return render.build();
}
@ -86,17 +89,21 @@ public class Label extends PanelComponent implements IConfigurableComponent {
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb == null) {
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);
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
@ -115,17 +122,17 @@ public class Label extends PanelComponent implements IConfigurableComponent {
}
private RawModelFontRenderer fontRenderer() {
if (renderer==null) {
if (renderer == null) {
renderer = new RawModelFontRenderer(Minecraft.getMinecraft().gameSettings, font, Minecraft.getMinecraft().getTextureManager(),
false, 1);
false, 1);
}
return renderer;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
int left = (int) (gui.getX0()+getX()*gui.panelSize);
int top = (int) (gui.getY0()+getY()*gui.panelSize);
int left = (int) (gui.getX0() + getX() * gui.panelSize);
int top = (int) (gui.getY0() + getY() * gui.panelSize);
GlStateManager.pushMatrix();
float scale = gui.mc.fontRendererObj.FONT_HEIGHT*gui.panelSize/(16F*9F*9F);
GlStateManager.translate(left, top, 0);
@ -138,7 +145,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case STRING:
text = ((NBTTagString)value).getString();
text = ((NBTTagString) value).getString();
break;
case FLOAT:
color = PanelUtils.setColor(color, id, value);
@ -151,7 +158,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
default:
return null;
}
@ -162,7 +169,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case STRING:
return I18n.format(IndustrialWires.MODID+".desc.label_text");
return I18n.format(IndustrialWires.MODID + ".desc.label_text");
default:
return null;
}
@ -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);
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;
}
@ -102,74 +107,65 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb==null) {
aabb = new AxisAlignedBB(x, 0, y, x+size, getHeight(), y+size);
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + size, getHeight(), y + size);
}
return aabb;
}
@Override
public boolean interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (!latching&&active) {
return false;
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (!latching && active) {
ticksTillOff = 10;
tile.markDirty();
tile.triggerRenderUpdate();
return;
}
setOut(!active, tile);
if (!latching) {
ticksTillOff = 10;
}
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
@Override
public void update(TileEntityPanel tile) {
if (!latching&&ticksTillOff>0) {
if (!latching && ticksTillOff > 0) {
ticksTillOff--;
tile.markDirty();
if (ticksTillOff==0) {
if (ticksTillOff == 0) {
setOut(false, tile);
}
}
}
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> 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);
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsOutputId) {
super.registerRSOutput(id, out);
out.accept(rsOutputChannel, (byte) (active ? 15 : 0), this);
}
}
@Override
public float getHeight() {
return size/2;
return size / 2;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, 0xff000000|color);
renderInGUIDefault(gui, 0xff000000 | color);
}
@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
@ -197,61 +193,61 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
@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;
case FLOAT:
color = PanelUtils.setColor(color, id, value);
break;
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;
case FLOAT:
color = PanelUtils.setColor(color, id, value);
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;
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
default:
return "INVALID";
case BOOL:
return I18n.format(IndustrialWires.MODID + ".desc.latching");
case RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
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");
case FLOAT:
return null;
default:
return "INVALID?";
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");
case FLOAT:
return null;
default:
return "INVALID?";
}
}
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte)rsOutputChannel)};
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
}
@Override
@ -271,8 +267,8 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset, color[0], 60),
new FloatConfig("green", x, yOffset+20, color[1], 60),
new FloatConfig("blue", x, yOffset+40, color[2], 60)
new FloatConfig("green", x, yOffset + 20, color[1], 60),
new FloatConfig("blue", x, yOffset + 40, color[2], 60)
};
}

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?
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);
@ -160,28 +184,28 @@ public abstract class PanelComponent {
public void renderInGUIDefault(GuiPanelCreator gui, int color) {
color |= 0xff000000;
AxisAlignedBB aabb = getBlockRelativeAABB();
int left = (int) (gui.getX0()+aabb.minX*gui.panelSize);
int top = (int) (gui.getY0()+aabb.minZ*gui.panelSize);
int right = (int) (gui.getX0()+aabb.maxX*gui.panelSize);
int bottom = (int) (gui.getY0()+aabb.maxZ*gui.panelSize);
int left = (int) (gui.getX0() + aabb.minX * gui.panelSize);
int top = (int) (gui.getY0() + aabb.minZ * gui.panelSize);
int right = (int) (gui.getX0() + aabb.maxX * gui.panelSize);
int bottom = (int) (gui.getY0() + aabb.maxZ * gui.panelSize);
Gui.drawRect(left, top, right, bottom, color);
}
public boolean isValidPos(List<PanelComponent> components) {
AxisAlignedBB aabb = getBlockRelativeAABB().offset(0, panelHeight, 0);
if (aabb.minX<0||aabb.maxX>1) {
if (aabb.minX < 0 || aabb.maxX > 1) {
return false;
}
if (aabb.minY<0||aabb.maxY>1) {
if (aabb.minY < 0 || aabb.maxY > 1) {
return false;
}
if (aabb.minZ<0||aabb.maxZ>1) {
if (aabb.minZ < 0 || aabb.maxZ > 1) {
return false;
}
aabb = getBlockRelativeAABB();
for (PanelComponent pc:components) {
if (pc==this) {
for (PanelComponent pc : components) {
if (pc == this) {
continue;
}
AxisAlignedBB otherBB = pc.getBlockRelativeAABB();
@ -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...
@ -185,7 +200,7 @@ public final class PanelUtils {
@SideOnly(Side.CLIENT)
public static void addBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom, float[] uvs, TextureAtlasSprite tex,
@Nullable Matrix4 mat, boolean inside) {
@Nullable Matrix4 mat, boolean inside) {
addQuad(out, new Vector3f(min.x, min.y + size.y, min.z), new Vector3f(min.x, min.y + size.y, min.z + size.z),
new Vector3f(min.x + size.x, min.y + size.y, min.z + size.z), new Vector3f(min.x + size.x, min.y + size.y, min.z),
EnumFacing.UP, colorTop, tex, uvs, mat, inside);
@ -223,7 +238,7 @@ public final class PanelUtils {
Vec3i dirV = dir.getDirectionVec();
RawQuad quad = new RawQuad(v0, v1, v2, v3, dir, tex,
color, new Vector3f(dirV.getX(), dirV.getY(), dirV.getZ()), uvs);
if (mat!=null) {
if (mat != null) {
quad = quad.apply(mat);
}
out.add(quad);
@ -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,20 +332,55 @@ 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) {
base.clear();
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) {
base.add(pc);
if (allNew) {
base.add(pc);
} else {
PanelComponent oldPc = base.get(i);
if (pc.getClass() != oldPc.getClass()) {
base.set(i, pc);
} else {
oldPc.readFromNBT(nbt);
}
}
}
}
}
public static ItemStack getPanelBase() {
if (panelBase==null) {
if (panelBase == null) {
panelBase = IC2Items.getItem("resource", "machine");
}
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);
@ -84,23 +84,26 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
final float yOff = .001F;
float xSize = horizontal?length:WIDTH;
float ySize = horizontal?WIDTH:length;
float xSize = horizontal ? length : WIDTH;
float ySize = horizontal ? WIDTH : length;
PanelUtils.addColoredQuad(ret, new Vector3f(0, yOff, 0), new Vector3f(0, yOff, ySize), new Vector3f(xSize, yOff, ySize), new Vector3f(xSize, yOff, 0),
EnumFacing.UP, GRAY);
float[] color = new float[4];
color[3] = 1;
for (int i = 0;i<3;i++) {
color[i] = ((this.color>>(8*(2-i)))&255)/255F*(.5F+out/30F);
for (int i = 0; i < 3; i++) {
color[i] = ((this.color >> (8 * (2 - i))) & 255) / 255F * (.5F + out / 30F);
}
float val;
if (horizontal) {
val = (out/15F)*(length-.0625F);
val = (out / 15F) * (length - .0625F);
} else {
val = (1-out/15F)*(length-.0625F);
val = (1 - out / 15F) * (length - .0625F);
}
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(horizontal?val:0, 0, horizontal?0:val),
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;
}
@ -118,40 +121,28 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb==null) {
aabb = new AxisAlignedBB(x, 0, y, x+(horizontal?length:WIDTH), getHeight(), y+(horizontal?WIDTH:length));
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + (horizontal ? length : WIDTH), getHeight(), y + (horizontal ? WIDTH : length));
}
return aabb;
}
@Override
public boolean 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);
}
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) {
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) {
if (id==rsId) {
outputs.remove(out);
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsId) {
super.registerRSOutput(id, out);
out.accept((int) rsChannel, this.out, this);
}
}
@ -162,26 +153,24 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public float getHeight() {
return .0625F/2;
return .0625F / 2;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, GRAY_INT);
double middleX = (getX()+(horizontal?length:.0625)/2);
double middleY = (getY()+(horizontal?.0625:length)/2);
int left = gui.getX0()+(int) ((middleX-.0625/2)*gui.panelSize);
int right = gui.getX0()+(int) ((middleX+.0625/2)*gui.panelSize);
int top = gui.getY0()+(int) ((middleY-.0625/2)*gui.panelSize);
int bottom = gui.getY0()+(int) ((middleY+.0625/2)*gui.panelSize);
Gui.drawRect(left, top, right, bottom, 0xff000000|color);
double middleX = (getX() + (horizontal ? length : .0625) / 2);
double middleY = (getY() + (horizontal ? .0625 : length) / 2);
int left = gui.getX0() + (int) ((middleX - .0625 / 2) * gui.panelSize);
int right = gui.getX0() + (int) ((middleX + .0625 / 2) * gui.panelSize);
int top = gui.getY0() + (int) ((middleY - .0625 / 2) * gui.panelSize);
int bottom = gui.getY0() + (int) ((middleY + .0625 / 2) * gui.panelSize);
Gui.drawRect(left, top, right, bottom, 0xff000000 | color);
}
@Override
public void invalidate(TileEntityPanel te) {
for (BiConsumer<Integer, Byte> out:outputs) {
out.accept((int)rsChannel, (byte) 0);
}
setOut(rsChannel, 0);
}
@Override
@ -216,19 +205,19 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case BOOL:
horizontal = ((NBTTagByte)value).getByte()!=0;
horizontal = ((NBTTagByte) value).getByte() != 0;
break;
case RS_CHANNEL:
rsChannel = ((NBTTagByte)value).getByte();
rsChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsId = ((NBTTagInt)value).getInt();
rsId = ((NBTTagInt) value).getInt();
break;
case FLOAT:
if (id<3) {
if (id < 3) {
color = PanelUtils.setColor(color, id, value);
} else {
length = scaleToRangePercent(((NBTTagFloat)value).getFloat(), .125F, 1);
length = scaleToRangePercent(((NBTTagFloat) value).getFloat(), .125F, 1);
}
break;
}
@ -242,12 +231,12 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case BOOL:
return I18n.format(IndustrialWires.MODID+".tooltip.horizontal");
return I18n.format(IndustrialWires.MODID + ".tooltip.horizontal");
case RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":id==2?"blue":"length")));
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : id == 2 ? "blue" : "length")));
default:
return "INVALID";
}
@ -259,9 +248,9 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
case BOOL:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID+".desc.rschannel_info");
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID+".desc.rsid_info");
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
case FLOAT:
return null;
default:
@ -271,21 +260,21 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[] {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[] {
return new IntConfig[]{
new IntConfig("rsId", 0, 50, rsId, 2, false)
};
}
@Override
public BoolConfig[] getBooleanOptions() {
return new BoolConfig[] {
return new BoolConfig[]{
new BoolConfig("horizontal", 0, 70, horizontal)
};
}
@ -296,10 +285,10 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
int x = 70;
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset+20, color[0], 60),
new FloatConfig("green", x, yOffset+40, color[1], 60),
new FloatConfig("blue", x, yOffset+60, color[2], 60),
new FloatConfig("length", x, yOffset, (length-.125F)/(1-.125F), 60)
new FloatConfig("red", x, yOffset + 20, color[0], 60),
new FloatConfig("green", x, yOffset + 40, color[1], 60),
new FloatConfig("blue", x, yOffset + 60, color[2], 60),
new FloatConfig("length", x, yOffset, (length - .125F) / (1 - .125F), 60)
};
}

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,22 +75,24 @@ 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 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<>();
PanelUtils.addColoredQuad(ret, new Vector3f(sizeX, yOffset, (sizeY-sizeX)/2),
new Vector3f(0, yOffset, (sizeY-sizeX)/2),
new Vector3f(0, yOffset, (sizeY+sizeX)/2),
new Vector3f(sizeX, yOffset, (sizeY+sizeX)/2), EnumFacing.UP, GRAY);
PanelUtils.addColoredQuad(ret, new Vector3f(sizeX, yOffset, (sizeY - sizeX) / 2),
new Vector3f(0, yOffset, (sizeY - sizeX) / 2),
new Vector3f(0, yOffset, (sizeY + sizeX) / 2),
new Vector3f(sizeX, yOffset, (sizeY + sizeX) / 2), EnumFacing.UP, GRAY);
Matrix4 rot = new Matrix4();
rot.translate((sizeX)/2, -.01F, sizeY/2);
rot.rotate(Math.PI*1/16*(active?-1:1), 1, 0, 0);
PanelUtils.addColoredBox(GRAY, GRAY, null, new Vector3f(-rodRadius, 0, -rodRadius), new Vector3f(2*rodRadius, rodLength, 2*rodRadius), ret,
rot.translate((sizeX) / 2, -.01F, sizeY / 2);
rot.rotate(Math.PI * 1 / 16 * (active ? -1 : 1), 1, 0, 0);
PanelUtils.addColoredBox(GRAY, GRAY, null, new Vector3f(-rodRadius, 0, -rodRadius), new Vector3f(2 * rodRadius, rodLength, 2 * rodRadius), ret,
false, rot);
return ret;
}
@ -108,18 +110,16 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb==null) {
aabb = new AxisAlignedBB(x, 0, y, x+sizeX, getHeight(), y +sizeY);
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + sizeX, getHeight(), y + sizeY);
}
return aabb;
}
@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,55 +128,45 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
}
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> 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);
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsOutputId) {
super.registerRSOutput(id, out);
out.accept((int) rsOutputChannel, (byte) (active ? 15 : 0), this);
}
}
@Override
public float getHeight() {
return .0625F*3/2;
return .0625F * 3 / 2;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
AxisAlignedBB aabb = getBlockRelativeAABB();
double zOffset = (aabb.maxZ-aabb.minZ-sizeX)/2;
int left = (int) (gui.getX0()+aabb.minX*gui.panelSize);
int top = (int) Math.ceil(gui.getY0()+(aabb.minZ+zOffset)*gui.panelSize);
int right = (int) (gui.getX0()+aabb.maxX*gui.panelSize);
int bottom = (int) Math.floor(gui.getY0()+(aabb.maxZ-zOffset)*gui.panelSize);
double zOffset = (aabb.maxZ - aabb.minZ - sizeX) / 2;
int left = (int) (gui.getX0() + aabb.minX * gui.panelSize);
int top = (int) Math.ceil(gui.getY0() + (aabb.minZ + zOffset) * gui.panelSize);
int right = (int) (gui.getX0() + aabb.maxX * gui.panelSize);
int bottom = (int) Math.floor(gui.getY0() + (aabb.maxZ - zOffset) * gui.panelSize);
Gui.drawRect(left, top, right, bottom, GRAY_INT);
double xOffset = (aabb.maxX-aabb.minX-rodRadius)/2;
left = (int) (gui.getX0()+(aabb.minX+xOffset)*gui.panelSize);
top = (int) Math.floor(gui.getY0()+(aabb.minZ+aabb.maxZ)/2*gui.panelSize);
right = (int) (gui.getX0()+(aabb.maxX-xOffset)*gui.panelSize);
bottom = (int) Math.ceil(gui.getY0()+aabb.maxZ*gui.panelSize);
Gui.drawRect(left, top, right, bottom, GRAY_INT+0x101010);
double xOffset = (aabb.maxX - aabb.minX - rodRadius) / 2;
left = (int) (gui.getX0() + (aabb.minX + xOffset) * gui.panelSize);
top = (int) Math.floor(gui.getY0() + (aabb.minZ + aabb.maxZ) / 2 * gui.panelSize);
right = (int) (gui.getX0() + (aabb.maxX - xOffset) * gui.panelSize);
bottom = (int) Math.ceil(gui.getY0() + aabb.maxZ * gui.panelSize);
Gui.drawRect(left, top, right, bottom, GRAY_INT + 0x101010);
}
@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
@ -204,49 +194,49 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
if (id==0) {
rsOutputChannel = ((NBTTagByte)value).getByte();
}
break;
case INT:
if (id==0) {
rsOutputId = ((NBTTagInt)value).getInt();
}
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 RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
default:
return "INVALID";
case RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
default:
return "INVALID";
}
}
@Override
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID+".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID+".desc.rsid_info");
case FLOAT:
return null;
default:
return "INVALID?";
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
case FLOAT:
return null;
default:
return "INVALID?";
}
}
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte)rsOutputChannel)};
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
}
@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;
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,12 +80,13 @@ public class RecipeCoilLength implements IRecipe {
}
return ret;
}
private int getLength(InventoryCrafting inv) {
int cableLength = 0;
for (int i = 0;i<inv.getSizeInventory();i++) {
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack curr = inv.getStackInSlot(i);
if (OreDictionary.itemMatches(curr, coil, false)) {
cableLength+=ItemIC2Coil.getLength(curr);
cableLength += ItemIC2Coil.getLength(curr);
} else if (OreDictionary.itemMatches(curr, cable, false)) {
cableLength++;
} else if (curr!=null) {

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,12 +43,19 @@ 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;
public class ItemIC2Coil extends Item implements IWireCoil{
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"};
public final static String lengthKey = "wireLength";
@ -62,11 +64,13 @@ 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) {
for (int i = 0;i<subNames.length;i++) {
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));
subItems.add(tmp);
@ -74,23 +78,29 @@ public class ItemIC2Coil extends Item implements IWireCoil{
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return this.getUnlocalizedName()+"."+subNames[stack.getMetadata()];
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"));
if(stack.getTagCompound()!=null && stack.getTagCompound().hasKey("linkingPos")) {
list.add(I18n.format(IndustrialWires.MODID + ".desc.wireLength", getLength(stack)));
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) {
list.add(I18n.format(Lib.DESC_INFO+"attachedToDim", link[1],link[2],link[3],link[0]));
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) {
@ -100,27 +110,26 @@ public class ItemIC2Coil extends Item implements IWireCoil{
return EnumActionResult.FAIL;
}
TileEntity tileEntity = world.getTileEntity(pos);
if(tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable)tileEntity).canConnect()) {
TargetingInfo target = new TargetingInfo(side, hitX,hitY,hitZ);
if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
WireType wire = getWireType(stack);
BlockPos masterPos = ((IImmersiveConnectable)tileEntity).getConnectionMaster(wire, target);
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
tileEntity = world.getTileEntity(masterPos);
if( !(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable)tileEntity).canConnect()) {
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;
}
if(!ItemNBTHelper.hasKey(stack, "linkingPos")) {
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[]{world.provider.getDimension(),masterPos.getX(),masterPos.getY(),masterPos.getZ()});
if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[]{world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ()});
target.writeToNBT(stack.getTagCompound());
} else {
WireType type = getWireType(stack);
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
BlockPos linkPos = new BlockPos(array[1],array[2],array[3]);
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
int distanceSq = (int) Math.ceil( linkPos.distanceSq(masterPos) );
if(array[0]!=world.provider.getDimension()) {
@ -132,13 +141,13 @@ public class ItemIC2Coil extends Item implements IWireCoil{
} else if(!(tileEntityLinkingPos instanceof IImmersiveConnectable)||!((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(type, TargetingInfo.readFromNBT(stack.getTagCompound()))) {
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN+"invalidPoint"));
} else {
IImmersiveConnectable nodeHere = (IImmersiveConnectable)tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable)tileEntityLinkingPos;
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
boolean connectionExists = false;
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
if(outputs!=null) {
for(Connection con : outputs) {
if(con.end.equals(Utils.toCC(nodeLink))) {
if (outputs != null) {
for (Connection con : outputs) {
if (con.end.equals(Utils.toCC(nodeLink))) {
connectionExists = true;
}
}
@ -151,11 +160,11 @@ public class ItemIC2Coil extends Item implements IWireCoil{
Set<BlockPos> ignore = new HashSet<>();
ignore.addAll(nodeHere.getIgnored(nodeLink));
ignore.addAll(nodeLink.getIgnored(nodeHere));
boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore)==null;
if(canSee) {
boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
if (canSee) {
int lengthOnStack = getLength(stack);
int length = (int)Math.sqrt(distanceSq);
if (length<=lengthOnStack) {
int length = (int) Math.sqrt(distanceSq);
if (length <= lengthOnStack) {
TargetingInfo targetLink = TargetingInfo.readFromNBT(stack.getTagCompound());
ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), length, type);
@ -164,21 +173,21 @@ public class ItemIC2Coil extends Item implements IWireCoil{
IESaveData.setDirty(world.provider.getDimension());
player.addStat(IEAchievements.connectWire);
if(!player.capabilities.isCreativeMode) {
if (length<lengthOnStack) {
setLength(stack, lengthOnStack-length);
if (!player.capabilities.isCreativeMode) {
if (length < lengthOnStack) {
setLength(stack, lengthOnStack - length);
} else {
player.setHeldItem(hand, null);
}
}
((TileEntity)nodeHere).markDirty();
((TileEntity) nodeHere).markDirty();
world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
IBlockState state = world.getBlockState(masterPos);
world.notifyBlockUpdate(masterPos, state,state, 3);
((TileEntity)nodeLink).markDirty();
world.notifyBlockUpdate(masterPos, state, state, 3);
((TileEntity) nodeLink).markDirty();
world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
state = world.getBlockState(linkPos);
world.notifyBlockUpdate(linkPos, state,state, 3);
world.notifyBlockUpdate(linkPos, state, state, 3);
} else {
player.addChatMessage(new TextComponentTranslation(IndustrialWires.MODID+".chat.tooLong"));
}
@ -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) {
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);
@ -103,7 +112,7 @@ public class ItemPanelComponent extends Item {
outer.setTag("data", inner);
int meta = getMetaFromPC(inner.getString("type"));
removeIrrelevantTags(inner);
if (meta>=0) {
if (meta >= 0) {
ItemStack ret = new ItemStack(IndustrialWires.panelComponent, 1, meta);
ret.setTagCompound(outer);
return ret;
@ -119,7 +128,7 @@ public class ItemPanelComponent extends Item {
}
private static int getMetaFromPC(String pc) {
for (int i = 0;i<types.length;i++) {
for (int i = 0; i < types.length; i++) {
if (pc.equals(types[i])) {
return i;
}
@ -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,27 +21,31 @@ 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) {
if (t == 0) {
return controls[0];
} else if (t==1) {
return controls[controls.length-1];
} else if (t == 1) {
return controls[controls.length - 1];
}
Vec3d ret = new Vec3d(0, 0, 0);
int n = controls.length-1;
for (int i = 0;i<=n;i++) {
double coeff = binomialCoeff(n, i)*Math.pow(t, i)*Math.pow(1-t, n-i);
ret = ret.addVector(coeff*controls[i].xCoord, coeff*controls[i].yCoord, coeff*controls[i].zCoord);
int n = controls.length - 1;
for (int i = 0; i <= n; i++) {
double coeff = binomialCoeff(n, i) * Math.pow(t, i) * Math.pow(1 - t, n - i);
ret = ret.addVector(coeff * controls[i].xCoord, coeff * controls[i].yCoord, coeff * controls[i].zCoord);
}
return ret;
}
public static int binomialCoeff(int n, int k) {
return factorial(n-k+1, n)/factorial(2, 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++) {
for (int i = start; i <= end; i++) {
ret *= i;
}
return ret;

View File

@ -21,29 +21,38 @@ import blusunrize.immersiveengineering.common.Config;
import malte0811.industrialWires.IWConfig.MechConversion;
public class ConversionUtil {
private ConversionUtil() {}
public static double rotPerIf() {
return 1/Config.IEConfig.Machines.dynamo_output;
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;
return 1 / MechConversion.euPerIf;
}
public static double euPerKin() {
return 1/euPerKin();
return 1 / euPerKin();
}
public static double kinPerEu() {
return MechConversion.kinPerEu;
}
public static double kinPerRot() {
return kinPerEu()*euPerIfIdeal()*ifPerRot();
return kinPerEu() * euPerIfIdeal() * ifPerRot();
}
public static double rotPerKin() {
return 1/kinPerRot();
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;
@ -103,15 +104,16 @@ public class DualEnergyStorage {
}
public void writeToNbt(NBTTagCompound nbtOuter, String key) {
NBTTagCompound nbt = key==null?nbtOuter:new NBTTagCompound();
NBTTagCompound nbt = key == null ? nbtOuter : new NBTTagCompound();
nbt.setDouble("stored", storedEU);
nbt.setDouble("maxStored", maxEU);
nbt.setDouble("maxIn", maxInEU);
nbt.setDouble("maxOut", maxOutEU);
if (key!=null) {
if (key != null) {
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,10 +55,9 @@ 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)
if (end == null)
continue;
// generate subvertices
c.getSubVertices(world);
@ -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<>();
@ -97,9 +75,9 @@ public final class MiscUtils {
BlockPos curr = open.get(0);
ret.add(curr);
open.remove(0);
for (EnumFacing f:EnumFacing.VALUES) {
for (EnumFacing f : EnumFacing.VALUES) {
BlockPos next = curr.offset(f);
if (!open.contains(next)&&!ret.contains(next)&&isValid.test(next, ret.size())) {
if (!open.contains(next) && !ret.contains(next) && isValid.test(next, ret.size())) {
open.add(next);
}
}

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

@ -28,18 +28,20 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class IC2Wiretype extends WireType{
public class IC2Wiretype extends WireType {
final int type;
final int[] ic2Rates = {32*8, 128*8, 512*8, 2048*8, 8192*8};
final int[] ic2Rates = {32 * 8, 128 * 8, 512 * 8, 2048 * 8, 8192 * 8};
final int[] ic2Colors = {0xa5bcc7, 0xbc7945, 0xfeff73, 0xb9d6d9, 0xf1f1f1};
final String[] ic2Names = {"ic2Tin", "ic2Copper", "ic2Gold", "ic2Hv", "ic2Glass"};
final double[] lossPerBlock = {.2, .2, .4, .8, .025};
final double[] ic2RenderDiameter = {.03125, .03125, .046875, .0625, .75*.03125};
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;
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);
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