From c4e0a03da82433c25a161de3938787c0f0d1e518 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 7 Jan 2014 20:52:29 +0800 Subject: [PATCH] Removed linker in favor of Calclavia Core's Multitool --- build.gradle | 6 +- .../resonantinduction/ResonantInduction.java | 9 +-- .../transport/ILinkable.java | 19 +++++ .../transport/LinkEvent.java | 81 +++++++++++++++++++ .../transport/levitator/BlockLevitator.java | 55 +++++-------- .../transport/levitator/ItemLinker.java | 36 --------- .../transport/levitator/TileEMLevitator.java | 26 +++++- .../transport/tesla/BlockTesla.java | 45 +---------- .../transport/tesla/TileTesla.java | 39 ++++++++- .../languages/en_US.properties | 2 +- 10 files changed, 191 insertions(+), 127 deletions(-) create mode 100644 src/main/java/resonantinduction/transport/ILinkable.java create mode 100644 src/main/java/resonantinduction/transport/LinkEvent.java delete mode 100644 src/main/java/resonantinduction/transport/levitator/ItemLinker.java diff --git a/build.gradle b/build.gradle index 60d9b7b5..ac123069 100644 --- a/build.gradle +++ b/build.gradle @@ -66,7 +66,7 @@ jar { } repositories { - maven { url 'http://calclavia.com/maven/' } + maven { url 'file://var/www/maven/' } ivy { name 'CB FS' @@ -74,8 +74,8 @@ repositories { } } dependencies { - compile 'universalelectricity:Universal-Electricity:+:dev' - compile 'calclaviacore:calclavia-core:+:dev' + compile 'universalelectricity:Universal-Electricity:3.0.+:dev' + compile 'calclaviacore:calclavia-core:1.1.+:dev' compile name: 'CodeChickenLib', version: "1.6.4-1.0.0.49", ext: 'jar' compile name: 'ForgeMultipart', version: "1.6.4-1.0.0.233", ext: 'jar' } diff --git a/src/main/java/resonantinduction/ResonantInduction.java b/src/main/java/resonantinduction/ResonantInduction.java index fad2f3ad..48055f9d 100644 --- a/src/main/java/resonantinduction/ResonantInduction.java +++ b/src/main/java/resonantinduction/ResonantInduction.java @@ -34,12 +34,12 @@ import resonantinduction.machine.grinder.TileGrinderWheel; import resonantinduction.machine.item.ItemDust; import resonantinduction.machine.liquid.BlockFluidMixture; import resonantinduction.machine.liquid.TileFluidMixture; +import resonantinduction.transport.LinkEvent; import resonantinduction.transport.battery.BlockBattery; import resonantinduction.transport.battery.ItemBlockBattery; import resonantinduction.transport.battery.TileBattery; import resonantinduction.transport.levitator.BlockLevitator; import resonantinduction.transport.levitator.ItemBlockContractor; -import resonantinduction.transport.levitator.ItemLinker; import resonantinduction.transport.levitator.TileEMLevitator; import resonantinduction.transport.tesla.BlockTesla; import resonantinduction.transport.tesla.TileTesla; @@ -154,7 +154,6 @@ public class ResonantInduction /** * Transport */ - public static Item itemLinker; private static Item itemPartWire; public static Item itemMultimeter; public static Item itemTransformer; @@ -199,7 +198,6 @@ public class ResonantInduction TileEMLevitator.PUSH_DELAY = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Push Delay", TileEMLevitator.PUSH_DELAY).getInt(TileEMLevitator.PUSH_DELAY); // Items - itemLinker = new ItemLinker(getNextItemID()); itemPartWire = new ItemWire(getNextItemID()); itemMultimeter = new ItemMultimeter(getNextItemID()); itemTransformer = new ItemTransformer(getNextItemID()); @@ -225,7 +223,6 @@ public class ResonantInduction CONFIGURATION.save(); - GameRegistry.registerItem(itemLinker, itemLinker.getUnlocalizedName()); GameRegistry.registerItem(itemMultimeter, itemMultimeter.getUnlocalizedName()); GameRegistry.registerItem(itemTransformer, itemTransformer.getUnlocalizedName()); GameRegistry.registerItem(itemDust, itemDust.getUnlocalizedName()); @@ -257,6 +254,7 @@ public class ResonantInduction } MinecraftForge.EVENT_BUS.register(itemDust); + MinecraftForge.EVENT_BUS.register(new LinkEvent()); } @EventHandler @@ -287,9 +285,6 @@ public class ResonantInduction */ final ItemStack defaultWire = EnumWireMaterial.IRON.getWire(); - /** Linker **/ - GameRegistry.addRecipe(new ShapedOreRecipe(itemLinker, " E ", "GCG", " E ", 'E', Item.eyeOfEnder, 'C', UniversalRecipe.BATTERY.get(), 'G', UniversalRecipe.SECONDARY_METAL.get())); - /** Tesla - by Jyzarc */ GameRegistry.addRecipe(new ShapedOreRecipe(blockTesla, "WEW", " C ", " I ", 'W', defaultWire, 'E', Item.eyeOfEnder, 'C', UniversalRecipe.BATTERY.get(), 'I', UniversalRecipe.PRIMARY_PLATE.get())); diff --git a/src/main/java/resonantinduction/transport/ILinkable.java b/src/main/java/resonantinduction/transport/ILinkable.java new file mode 100644 index 00000000..45eac1ed --- /dev/null +++ b/src/main/java/resonantinduction/transport/ILinkable.java @@ -0,0 +1,19 @@ +package resonantinduction.transport; + +import net.minecraft.entity.player.EntityPlayer; +import universalelectricity.api.vector.VectorWorld; + +/** + * @author Calclavia + * + */ +public interface ILinkable +{ + /** + * + * @param player + * @param vector + * @return True to clear the link. + */ + public boolean onLink(EntityPlayer player, VectorWorld vector); +} diff --git a/src/main/java/resonantinduction/transport/LinkEvent.java b/src/main/java/resonantinduction/transport/LinkEvent.java new file mode 100644 index 00000000..54691e21 --- /dev/null +++ b/src/main/java/resonantinduction/transport/LinkEvent.java @@ -0,0 +1,81 @@ +/** + * + */ +package resonantinduction.transport; + +import codechicken.multipart.ControlKeyModifer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.event.Event.Result; +import net.minecraftforge.event.ForgeSubscribe; +import universalelectricity.api.vector.VectorWorld; +import calclavia.components.event.MultitoolEvent; + +/** + * @author Calclavia + */ +public class LinkEvent +{ + @ForgeSubscribe + public void linkEvent(MultitoolEvent evt) + { + if (ControlKeyModifer.isControlDown(evt.player)) + { + TileEntity tile = evt.world.getBlockTileEntity(evt.x, evt.y, evt.z); + + if (tile instanceof ILinkable && this.hasLink(evt.toolStack)) + { + if (!evt.world.isRemote) + { + if (((ILinkable) tile).onLink(evt.player, this.getLink(evt.toolStack))) + { + this.clearLink(evt.toolStack); + evt.player.addChatMessage("Link cleared."); + } + } + evt.setResult(Result.DENY); + } + else + { + if (!evt.world.isRemote) + { + evt.player.addChatMessage("Set link to block [" + evt.x + ", " + evt.y + ", " + evt.z + "], Dimension: '" + evt.world.provider.getDimensionName() + "'"); + this.setLink(evt.toolStack, new VectorWorld(evt.world, evt.x, evt.y, evt.z)); + } + } + + evt.setCanceled(true); + } + } + + public boolean hasLink(ItemStack itemStack) + { + return getLink(itemStack) != null; + } + + public VectorWorld getLink(ItemStack itemStack) + { + if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("link")) + { + return null; + } + + return new VectorWorld(itemStack.getTagCompound().getCompoundTag("link")); + } + + public void setLink(ItemStack itemStack, VectorWorld vec) + { + if (itemStack.getTagCompound() == null) + { + itemStack.setTagCompound(new NBTTagCompound()); + } + + itemStack.getTagCompound().setCompoundTag("link", vec.writeToNBT(new NBTTagCompound())); + } + + public void clearLink(ItemStack itemStack) + { + itemStack.getTagCompound().removeTag("link"); + } +} diff --git a/src/main/java/resonantinduction/transport/levitator/BlockLevitator.java b/src/main/java/resonantinduction/transport/levitator/BlockLevitator.java index 2fc475ae..67cbd0ff 100644 --- a/src/main/java/resonantinduction/transport/levitator/BlockLevitator.java +++ b/src/main/java/resonantinduction/transport/levitator/BlockLevitator.java @@ -1,6 +1,5 @@ package resonantinduction.transport.levitator; -import calclavia.lib.prefab.item.ItemCoordLink; import net.minecraft.block.ITileEntityProvider; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -11,7 +10,6 @@ import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.core.base.BlockBase; import resonantinduction.core.render.BlockRenderingHandler; -import universalelectricity.api.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -19,7 +17,7 @@ public class BlockLevitator extends BlockBase implements ITileEntityProvider { public BlockLevitator(int id) { - super("contractor", id); + super("levitator", id); this.setTextureName(ResonantInduction.PREFIX + "machine"); } @@ -31,59 +29,42 @@ public class BlockLevitator extends BlockBase implements ITileEntityProvider } @Override - public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) { - TileEMLevitator contractor = (TileEMLevitator) world.getBlockTileEntity(par2, par3, par4); + TileEMLevitator levitator = (TileEMLevitator) world.getBlockTileEntity(x, y, z); if (entityPlayer.getCurrentEquippedItem() != null) { if (entityPlayer.getCurrentEquippedItem().itemID == Item.dyePowder.itemID) { - contractor.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage()); + levitator.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage()); if (!entityPlayer.capabilities.isCreativeMode) { entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1); } + return true; } - else if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemCoordLink) - { - ItemCoordLink link = ((ItemCoordLink) entityPlayer.getCurrentEquippedItem().getItem()); - Vector3 linkVec = link.getLink(entityPlayer.getCurrentEquippedItem()); - - if (linkVec != null) - { - if (linkVec.getTileEntity(world) instanceof TileEMLevitator) - { - contractor.setLink((TileEMLevitator) linkVec.getTileEntity(world), true); - - if (world.isRemote) - { - entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]"); - } - - link.clearLink(entityPlayer.getCurrentEquippedItem()); - - return true; - } - } - - return false; - } } + levitator.suck = !levitator.suck; + levitator.updatePath(); + + return false; + } + + @Override + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { if (!entityPlayer.isSneaking()) { - contractor.incrementFacing(); - } - else - { - contractor.suck = !contractor.suck; - contractor.updatePath(); + TileEMLevitator levitator = (TileEMLevitator) world.getBlockTileEntity(x, y, z); + levitator.incrementFacing(); + return true; } - return true; + return false; } @Override diff --git a/src/main/java/resonantinduction/transport/levitator/ItemLinker.java b/src/main/java/resonantinduction/transport/levitator/ItemLinker.java deleted file mode 100644 index ad541bd6..00000000 --- a/src/main/java/resonantinduction/transport/levitator/ItemLinker.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - */ -package resonantinduction.transport.levitator; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import resonantinduction.ResonantInduction; -import resonantinduction.TabRI; -import universalelectricity.api.vector.VectorWorld; -import calclavia.lib.prefab.item.ItemCoordLink; - -/** - * @author Calclavia - * - */ -public class ItemLinker extends ItemCoordLink -{ - public ItemLinker(int id) - { - super(id, "linker", ResonantInduction.CONFIGURATION, ResonantInduction.PREFIX, TabRI.INSTANCE); - } - - @Override - public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) - { - if (!world.isRemote) - { - player.addChatMessage("Set link to block [" + x + ", " + y + ", " + z + "], Dimension: '" + world.getWorldInfo().getWorldName() + "'"); - this.setLink(stack, new VectorWorld(world, x, y, z)); - } - - return true; - } -} diff --git a/src/main/java/resonantinduction/transport/levitator/TileEMLevitator.java b/src/main/java/resonantinduction/transport/levitator/TileEMLevitator.java index 6c0015ab..46306269 100644 --- a/src/main/java/resonantinduction/transport/levitator/TileEMLevitator.java +++ b/src/main/java/resonantinduction/transport/levitator/TileEMLevitator.java @@ -22,10 +22,13 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.IFluidBlock; import resonantinduction.ResonantInduction; +import resonantinduction.transport.ILinkable; import resonantinduction.transport.tesla.TileTesla; import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorWorld; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; +import calclavia.lib.prefab.item.ItemCoordLink; import calclavia.lib.prefab.tile.TileAdvanced; import calclavia.lib.utility.InventoryUtility; @@ -36,7 +39,7 @@ import com.google.common.io.ByteArrayDataInput; * @author Calclavia * */ -public class TileEMLevitator extends TileAdvanced implements IPacketReceiver, IPacketSender +public class TileEMLevitator extends TileAdvanced implements IPacketReceiver, IPacketSender, ILinkable { public static int MAX_REACH = 40; public static int PUSH_DELAY = 5; @@ -597,4 +600,25 @@ public class TileEMLevitator extends TileAdvanced implements IPacketReceiver, IP worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } + @Override + public boolean onLink(EntityPlayer player, VectorWorld vector) + { + if (vector != null) + { + if (vector.getTileEntity(this.worldObj) instanceof TileEMLevitator) + { + this.setLink((TileEMLevitator) vector.getTileEntity(this.worldObj), true); + + if (this.worldObj.isRemote) + { + player.addChatMessage("Linked " + this.getBlockType().getLocalizedName() + " with " + " [" + (int) vector.x + ", " + (int) vector.y + ", " + (int) vector.z + "]"); + } + + return true; + } + } + + return false; + } + } diff --git a/src/main/java/resonantinduction/transport/tesla/BlockTesla.java b/src/main/java/resonantinduction/transport/tesla/BlockTesla.java index 44337024..3536e993 100644 --- a/src/main/java/resonantinduction/transport/tesla/BlockTesla.java +++ b/src/main/java/resonantinduction/transport/tesla/BlockTesla.java @@ -12,6 +12,7 @@ import resonantinduction.ResonantInduction; import resonantinduction.Utility; import resonantinduction.core.base.BlockIOBase; import resonantinduction.core.render.BlockRenderingHandler; +import resonantinduction.transport.levitator.TileEMLevitator; import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.VectorWorld; import calclavia.lib.prefab.item.ItemCoordLink; @@ -40,7 +41,7 @@ public class BlockTesla extends BlockIOBase implements ITileEntityProvider } @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { TileEntity t = world.getBlockTileEntity(x, y, z); TileTesla tileEntity = ((TileTesla) t).getControllingTelsa(); @@ -76,45 +77,6 @@ public class BlockTesla extends BlockIOBase implements ITileEntityProvider return true; } - else if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemCoordLink) - { - if (tileEntity.linked == null) - { - ItemCoordLink link = ((ItemCoordLink) entityPlayer.getCurrentEquippedItem().getItem()); - VectorWorld linkVec = link.getLink(entityPlayer.getCurrentEquippedItem()); - - if (linkVec != null) - { - if (!world.isRemote) - { - World otherWorld = linkVec.world; - - if (linkVec.getTileEntity(otherWorld) instanceof TileTesla) - { - tileEntity.setLink(new Vector3(((TileTesla) linkVec.getTileEntity(otherWorld)).getTopTelsa()), linkVec.world.provider.dimensionId, true); - - entityPlayer.addChatMessage(LanguageUtility.getLocal("message.tesla.pair").replace("%v0", this.getLocalizedName()).replace("%v1", linkVec.x + "").replace("%v2", linkVec.y + "").replace("%v3", linkVec.z + "")); - - link.clearLink(entityPlayer.getCurrentEquippedItem()); - world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "ambient.weather.thunder", 5, 1); - - return true; - } - } - } - } - else - { - tileEntity.setLink(null, world.provider.dimensionId, true); - - if (!world.isRemote) - { - entityPlayer.addChatMessage("Unlinked Tesla."); - } - - return true; - } - } } else { @@ -124,11 +86,12 @@ public class BlockTesla extends BlockIOBase implements ITileEntityProvider { entityPlayer.addChatMessage(LanguageUtility.getLocal("message.tesla.mode").replace("%v", receiveMode + "")); } + return true; } - return super.onBlockActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); + return false; } @Override diff --git a/src/main/java/resonantinduction/transport/tesla/TileTesla.java b/src/main/java/resonantinduction/transport/tesla/TileTesla.java index 6a0b5a10..317b5c00 100644 --- a/src/main/java/resonantinduction/transport/tesla/TileTesla.java +++ b/src/main/java/resonantinduction/transport/tesla/TileTesla.java @@ -21,12 +21,15 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.api.ITesla; +import resonantinduction.transport.ILinkable; import universalelectricity.api.energy.EnergyStorageHandler; import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorWorld; import calclavia.lib.CustomDamageSource; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; import calclavia.lib.prefab.tile.TileElectrical; +import calclavia.lib.utility.LanguageUtility; import com.google.common.io.ByteArrayDataInput; @@ -40,7 +43,7 @@ import cpw.mods.fml.common.network.PacketDispatcher; * @author Calclavia * */ -public class TileTesla extends TileElectrical implements ITesla, IPacketSender, IPacketReceiver +public class TileTesla extends TileElectrical implements ITesla, IPacketSender, IPacketReceiver, ILinkable { public final static int DEFAULT_COLOR = 12; public final long TRANSFER_CAP = 10000; @@ -610,4 +613,38 @@ public class TileTesla extends TileElectrical implements ITesla, IPacketSender, } } } + + @Override + public boolean onLink(EntityPlayer player, VectorWorld vector) + { + if (linked == null) + { + if (vector != null) + { + if (!worldObj.isRemote) + { + World otherWorld = vector.world; + + if (vector.getTileEntity(otherWorld) instanceof TileTesla) + { + this.setLink(new Vector3(((TileTesla) vector.getTileEntity(otherWorld)).getTopTelsa()), vector.world.provider.dimensionId, true); + player.addChatMessage(LanguageUtility.getLocal("message.tesla.pair").replace("%v0", this.getBlockType().getLocalizedName()).replace("%v1", vector.x + "").replace("%v2", vector.y + "").replace("%v3", vector.z + "")); + worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, "ambient.weather.thunder", 5, 1); + return true; + } + } + } + } + else + { + this.setLink(null, worldObj.provider.dimensionId, true); + + if (!worldObj.isRemote) + { + player.addChatMessage("Unlinked Tesla."); + } + } + + return false; + } } diff --git a/src/main/resources/assets/resonantinduction/languages/en_US.properties b/src/main/resources/assets/resonantinduction/languages/en_US.properties index bb7ff4d4..b7dec100 100644 --- a/src/main/resources/assets/resonantinduction/languages/en_US.properties +++ b/src/main/resources/assets/resonantinduction/languages/en_US.properties @@ -11,7 +11,7 @@ fluid.mixture=Mixture ## Blocks tile.resonantinduction\:tesla.name=Tesla Coil -tile.resonantinduction\:contractor.name=Electromagnetic Levitator +tile.resonantinduction\:levitator.name=Electromagnetic Levitator tile.resonantinduction\:battery.name=Battery tile.resonantinduction\:machinePart.name=Machine Part tile.resonantinduction\:grindingWheel.name=Grinder Wheel