From 8485dd2e5903b5038074d9d14000e36763bb812f Mon Sep 17 00:00:00 2001 From: tgame14 Date: Thu, 17 Apr 2014 18:01:17 +0300 Subject: [PATCH] added Item for ItemRailing, and registered in Multipart factory including in load phase, EXPERIMENTAL --- .../electrical/Electrical.java | 8 +++ .../electrical/MultipartElectrical.java | 5 +- .../electrical/itemrailing/GridRailing.java | 8 ++- .../itemrailing/ItemItemRailing.java | 60 +++++++++++++++++++ .../electrical/itemrailing/PartRailing.java | 9 ++- 5 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 electrical/src/main/scala/resonantinduction/electrical/itemrailing/ItemItemRailing.java diff --git a/electrical/src/main/scala/resonantinduction/electrical/Electrical.java b/electrical/src/main/scala/resonantinduction/electrical/Electrical.java index 5a8606a1..447c7fe5 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/Electrical.java +++ b/electrical/src/main/scala/resonantinduction/electrical/Electrical.java @@ -21,6 +21,7 @@ import resonantinduction.electrical.generator.TileMotor; import resonantinduction.electrical.generator.solar.TileSolarPanel; import resonantinduction.electrical.generator.thermopile.BlockThermopile; import resonantinduction.electrical.generator.thermopile.TileThermopile; +import resonantinduction.electrical.itemrailing.ItemItemRailing; import resonantinduction.electrical.levitator.ItemLevitator; import resonantinduction.electrical.multimeter.ItemMultimeter; import resonantinduction.electrical.tesla.BlockTesla; @@ -79,6 +80,9 @@ public class Electrical public static Block blockBattery; public static Block blockEncoder; + // Railings + public static Item itemRailing; + // Generators public static Block blockSolarPanel; public static Block blockMotor; @@ -123,6 +127,10 @@ public class Electrical // Quantum itemQuantumGlyph = contentRegistry.createItem(ItemQuantumGlyph.class); + + //Railings + itemRailing = contentRegistry.createItem(ItemItemRailing.class); + Settings.CONFIGURATION.save(); OreDictionary.registerOre("wire", itemWire); diff --git a/electrical/src/main/scala/resonantinduction/electrical/MultipartElectrical.java b/electrical/src/main/scala/resonantinduction/electrical/MultipartElectrical.java index bf771c79..d3385b42 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/MultipartElectrical.java +++ b/electrical/src/main/scala/resonantinduction/electrical/MultipartElectrical.java @@ -1,6 +1,7 @@ package resonantinduction.electrical; import resonantinduction.electrical.charger.PartCharger; +import resonantinduction.electrical.itemrailing.PartRailing; import resonantinduction.electrical.levitator.PartLevitator; import resonantinduction.electrical.multimeter.PartMultimeter; import resonantinduction.electrical.transformer.PartTransformer; @@ -18,7 +19,7 @@ public class MultipartElectrical implements IPartFactory { public static MultipartElectrical INSTANCE; - public static final String[] PART_TYPES = { "resonant_induction_quantum_glyph", "resonant_induction_wire", "resonant_induction_switch_wire", "resonant_induction_flat_wire", "resonant_induction_flat_switch_wire", "resonant_induction_multimeter", "resonant_induction_transformer", "resonant_induction_charger", "resonant_induction_levitator" }; + public static final String[] PART_TYPES = { "resonant_induction_quantum_glyph", "resonant_induction_wire", "resonant_induction_switch_wire", "resonant_induction_flat_wire", "resonant_induction_flat_switch_wire", "resonant_induction_multimeter", "resonant_induction_transformer", "resonant_induction_charger", "resonant_induction_levitator", "resonant_induction_itemrailing" }; public MultipartElectrical() { @@ -51,6 +52,8 @@ public class MultipartElectrical implements IPartFactory return new PartLevitator(); else if (name.equals("resonant_induction_quantum_glyph")) return new PartQuantumGlyph(); + else if (name.equals("resonant_induction_itemrailing")) + return new PartRailing(); return null; } diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java index f223e2c0..6f7215a5 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java @@ -1,6 +1,7 @@ package resonantinduction.electrical.itemrailing; import calclavia.lib.grid.NodeGrid; +import net.minecraft.item.ItemStack; import resonantinduction.electrical.itemrailing.interfaces.IItemRailing; import resonantinduction.electrical.itemrailing.interfaces.IItemRailingTransfer; @@ -40,10 +41,15 @@ public class GridRailing extends NodeGrid return arr[0]; } - public IItemRailing chooseNextGoal(IItemRailingTransfer itemwrapper) + public IItemRailing chooseNextInstantGoal(IItemRailingTransfer itemwrapper) { IItemRailing[] arr = (IItemRailing[]) itemwrapper.getRailing().getConnectionMap().entrySet().toArray(); Arrays.sort(arr, new RailingDistanceComparator(itemwrapper.getEndGoal())); return arr[0]; } + + public void onItemEnterGrid(IItemRailing railing, ItemStack item) + { + + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/ItemItemRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/ItemItemRailing.java new file mode 100644 index 00000000..55eefd34 --- /dev/null +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/ItemItemRailing.java @@ -0,0 +1,60 @@ +package resonantinduction.electrical.itemrailing; + +import codechicken.lib.vec.BlockCoord; +import codechicken.lib.vec.Vector3; +import codechicken.multipart.ControlKeyModifer; +import codechicken.multipart.JItemMultiPart; +import codechicken.multipart.MultiPartRegistry; +import codechicken.multipart.TMultiPart; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; +import resonantinduction.core.MultipartUtility; + +/** + * @author tgame14 + * @since 17/04/14 + */ +public class ItemItemRailing extends JItemMultiPart +{ + public ItemItemRailing(int id) + { + super(id); + } + + @Override + public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 vhit) + { + BlockCoord onPos = pos.copy().offset(side ^ 1); + + if (player.isSneaking() && !ControlKeyModifer.isControlDown(player)) + { + PartRailing railing = (PartRailing) MultiPartRegistry.createPart("resonant_induction_itemrailing", false); + + if (railing != null) + { + railing.preparePlacement(itemStack.getItemDamage()); + } + + return railing; + } + else + { + if (!MultipartUtility.canPlaceWireOnSide(world, onPos.x, onPos.y, onPos.z, ForgeDirection.getOrientation(side), false)) + { + return null; + } + + PartRailing railing = (PartRailing) MultiPartRegistry.createPart("resonant_induction_itemrailing", false); + + if (railing != null) + { + railing.preparePlacement(side); + } + + return railing; + } + } + +} diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java index 418323b2..defe87c3 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java @@ -2,6 +2,7 @@ package resonantinduction.electrical.itemrailing; import calclavia.lib.grid.INode; import calclavia.lib.grid.INodeProvider; +import codechicken.multipart.TileMultipart; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -39,6 +40,7 @@ public class PartRailing extends PartFramedConnection