diff options
author | Prometheus0000 <prometheus0000000@gmail.com> | 2020-12-26 02:58:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-26 02:58:56 -0500 |
commit | 67d69bea466aed1de605e10fda01b84a892a7c9a (patch) | |
tree | f208851b757057fa6979ed67521c36626a4082d4 /src | |
parent | d23b54512350195e8340ef54ef85b526b7be7606 (diff) | |
parent | 7a2db9a02428b7ffa939c8bcc36a7edfe8c4d938 (diff) | |
download | GT5-Unofficial-67d69bea466aed1de605e10fda01b84a892a7c9a.tar.gz GT5-Unofficial-67d69bea466aed1de605e10fda01b84a892a7c9a.tar.bz2 GT5-Unofficial-67d69bea466aed1de605e10fda01b84a892a7c9a.zip |
Merge pull request #4 from Technus/master
update
Diffstat (limited to 'src')
25 files changed, 1163 insertions, 239 deletions
diff --git a/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java b/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java index df5c11e67b..2609a81860 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java +++ b/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java @@ -933,6 +933,8 @@ public class DreamCraftRecipeLoader implements Runnable { 48000, 64, 200000, 8, new Object[]{ GT_OreDictUnificator.get(OrePrefixes.frameGt, Materials.CosmicNeutronium, 1L), GT_OreDictUnificator.get(OrePrefixes.plate, Materials.CosmicNeutronium, 6L), + ItemList.Gravistar.get(4L), + ItemList.Emitter_UHV.get(4L), new Object[]{OrePrefixes.circuit.get(Materials.Bio), 4L}, GT_OreDictUnificator.get(OrePrefixes.wireFine, Materials.Neutronium, 64L), GT_OreDictUnificator.get(OrePrefixes.wireFine, Materials.Neutronium, 64L), @@ -952,7 +954,9 @@ public class DreamCraftRecipeLoader implements Runnable { 96000, 128, 400000, 16, new Object[]{ GT_OreDictUnificator.get(OrePrefixes.frameGt, Materials.Infinity, 1L), GT_OreDictUnificator.get(OrePrefixes.plate, Materials.Infinity, 6L), - new Object[]{OrePrefixes.circuit.get(Materials.Bio), 8L}, + ItemList.Gravistar.get(8L), + ItemList.Emitter_UEV.get(4L), + new Object[]{OrePrefixes.circuit.get(Materials.Nano), 4}, GT_OreDictUnificator.get(OrePrefixes.wireFine, Materials.Tritanium, 64L), GT_OreDictUnificator.get(OrePrefixes.wireFine, Materials.Tritanium, 64L), GT_OreDictUnificator.get(OrePrefixes.wireFine, Materials.Tritanium, 64L), @@ -1084,7 +1088,7 @@ public class DreamCraftRecipeLoader implements Runnable { GT_OreDictUnificator.get(OrePrefixes.foil, Materials.Silicone, 64), GT_OreDictUnificator.get(OrePrefixes.foil, Materials.Polybenzimidazole, 64) }, new FluidStack[]{ - Materials.SolderingAlloy.getMolten(3760L), + Materials.SolderingAlloy.getMolten(3744L), Materials.Naquadria.getMolten(4032L), new FluidStack(FluidRegistry.getFluid("ic2coolant"), 20000) }, getItemContainer("NanoCircuit").get(1L), 8000, 8000000); @@ -1105,7 +1109,7 @@ public class DreamCraftRecipeLoader implements Runnable { GT_OreDictUnificator.get(OrePrefixes.bolt, Materials.Neutronium, 16), GT_OreDictUnificator.get(OrePrefixes.wireFine, Materials.Lanthanum, 64) }, new FluidStack[]{ - Materials.SolderingAlloy.getMolten(3760L), + Materials.SolderingAlloy.getMolten(3744L), Materials.UUMatter.getFluid(8000L), Materials.Osmium.getMolten(1152L) }, getItemContainer("PikoCircuit").get(1L), 10000, 8000000); @@ -1124,7 +1128,7 @@ public class DreamCraftRecipeLoader implements Runnable { GT_OreDictUnificator.get(OrePrefixes.wireGt01, Materials.Bedrockium, 8), GT_OreDictUnificator.get(OrePrefixes.wireFine, Materials.Lanthanum, 64) }, new FluidStack[]{ - Materials.SolderingAlloy.getMolten(3760L), + Materials.SolderingAlloy.getMolten(3744L), Materials.UUMatter.getFluid(24000L), Materials.Osmium.getMolten(2304L) }, getItemContainer("QuantumCircuit").get(1L), 20000, 32000000); @@ -1682,7 +1686,13 @@ public class DreamCraftRecipeLoader implements Runnable { GT_OreDictUnificator.get(OrePrefixes.plate, Materials.NickelZincFerrite, 2), GT_OreDictUnificator.get(OrePrefixes.foil, Materials.Aluminium, 8), }, Materials.SolderingAlloy.getMolten(72), CustomItemList.teslaCover.getWithDamage(1, 1), 320, 7680); - + //Ender Fluid Link Cover + GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ + GT_OreDictUnificator.get(OrePrefixes.plateDense, Materials.Enderium, 4), + ItemList.Sensor_LuV.get(1), + ItemList.Emitter_LuV.get(1), + ItemList.Electric_Pump_LuV.get(1), + }, Materials.Chrome.getMolten(288), CustomItemList.enderLinkFluidCover.getWithDamage(1, 0), 320, 30720); //endregion //region recycling diff --git a/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java b/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java index 581c81d15f..1edd924587 100644 --- a/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java +++ b/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java @@ -2,6 +2,7 @@ package com.github.technus.tectech.loader; import com.github.technus.tectech.mechanics.data.ChunkDataMessage; import com.github.technus.tectech.mechanics.data.PlayerDataMessage; +import com.github.technus.tectech.mechanics.enderStorage.EnderLinkCoverMessage; import com.github.technus.tectech.mechanics.spark.RendererMessage; import com.github.technus.tectech.mechanics.alignment.AlignmentMessage; import com.github.technus.tectech.thing.metaTileEntity.hatch.TextParametersMessage; @@ -34,6 +35,10 @@ public class NetworkDispatcher extends eu.usrv.yamcore.network.PacketDispatcher registerMessage(RendererMessage.ClientHandler.class, RendererMessage.RendererData.class); + registerMessage(EnderLinkCoverMessage.ServerHandler.class, EnderLinkCoverMessage.EnderLinkCoverQuery.class); + registerMessage(EnderLinkCoverMessage.ServerUpdateHandler.class, EnderLinkCoverMessage.EnderLinkCoverUpdate.class); + registerMessage(EnderLinkCoverMessage.ClientHandler.class, EnderLinkCoverMessage.EnderLinkCoverData.class); + registerMessage(TextParametersMessage.ServerHandler.class, TextParametersMessage.ParametersTextQuery.class); registerMessage(TextParametersMessage.ServerUpdateHandler.class, TextParametersMessage.ParametersTextUpdate.class); registerMessage(TextParametersMessage.ClientHandler.class, TextParametersMessage.ParametersTextData.class); diff --git a/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java index d7e9a21a67..1376049f5a 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java @@ -1,8 +1,10 @@ package com.github.technus.tectech.loader.thing; import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.thing.cover.GT_Cover_TM_EnderFluidLink; import com.github.technus.tectech.thing.cover.GT_Cover_TM_TeslaCoil; import com.github.technus.tectech.thing.cover.GT_Cover_TM_TeslaCoil_Ultimate; +import com.github.technus.tectech.thing.item.EnderFluidLinkCover; import com.github.technus.tectech.thing.item.TeslaCoilCover; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; @@ -16,9 +18,11 @@ public class CoverLoader implements Runnable { public void run() { final IIconContainer TESLA_OVERLAY = new Textures.BlockIcons.CustomIcon("iconsets/TESLA_OVERLAY"); final IIconContainer TESLA_OVERLAY_ULTIMATE = new Textures.BlockIcons.CustomIcon("iconsets/TESLA_OVERLAY_ULTIMATE"); + final IIconContainer ENDERFLUIDLINK_OVERLAY = new Textures.BlockIcons.CustomIcon("iconsets/ENDERFLUIDLINK_OVERLAY"); GregTech_API.registerCover(new ItemStack(TeslaCoilCover.INSTANCE, 1, 0), new GT_RenderedTexture(TESLA_OVERLAY), new GT_Cover_TM_TeslaCoil()); GregTech_API.registerCover(new ItemStack(TeslaCoilCover.INSTANCE, 1, 1), new GT_RenderedTexture(TESLA_OVERLAY_ULTIMATE), new GT_Cover_TM_TeslaCoil_Ultimate()); + GregTech_API.registerCover(new ItemStack(EnderFluidLinkCover.INSTANCE, 1, 0), new GT_RenderedTexture(ENDERFLUIDLINK_OVERLAY), new GT_Cover_TM_EnderFluidLink()); TecTech.LOGGER.info("Cover functionality registered"); } } diff --git a/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java index 7b432dbcb4..6fa0ba2bb3 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java @@ -60,6 +60,7 @@ public class ThingsLoader implements Runnable { TeslaStaff.run(); TeslaCoilCover.run(); TeslaCoilCapacitor.run(); + EnderFluidLinkCover.run(); TecTech.LOGGER.info("Useful Items registered"); TeslaCoilComponent.run(); diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java index a3fa341697..0beb5e0af8 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java @@ -243,7 +243,9 @@ public class AnomalyHandler implements IChunkMetaDataHandler { player.attackEntityFrom(MainLoader.subspace,Math.max(1,badness/8f)); } } else if (playerTag.getDouble(SPACE_CANCER) > 0 && !player.isDead) { - playerTag.setDouble(SPACE_CANCER, Math.max(0, playerTag.getDouble(SPACE_CANCER) - 7.6293945E-6f)); + if (playerTag.getDouble(SPACE_CANCER) == 0 || player.ticksExisted % 10 != 0) + return; + playerTag.setDouble(SPACE_CANCER, Math.max(0, playerTag.getDouble(SPACE_CANCER) - 7.6293945E-5f)); } } TecTech.playerPersistence.saveData(player); diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderFluidContainer.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderFluidContainer.java new file mode 100644 index 0000000000..1a5ad6a69c --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderFluidContainer.java @@ -0,0 +1,100 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import java.io.Serializable; + +public class EnderFluidContainer implements IFluidHandler, Serializable { + private static final int CAPACITY = 64000; + private int fluidID = -1; + private int fluidQuantity = 0; + + public EnderFluidContainer() { + } + + private FluidStack getFluidStack() { + FluidStack fluidStack = null; + if (fluidID >= 0) { + fluidStack = new FluidStack(fluidID, fluidQuantity); + } + return fluidStack; + } + + private void setFluidStack(FluidStack fluidStack) { + if (fluidStack != null && fluidStack.amount != 0) { + fluidID = fluidStack.getFluidID(); + fluidQuantity = fluidStack.amount; + } else { + fluidID = -1; + fluidQuantity = 0; + } + } + + + @Override + public int fill(ForgeDirection side, FluidStack fluidStackIn, boolean doFill) { + int filledFluid = 0; + FluidStack fluidStackStored = getFluidStack(); + if (fluidStackIn != null) { + if (fluidStackStored == null) { + fluidStackStored = fluidStackIn.copy(); + fluidStackStored.amount = 0; + } + if (fluidStackStored.amount < CAPACITY && fluidStackIn.isFluidEqual(fluidStackStored)) { + filledFluid = Math.min(CAPACITY - fluidStackStored.amount, fluidStackIn.amount); + if (doFill) { + fluidStackStored.amount += filledFluid; + setFluidStack(fluidStackStored); + } + } + } + return filledFluid; + } + + @Override + public FluidStack drain(ForgeDirection side, FluidStack fluidStack, boolean doDrain) { + FluidStack fluidStackOutput = null; + if (fluidStack != null && fluidStack.isFluidEqual(getFluidStack())) { + fluidStackOutput = drain(side, fluidStack.amount, doDrain); + } + return fluidStackOutput; + } + + @Override + public FluidStack drain(ForgeDirection side, int amount, boolean doDrain) { + FluidStack fluidStackOutput = null; + FluidStack fluidStackStored = getFluidStack(); + if (fluidStackStored != null && fluidStackStored.amount > 0) { + int drainedFluid = Math.min(fluidStackStored.amount, amount); + fluidStackOutput = fluidStackStored.copy(); + fluidStackOutput.amount = drainedFluid; + if (doDrain) { + fluidStackStored.amount -= drainedFluid; + if (fluidStackStored.amount == 0) { + fluidStackStored = null; + } + setFluidStack(fluidStackStored); + } + } + return fluidStackOutput; + } + + @Override + public boolean canFill(ForgeDirection forgeDirection, Fluid fluid) { + return true; + } + + @Override + public boolean canDrain(ForgeDirection forgeDirection, Fluid fluid) { + return true; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection forgeDirection) { + return new FluidTankInfo[]{new FluidTankInfo(getFluidStack(), CAPACITY)}; + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java new file mode 100644 index 0000000000..081ce3b309 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java @@ -0,0 +1,132 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import eu.usrv.yamcore.network.client.AbstractClientMessageHandler; +import eu.usrv.yamcore.network.server.AbstractServerMessageHandler; +import gregtech.api.metatileentity.BaseMetaTileEntity; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fluids.IFluidHandler; + +import java.io.*; +import java.util.Arrays; + +import static com.github.technus.tectech.mechanics.enderStorage.EnderWorldSavedData.bindEnderLinkTag; +import static com.github.technus.tectech.mechanics.enderStorage.EnderWorldSavedData.getEnderLinkTag; +import static com.github.technus.tectech.thing.cover.GT_Cover_TM_EnderFluidLink.setEnderLinkTag; + +public class EnderLinkCoverMessage implements IMessage { + EnderLinkTankWithTag messageData; + + public EnderLinkCoverMessage() { + } + + @Override + public void fromBytes(ByteBuf pBuffer) { + try { + //I'd love to know why I need to offset by one byte for this to work + byte[] boop = pBuffer.array(); + boop = Arrays.copyOfRange(boop, 1, boop.length); + InputStream is = new ByteArrayInputStream(boop); + ObjectInputStream ois = new ObjectInputStream(is); + Object data = ois.readObject(); + messageData = (EnderLinkTankWithTag) data; + } catch (Exception ignore) { + } + } + + @Override + public void toBytes(ByteBuf pBuffer) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(messageData); + oos.flush(); + InputStream is = new ByteArrayInputStream(baos.toByteArray()); + pBuffer.writeBytes(is, baos.toByteArray().length); + } catch (Exception ignore) { + } + } + + public static class EnderLinkCoverQuery extends EnderLinkCoverMessage { + public EnderLinkCoverQuery() { + } + + public EnderLinkCoverQuery(EnderLinkTag tag, IFluidHandler fluidHandler) { + messageData = new EnderLinkTankWithTag(tag, fluidHandler); + } + } + + public static class EnderLinkCoverUpdate extends EnderLinkCoverMessage { + public EnderLinkCoverUpdate() { + } + + public EnderLinkCoverUpdate(EnderLinkTag tag, IFluidHandler fluidHandler) { + messageData = new EnderLinkTankWithTag(tag, fluidHandler); + } + } + + public static class EnderLinkCoverData extends EnderLinkCoverMessage { + public EnderLinkCoverData() { + } + + public EnderLinkCoverData(EnderLinkTag tag, IFluidHandler fluidHandler) { + messageData = new EnderLinkTankWithTag(tag, fluidHandler); + } + } + + public static class ServerHandler extends AbstractServerMessageHandler<EnderLinkCoverQuery> { + @Override + public IMessage handleServerMessage(EntityPlayer pPlayer, EnderLinkCoverQuery pMessage, MessageContext pCtx) { + IMessage reply = null; + if (pMessage.messageData != null) { + reply = new EnderLinkCoverData(getEnderLinkTag(pMessage.messageData.getFluidHandler()), + pMessage.messageData.getFluidHandler()); + } + return reply; + } + } + + public static class ServerUpdateHandler extends AbstractServerMessageHandler<EnderLinkCoverUpdate> { + @Override + public IMessage handleServerMessage(EntityPlayer pPlayer, EnderLinkCoverUpdate pMessage, MessageContext pCtx) { + if (pMessage.messageData != null) { + EnderLinkTag tag = pMessage.messageData.getTag(); + IFluidHandler handler = pMessage.messageData.getFluidHandler(); + if (tag.getUUID() == null){ + bindEnderLinkTag(handler, tag); + } else if (handler instanceof BaseMetaTileEntity) { + BaseMetaTileEntity baseTile = (BaseMetaTileEntity) handler; + if (tag.getUUID() == baseTile.getOwnerUuid()){ + bindEnderLinkTag(handler, tag); + } + } + } + return null; + } + } + + public static class ClientHandler extends AbstractClientMessageHandler<EnderLinkCoverData> { + @Override + public IMessage handleClientMessage(EntityPlayer pPlayer, EnderLinkCoverData pMessage, MessageContext pCtx) { + if (pMessage.messageData != null) { + setEnderLinkTag(pMessage.messageData.getTag()); + } + return null; + } + } + + private static class EnderLinkTankWithTag extends EnderLinkTank { + private final EnderLinkTag tag; + + public EnderLinkTankWithTag(EnderLinkTag tag, IFluidHandler fluidHandler) { + super(fluidHandler); + this.tag = tag; + } + + public EnderLinkTag getTag() { + return tag; + } + } +}
\ No newline at end of file diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTag.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTag.java new file mode 100644 index 0000000000..3d7b7a20b8 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTag.java @@ -0,0 +1,39 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import com.google.common.base.Objects; + +import java.awt.*; +import java.io.Serializable; +import java.util.UUID; + +public class EnderLinkTag implements Serializable { + private final Color color; + private final UUID player; + + public EnderLinkTag(Color color, UUID player) { + this.color = color; + this.player = player; + } + + public int getColorInt() { + return color.getRGB(); + } + + public UUID getUUID() { + return player; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EnderLinkTag that = (EnderLinkTag) o; + return Objects.equal(color, that.color) && + Objects.equal(player, that.player); + } + + @Override + public int hashCode() { + return Objects.hashCode(color, player); + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTank.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTank.java new file mode 100644 index 0000000000..a64a629161 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTank.java @@ -0,0 +1,46 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import com.google.common.base.Objects; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.fluids.IFluidHandler; + +import java.io.Serializable; + +public class EnderLinkTank implements Serializable { + private final int X; + private final int Y; + private final int Z; + private final int D; + + public EnderLinkTank(IFluidHandler fluidHandler) { + TileEntity tile = (TileEntity)fluidHandler; + X = tile.xCoord; + Y = tile.yCoord; + Z = tile.zCoord; + D = tile.getWorldObj().provider.dimensionId; + } + + public IFluidHandler getFluidHandler() { + IFluidHandler fluidHandler = null; + TileEntity tile = DimensionManager.getWorld(D).getTileEntity(X, Y, Z); + if (tile instanceof IFluidHandler) fluidHandler = (IFluidHandler) tile; + return fluidHandler; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EnderLinkTank that = (EnderLinkTank) o; + return X == that.X && + Y == that.Y && + Z == that.Z && + D == that.D; + } + + @Override + public int hashCode() { + return Objects.hashCode(X, Y, Z, D); + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderWorldSavedData.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderWorldSavedData.java new file mode 100644 index 0000000000..6afa3a494f --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderWorldSavedData.java @@ -0,0 +1,129 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.WorldSavedData; +import net.minecraft.world.storage.MapStorage; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.fluids.IFluidHandler; + +import java.awt.*; +import java.io.*; +import java.util.HashMap; +import java.util.Map; + +import static com.github.technus.tectech.Reference.MODID; + +public class EnderWorldSavedData extends WorldSavedData { + private static EnderWorldSavedData INSTANCE; + + private static final String DATA_NAME = MODID + "_EnderWorldSavedData"; + private static final String ENDER_LIQUID_TAG_LINK = DATA_NAME + "_EnderLiquidTagLink"; + private static final String ENDER_LIQUID_TANK_LINK = DATA_NAME + "_EnderLiquidTankLink"; + private static final EnderLinkTag DEFAULT_LINK_TAG = new EnderLinkTag(Color.WHITE, null); + + private Map<EnderLinkTag, EnderFluidContainer> EnderLiquidTagLink = new HashMap<>(); + private Map<EnderLinkTank, EnderLinkTag> EnderLiquidTankLink = new HashMap<>(); + + public EnderWorldSavedData() { + super(DATA_NAME); + } + + public EnderWorldSavedData(String s) { + super(s); + } + + @Override + public void readFromNBT(NBTTagCompound nbtTagCompound) { + try { + byte[] ba = nbtTagCompound.getByteArray(ENDER_LIQUID_TAG_LINK); + InputStream is = new ByteArrayInputStream(ba); + ObjectInputStream ois = new ObjectInputStream(is); + Object data = ois.readObject(); + EnderLiquidTagLink = (Map<EnderLinkTag, EnderFluidContainer>) data; + } catch (IOException | ClassNotFoundException ignored) { + System.out.println("ENDER_LIQUID_TAG_LINK LOAD FAILED"); + System.out.println(ignored); + } + + try { + byte[] ba = nbtTagCompound.getByteArray(ENDER_LIQUID_TANK_LINK); + InputStream is = new ByteArrayInputStream(ba); + ObjectInputStream ois = new ObjectInputStream(is); + Object data = ois.readObject(); + EnderLiquidTankLink = (Map<EnderLinkTank, EnderLinkTag>) data; + } catch (IOException | ClassNotFoundException ignored) { + System.out.println("ENDER_LIQUID_TANK_LINK LOAD FAILED"); + System.out.println(ignored); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbtTagCompound) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(EnderLiquidTagLink); + oos.flush(); + byte[] data = bos.toByteArray(); + nbtTagCompound.setByteArray(ENDER_LIQUID_TAG_LINK, data); + } catch (IOException ignored) { + System.out.println("ENDER_LIQUID_TAG_LINK SAVE FAILED"); + System.out.println(ignored); + } + + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(EnderLiquidTankLink); + oos.flush(); + byte[] data = bos.toByteArray(); + nbtTagCompound.setByteArray(ENDER_LIQUID_TANK_LINK, data); + } catch (IOException ignored) { + System.out.println("ENDER_LIQUID_TANK_LINK SAVE FAILED"); + System.out.println(ignored); + } + } + + private static void loadInstance() { + if (INSTANCE == null) { + MapStorage storage = DimensionManager.getWorld(0).mapStorage; + INSTANCE = (EnderWorldSavedData) storage.loadData(EnderWorldSavedData.class, DATA_NAME); + if (INSTANCE == null) { + INSTANCE = new EnderWorldSavedData(); + storage.setData(DATA_NAME, INSTANCE); + } + } + INSTANCE.markDirty(); + } + + private static Map<EnderLinkTag, EnderFluidContainer> getEnderLiquidLink() { + loadInstance(); + return INSTANCE.EnderLiquidTagLink; + } + + private static Map<EnderLinkTank, EnderLinkTag> getEnderLiquidTankLink() { + loadInstance(); + return INSTANCE.EnderLiquidTankLink; + } + + public static EnderFluidContainer getEnderFluidContainer(EnderLinkTag tag) { + if (!getEnderLiquidLink().containsKey(tag)) { + getEnderLiquidLink().put(tag, new EnderFluidContainer()); + } + return getEnderLiquidLink().get(tag); + } + + public static EnderLinkTag getEnderLinkTag(IFluidHandler handler) { + EnderLinkTank tank = new EnderLinkTank(handler); + if (!getEnderLiquidTankLink().containsKey(tank)) { + getEnderLiquidTankLink().put(tank, DEFAULT_LINK_TAG); + } + return getEnderLiquidTankLink().get(tank); + } + + public static void bindEnderLinkTag(IFluidHandler handler, EnderLinkTag tag) { + EnderLinkTank tank = new EnderLinkTank(handler); + getEnderLiquidTankLink().remove(tank); + getEnderLiquidTankLink().put(tank, tag); + } +}
\ No newline at end of file diff --git a/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java b/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java index 58caed7951..58356774cc 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java +++ b/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java @@ -3,6 +3,8 @@ package com.github.technus.tectech.mechanics.spark; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import eu.usrv.yamcore.network.client.AbstractClientMessageHandler; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; @@ -16,7 +18,7 @@ import java.util.Arrays; import java.util.HashSet; public class RendererMessage implements IMessage { - HashSet<ThaumSpark> sparkList = new HashSet<ThaumSpark>(); + HashSet<ThaumSpark> sparkList; public RendererMessage() { } @@ -31,7 +33,7 @@ public class RendererMessage implements IMessage { ObjectInputStream ois = new ObjectInputStream(is); Object data = ois.readObject(); sparkList = (HashSet<ThaumSpark>) data; - } catch (IOException | ClassNotFoundException ex) { + } catch (IOException | ClassNotFoundException ignored) { } } @@ -44,7 +46,7 @@ public class RendererMessage implements IMessage { oos.flush(); InputStream is = new ByteArrayInputStream(baos.toByteArray()); pBuffer.writeBytes(is, baos.toByteArray().length); - } catch (IOException ex) { + } catch (IOException ignore) { } } @@ -69,6 +71,7 @@ public class RendererMessage implements IMessage { } } + @SideOnly(Side.CLIENT) private static void thaumLightning(int tX, int tY, int tZ, int tXN, int tYN, int tZN, int wID) { //This is enough to check for thaum, since it only ever matters for client side effects (Tested not to crash) if (Loader.isModLoaded("Thaumcraft")) { diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java index e397c1dc5f..de8d828cf4 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java @@ -1,19 +1,19 @@ package com.github.technus.tectech.mechanics.tesla; import com.github.technus.tectech.mechanics.spark.ThaumSpark; +import com.google.common.collect.Multimap; -import java.util.HashMap; import java.util.HashSet; -import java.util.Objects; +import java.util.Map; -import static com.github.technus.tectech.util.Util.entriesSortedByValues; import static java.lang.Math.sqrt; public interface ITeslaConnectable extends ITeslaConnectableSimple { //Map with all Teslas in the same dimension and the distance to them //TODO Range - HashMap<ITeslaConnectableSimple, Integer> teslaNodeMap = new HashMap<>(); + Multimap<Integer, ITeslaConnectableSimple> getTeslaNodeMap(); + //ThaumCraft lighting coordinate pairs, so we can send them in bursts and save on lag - HashSet<ThaumSpark> sparkList = new HashSet<>(); + HashSet<ThaumSpark> getSparkList(); //-128 to -1 disables capability //0 means any source or target @@ -33,88 +33,113 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { boolean teslaDrainEnergy(long teslaVoltageDrained); class TeslaUtil { - public static final HashSet<ITeslaConnectableSimple> teslaNodeSet = new HashSet<>();//Targets for power transmission + private static final HashSet<ITeslaConnectableSimple> teslaSimpleNodeSet = new HashSet<>();//Targets for power transmission + private static final HashSet<ITeslaConnectable> teslaNodeSet = new HashSet<>();//Sources of power transmission + + public static void teslaSimpleNodeSetAdd(ITeslaConnectableSimple target) { + if (!teslaSimpleNodeSet.contains(target)) { + teslaSimpleNodeSet.add(target); + teslaNodeSet.forEach(origin -> addTargetToTeslaOrigin(target, origin)); + } + } + + public static void teslaSimpleNodeSetRemove(ITeslaConnectableSimple target){ + teslaSimpleNodeSet.remove(target); + if (target instanceof ITeslaConnectable)teslaNodeSet.remove(target); + teslaNodeSet.forEach(origin -> removeTargetFromTeslaOrigin(target, origin)); + } + + private static void addTargetToTeslaOrigin(ITeslaConnectableSimple target, ITeslaConnectable origin){ + if (origin.equals(target) || !origin.getTeslaDimension().equals(target.getTeslaDimension())) { + //Skip if looking at myself and skip if not in the same dimension + //TODO, INTERDIM? + return; + } else if (origin.getTeslaTransmissionCapability() != 0 && origin.getTeslaReceptionCapability() != 0 && + origin.getTeslaTransmissionCapability() != origin.getTeslaReceptionCapability()) { + //Skip if incompatible + return; + } + //Range calc + int distance = (int) sqrt(origin.getTeslaPosition().distanceSq(target.getTeslaPosition())); + if (distance > origin.getTeslaTransmissionRange() * target.getTeslaReceptionCoefficient()) { + //Skip if the range is too vast + return; + } + origin.getTeslaNodeMap().put(distance, target); + } + + private static void removeTargetFromTeslaOrigin(ITeslaConnectableSimple target, ITeslaConnectable origin){ + //Range calc TODO Remove duplicate? + int distance = (int) sqrt(origin.getTeslaPosition().distanceSq(target.getTeslaPosition())); + origin.getTeslaNodeMap().remove(distance, target); + } public static void generateTeslaNodeMap(ITeslaConnectable origin) { - origin.teslaNodeMap.clear(); - for (ITeslaConnectableSimple target : teslaNodeSet) { + origin.getTeslaNodeMap().clear(); + for (ITeslaConnectableSimple target : teslaSimpleNodeSet) { //Sanity checks if (target == null) { //The Tesla Covers do not remove themselves from the list and this is the code that does - teslaNodeSet.remove(null); - continue; - } else if (origin.equals(target) || !origin.getTeslaDimension().equals(target.getTeslaDimension())) { - //Skip if looking at myself and skip if not in the same dimension - //TODO, INTERDIM? - continue; - } else if (origin.getTeslaTransmissionCapability() != 0 && origin.getTeslaReceptionCapability() != 0 && - origin.getTeslaTransmissionCapability() != origin.getTeslaReceptionCapability()) { - //Skip if incompatible - continue; - } - - //Range calc - int distance = (int) sqrt(origin.getTeslaPosition().distanceSq(target.getTeslaPosition())); - if (distance > origin.getTeslaTransmissionRange() * target.getTeslaReceptionCoefficient()) { - //Skip if the range is too vast + teslaSimpleNodeSet.remove(null); continue; } - origin.teslaNodeMap.put(target, distance); + addTargetToTeslaOrigin(target, origin); } - } - - public static void cleanTeslaNodeMap(ITeslaConnectable origin) { - //Wipes all null objects, in practice this is unloaded or improperly removed tesla objects - origin.teslaNodeMap.keySet().removeIf(Objects::isNull); + teslaNodeSet.add(origin); } public static long powerTeslaNodeMap(ITeslaConnectable origin) { - //Teslas can only send OR receive - if (origin.isTeslaReadyToReceive()) { - return 0L;//TODO Negative values to indicate charging? - } long remainingAmperes = origin.getTeslaOutputCurrent(); - while (remainingAmperes > 0) { - long startingAmperes = remainingAmperes; - for (HashMap.Entry<ITeslaConnectableSimple, Integer> Rx : entriesSortedByValues(teslaNodeMap)) { - if (origin.getTeslaStoredEnergy() < (origin.isOverdriveEnabled() ? origin.getTeslaOutputVoltage() * 2 : origin.getTeslaOutputVoltage())) { - //Return and end the tick if we're out of energy to send - return origin.getTeslaOutputCurrent() - remainingAmperes; - } - - ITeslaConnectableSimple target = Rx.getKey(); - int distance = Rx.getValue(); + boolean canSendPower = !origin.isTeslaReadyToReceive() && remainingAmperes > 0; + + if (canSendPower) { + for (Map.Entry<Integer, ITeslaConnectableSimple> Rx : origin.getTeslaNodeMap().entries()) { + //Do we still have power left to send kind of check + if (origin.getTeslaStoredEnergy() < (origin.isOverdriveEnabled() ? origin.getTeslaOutputVoltage() * + 2 : origin.getTeslaOutputVoltage())) break; + //Explicit words for the important fields + ITeslaConnectableSimple target = Rx.getValue(); + int distance = Rx.getKey(); + //Can our target receive energy? + if(!target.isTeslaReadyToReceive()) continue; //Calculate the voltage output long outputVoltageInjectable; long outputVoltageConsumption; - if (origin.isOverdriveEnabled()) { outputVoltageInjectable = origin.getTeslaOutputVoltage(); - outputVoltageConsumption = origin.getTeslaOutputVoltage() + (distance * origin.getTeslaEnergyLossPerBlock()) + - (long) Math.round(origin.getTeslaOutputVoltage() * origin.getTeslaOverdriveLossCoefficient()); + outputVoltageConsumption = origin.getTeslaOutputVoltage() + + (distance * origin.getTeslaEnergyLossPerBlock()) + + (long) Math.round(origin.getTeslaOutputVoltage() * + origin.getTeslaOverdriveLossCoefficient()); } else { - outputVoltageInjectable = origin.getTeslaOutputVoltage() - (distance * origin.getTeslaEnergyLossPerBlock()); + outputVoltageInjectable = origin.getTeslaOutputVoltage() - (distance * + origin.getTeslaEnergyLossPerBlock()); outputVoltageConsumption = origin.getTeslaOutputVoltage(); } - //Skip the target if the cost is too high - if (origin.getTeslaStoredEnergy() < outputVoltageConsumption) { - continue; + //Break out of the loop if the cost is too high + //Since the next target will have an even higher cost, just quit now. + if (origin.getTeslaStoredEnergy() < outputVoltageConsumption) break; + + //Now shove in as many packets as will fit~ + while(canSendPower){ + if (target.teslaInjectEnergy(outputVoltageInjectable)) { + origin.teslaDrainEnergy(outputVoltageConsumption); + origin.getSparkList().add(new ThaumSpark(origin.getTeslaPosition(), + target.getTeslaPosition(), origin.getTeslaDimension())); + remainingAmperes--; + //Update the can send power flag each time we send power + canSendPower = (origin.getTeslaStoredEnergy() < outputVoltageConsumption || + remainingAmperes > 0); + } else { + //Breaks out when I can't send anymore power + break; + } } - if (target.teslaInjectEnergy(outputVoltageInjectable)) { - origin.teslaDrainEnergy(outputVoltageConsumption); - sparkList.add(new ThaumSpark(origin.getTeslaPosition(), target.getTeslaPosition(), origin.getTeslaDimension())); - remainingAmperes--; - } - if (remainingAmperes == 0) { - return origin.getTeslaOutputCurrent(); - } - } - //End the tick after one iteration with no transmissions - if (remainingAmperes == startingAmperes) { - return origin.getTeslaOutputCurrent() - remainingAmperes; + //Break out if we can't send power anymore + if (!canSendPower)break; } } return origin.getTeslaOutputCurrent() - remainingAmperes; diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java new file mode 100644 index 0000000000..5c6fef6af8 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java @@ -0,0 +1,77 @@ +package com.github.technus.tectech.mechanics.tesla; + +import com.github.technus.tectech.util.Vec3Impl; +import com.google.common.base.Objects; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.teslaSimpleNodeSetAdd; +import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.teslaSimpleNodeSetRemove; + +public class TeslaCoverConnection implements ITeslaConnectableSimple { + private final IGregTechTileEntity IGT; + private final Vec3Impl pos; + private final byte teslaReceptionCapability; + + public TeslaCoverConnection(IGregTechTileEntity IGT, byte teslaReceptionCapability) { + this.IGT = IGT; + this.pos = new Vec3Impl(IGT); + this.teslaReceptionCapability = teslaReceptionCapability; + } + + @Override + public byte getTeslaReceptionCapability() { + return teslaReceptionCapability; + } + + @Override + public float getTeslaReceptionCoefficient() { + return 1; + } + + @Override + public boolean isTeslaReadyToReceive() { + return true; + } + + @Override + public long getTeslaStoredEnergy() { + return IGT.getStoredEU(); + } + + @Override + public Vec3Impl getTeslaPosition() { + return pos; + } + + @Override + public Integer getTeslaDimension() { + return IGT.getWorld().provider.dimensionId; + } + + @Override + public boolean teslaInjectEnergy(long teslaVoltageInjected) { + //Same as in the microwave transmitters, this does not account for amp limits + boolean output = false; + + if (!IGT.isDead()){ + output = IGT.injectEnergyUnits((byte) 1, teslaVoltageInjected, 1L) > 0L; + } else { + teslaSimpleNodeSetRemove(this); + } + + return output; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TeslaCoverConnection that = (TeslaCoverConnection) o; + return Objects.equal(IGT, that.IGT); + } + + @Override + public int hashCode() { + return Objects.hashCode(IGT); + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java index a86695ff4a..9bd69c67ed 100644 --- a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java +++ b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java @@ -94,7 +94,7 @@ public enum CustomItemList implements IItemContainer { eM_avr_HV, eM_avr_EV, eM_avr_IV, eM_avr_LuV, eM_avr_ZPM, eM_avr_UV, eM_avr_UHV, eM_avr_UEV, eM_avr_UIV, eM_avr_UMV, - scanContainer, parametrizerMemory, teslaCapacitor, teslaCover, teslaComponent, teslaStaff, + scanContainer, parametrizerMemory, teslaCapacitor, teslaCover, teslaComponent, teslaStaff, enderLinkFluidCover, Machine_TeslaCoil_1by1_LV, Machine_TeslaCoil_1by1_MV, Machine_TeslaCoil_1by1_HV, Machine_TeslaCoil_1by1_EV, Machine_TeslaCoil_1by1_IV, Machine_TeslaCoil_2by2_LV, Machine_TeslaCoil_2by2_MV, Machine_TeslaCoil_2by2_HV, Machine_TeslaCoil_2by2_EV, Machine_TeslaCoil_2by2_IV, diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java new file mode 100644 index 0000000000..03c612c190 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java @@ -0,0 +1,355 @@ +package com.github.technus.tectech.thing.cover; + +import com.github.technus.tectech.loader.NetworkDispatcher; +import com.github.technus.tectech.mechanics.enderStorage.EnderLinkCoverMessage; +import com.github.technus.tectech.mechanics.enderStorage.EnderLinkTag; +import eu.usrv.yamcore.auxiliary.PlayerChatHelper; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.GT_GUICover; +import gregtech.api.gui.widgets.GT_GuiIcon; +import gregtech.api.gui.widgets.GT_GuiIconButton; +import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import gregtech.api.interfaces.IGuiScreen; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.metatileentity.BaseMetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.net.GT_Packet_TileEntityCover; +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_Utility; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidHandler; + +import java.awt.*; +import java.util.UUID; + +import static com.github.technus.tectech.mechanics.enderStorage.EnderWorldSavedData.*; + +public class GT_Cover_TM_EnderFluidLink extends GT_CoverBehavior { + private static final int L_PER_TICK = 8000; + private final static int IMPORT_EXPORT_MASK = 0b0001; + private final static int PUBLIC_PRIVATE_MASK = 0b0010; + private static EnderLinkTag tag = new EnderLinkTag(Color.WHITE, null);//Client-Sided + + public GT_Cover_TM_EnderFluidLink() { + } + + public static void setEnderLinkTag(EnderLinkTag inputTag) { + if(inputTag != null) { + tag = inputTag; + //Hacky Way to update the gui + GUI_INSTANCE.resetColorField(); + } + } + + private void transferFluid(IFluidHandler source, byte sSide, IFluidHandler target, byte tSide, int amount) { + FluidStack fluidStack = source.drain(ForgeDirection.getOrientation(sSide), amount, false); + + if (fluidStack != null) { + int fluidTransferred = target.fill(ForgeDirection.getOrientation(tSide), fluidStack, true); + source.drain(ForgeDirection.getOrientation(sSide), fluidTransferred, true); + } + } + + private boolean testBit(int aCoverVariable, int bitMask) { + return (aCoverVariable & bitMask) != 0; + } + + private int toggleBit(int aCoverVariable, int bitMask) { + return (aCoverVariable ^ bitMask); + } + + @Override + public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + if ((aTileEntity instanceof IFluidHandler)) { + IFluidHandler fluidHandlerSelf = (IFluidHandler) aTileEntity; + IFluidHandler fluidHandlerEnder = getEnderFluidContainer(getEnderLinkTag((IFluidHandler) aTileEntity)); + + if (testBit(aCoverVariable, IMPORT_EXPORT_MASK)) { + transferFluid(fluidHandlerEnder, (byte) 6, fluidHandlerSelf, aSide, L_PER_TICK); + } else { + transferFluid(fluidHandlerSelf, aSide, fluidHandlerEnder, (byte) 6, L_PER_TICK); + } + } + return aCoverVariable; + } + + @Override + public String getDescription(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return ""; + } + + @Override + public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return true; + } + + @Override + public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return true; + } + + @Override + public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + int newCoverVariable = toggleBit(aCoverVariable, IMPORT_EXPORT_MASK); + + if (testBit(aCoverVariable, IMPORT_EXPORT_MASK)) { + PlayerChatHelper.SendInfo(aPlayer, "Ender Suction Engaged!");//TODO Translation support + } else { + PlayerChatHelper.SendInfo(aPlayer, "Ender Filling Engaged!"); + } + return newCoverVariable; + } + + @Override + public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + //Runs each tick + return 1; + } + + //region GUI + @Override + public boolean hasCoverGUI() { + return true; + } + + @Override + public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { + //Only open gui if we're placed on a fluid tank + Object gui = null; + if (aTileEntity instanceof IFluidHandler) { + gui = new TM_EnderFluidLinkCover(aSide, aCoverID, coverData, aTileEntity); + } + return gui; + } + + private static TM_EnderFluidLinkCover GUI_INSTANCE; + + private class TM_EnderFluidLinkCover extends GT_GUICover { + private final byte side; + private final int coverID; + private int coverVariable; + private GT_GuiIntegerHexTextBox colorField; + + private final static int START_X = 10; + private final static int START_Y = 25; + private final static int SPACE_X = 18; + private final static int SPACE_Y = 18; + + private final static int SIZE_X = 176; + private final static int SIZE_Y = 107; + + private final static int BOX_SIZE_X = 34; + private final static int BOX_SIZE_Y = 34; + + private final static int TEXT_FIELD_SIZE_X = 72; + private final static int TEXT_FIELD_SIZE_Y = 12; + private final static int TEXT_STRING_LENGTH = 9; + + private final static int FONT_COLOR = 0xFF555555; + private final static int BOX_BORDER_COLOR = 0xFF000000; + + private final static int COLOR_FIELD_ID = 0; + private final static int PUBLIC_BUTTON_ID = 1; + private final static int PRIVATE_BUTTON_ID = 2; + private final static int IMPORT_BUTTON_ID = 3; + private final static int EXPORT_BUTTON_ID = 4; + + private GT_GuiIconButton newButtonWithSpacing(int id, int x, int y, GT_GuiIcon icon) { + return new GT_GuiIconButton(this, id, START_X + SPACE_X * x, START_Y + SPACE_Y * y, icon); + } + + private GT_GuiIntegerHexTextBox newTextField(int id, int x, int y) { + GT_GuiIntegerHexTextBox field = new GT_GuiIntegerHexTextBox(this, id, START_X + SPACE_X * x, + START_Y + SPACE_Y * y, TEXT_FIELD_SIZE_X, TEXT_FIELD_SIZE_Y); + field.setMaxStringLength(TEXT_STRING_LENGTH); + return field; + } + + private int drawNewString(String text, int x, int y) { + int align = 4; + return fontRendererObj.drawString(text, START_X + SPACE_X * x, align + START_Y + SPACE_Y * y, FONT_COLOR); + } + + private void drawColorSquare(int x, int y) { + //Draw the border square + int borderX1 = START_X + SPACE_X * x; + int borderY1 = START_Y + SPACE_Y * y; + int borderX2 = borderX1 + BOX_SIZE_X; + int borderY2 = borderY1 + BOX_SIZE_Y; + drawRect(borderX1, borderY1, borderX2, borderY2, BOX_BORDER_COLOR); + + //Draw Checkerboard Pattern + int white = 0xFFFFFFFF; + int grey = 0xFFBFBFBF; + boolean whiteOrGrey = true; + int cGridXStart = borderX1 + 1; + int cGridYStart = borderY1 + 1; + int cGridXToDraw = 4; + int cGridYToDraw = 4; + int cSquareWidth = 8; + int cSquareHeight = 8; + for (int i = 0; i < cGridXToDraw; i++) { + for (int j = 0; j < cGridYToDraw; j++) { + int cBoxX1 = cGridXStart + (cSquareWidth * i); + int cBoxY1 = cGridYStart + (cSquareHeight * j); + int cBoxX2 = cBoxX1 + cSquareWidth; + int cBoxY2 = cBoxY1 + cSquareHeight; + int cBoxColor = whiteOrGrey ? white : grey; + drawRect(cBoxX1, cBoxY1, cBoxX2, cBoxY2, cBoxColor); + whiteOrGrey = !whiteOrGrey; + } + whiteOrGrey = !whiteOrGrey; + } + + //Draw the actual color + int insideX1 = borderX1 + 1; + int insideY1 = borderY1 + 1; + int insideX2 = borderX2 - 1; + int insideY2 = borderY2 - 1; + drawRect(insideX1, insideY1, insideX2, insideY2, tag.getColorInt()); + } + + public TM_EnderFluidLinkCover(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + super(aTileEntity, SIZE_X, SIZE_Y, GT_Utility.intToStack(aCoverID)); + side = aSide; + coverID = aCoverID; + coverVariable = aCoverVariable; + NetworkDispatcher.INSTANCE.sendToServer(new EnderLinkCoverMessage.EnderLinkCoverQuery(tag, (IFluidHandler) tile)); + //Color Value Field + colorField = newTextField(COLOR_FIELD_ID, 2, 1); + GUI_INSTANCE = this; + resetColorField(); + //Public/Private Buttons + newButtonWithSpacing(PUBLIC_BUTTON_ID, 0, 2, GT_GuiIcon.WHITELIST) + .setTooltipText("Public"); + newButtonWithSpacing(PRIVATE_BUTTON_ID, 1, 2, GT_GuiIcon.BLACKLIST) + .setTooltipText("Private"); + //Import/Export Buttons + newButtonWithSpacing(IMPORT_BUTTON_ID, 0, 3, GT_GuiIcon.IMPORT) + .setTooltipText(trans("007", "Import")); + newButtonWithSpacing(EXPORT_BUTTON_ID, 1, 3, GT_GuiIcon.EXPORT) + .setTooltipText(trans("007", "Export")); + } + + @Override + public void drawExtras(int mouseX, int mouseY, float parTicks) { + super.drawExtras(mouseX, mouseY, parTicks); + drawColorSquare(0, 0); + drawNewString("Color Value", 2, 0); + drawNewString("Public/Private", 2, 2); + drawNewString(trans("229", "Import/Export"), 2, 3); + } + + @Override + protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { + updateButtons(); + } + + @Override + public void buttonClicked(GuiButton btn){ + if (getClickable(btn.id)){ + coverVariable = getNewCoverVariable(btn.id); + GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); + } + updateButtons(); + } + + private void updateButtons(){ + GuiButton b; + for (Object o : buttonList) { + b = (GuiButton) o; + b.enabled = getClickable(b.id); + } + } + + private void switchPrivatePublic(int coverVar) { + UUID ownerUUID = tag.getUUID(); + if (testBit(coverVar, PUBLIC_PRIVATE_MASK)){ + if (tile instanceof BaseMetaTileEntity){ + BaseMetaTileEntity mte = (BaseMetaTileEntity) tile; + ownerUUID = mte.getOwnerUuid(); + } + } else { + ownerUUID = null; + } + EnderLinkTag newTag = new EnderLinkTag(new Color(tag.getColorInt(), true), ownerUUID); + NetworkDispatcher.INSTANCE.sendToServer(new EnderLinkCoverMessage.EnderLinkCoverUpdate(newTag, (IFluidHandler) tile)); + } + + private int getNewCoverVariable(int id) { + int tempCoverVariable = coverVariable; + switch (id) { + case PUBLIC_BUTTON_ID: case PRIVATE_BUTTON_ID: + tempCoverVariable = toggleBit(tempCoverVariable, PUBLIC_PRIVATE_MASK); + switchPrivatePublic(tempCoverVariable); + break; + case IMPORT_BUTTON_ID: case EXPORT_BUTTON_ID: + tempCoverVariable = toggleBit(tempCoverVariable, IMPORT_EXPORT_MASK); + } + return tempCoverVariable; + } + + private boolean getClickable(int id) { + boolean canBeClicked = false; + switch (id) { + case PUBLIC_BUTTON_ID: + canBeClicked = testBit(coverVariable, PUBLIC_PRIVATE_MASK); + break; + case PRIVATE_BUTTON_ID: + canBeClicked = !testBit(coverVariable, PUBLIC_PRIVATE_MASK); + break; + case IMPORT_BUTTON_ID: + canBeClicked = testBit(coverVariable, IMPORT_EXPORT_MASK); + break; + case EXPORT_BUTTON_ID: + canBeClicked = !testBit(coverVariable, IMPORT_EXPORT_MASK); + } + return canBeClicked; + } + + @Override + public void applyTextBox(GT_GuiIntegerTextBox box) { + try { + String string = box.getText(); + int colorValue = (int) Long.parseLong(string.replaceFirst("#", ""), 16); + tag = new EnderLinkTag(new Color(colorValue, true), tag.getUUID()); + NetworkDispatcher.INSTANCE.sendToServer(new EnderLinkCoverMessage.EnderLinkCoverUpdate(tag, (IFluidHandler) tile)); + } catch (NumberFormatException ignored) { + } + resetColorField(); + } + + @Override + public void resetTextBox(GT_GuiIntegerTextBox box) { + //Solid White becomes: #FFFFFFFF + box.setText("#" + String.format("%08X", tag.getColorInt())); + } + + public void resetColorField() { + resetTextBox(colorField); + } + + private class GT_GuiIntegerHexTextBox extends GT_GuiIntegerTextBox { + public GT_GuiIntegerHexTextBox(IGuiScreen gui, int id, int x, int y, int width, int height) { + super(gui, id, x, y, width, height); + } + + @Override + public boolean validChar(char c, int key) { + boolean isValid; + if (getCursorPosition() == 0) { + isValid = c == '#'; + } else { + isValid = super.validChar(c, key) + || c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E' || c == 'F' + || c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f'; + } + return isValid; + } + } + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java index 2efe2f3cbc..a573ed740b 100644 --- a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java @@ -1,9 +1,7 @@ package com.github.technus.tectech.thing.cover; -import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple; -import com.github.technus.tectech.util.Vec3Impl; +import com.github.technus.tectech.mechanics.tesla.TeslaCoverConnection; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.EntityPlayer; @@ -11,9 +9,7 @@ import net.minecraft.entity.player.EntityPlayer; import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.*; import static ic2.api.info.Info.DMG_ELECTRIC; -public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior implements ITeslaConnectableSimple { - private IGregTechTileEntity IGT; - +public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior { public GT_Cover_TM_TeslaCoil() { } @@ -21,14 +17,10 @@ public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior implements ITeslaCon public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { //Only do stuff if we're on top and have power if (aSide == 1 || aTileEntity.getEUCapacity() > 0) { - //Pull IGT onto the outside, should only execute first tick - if (IGT == null) { - IGT = aTileEntity.getIGregTechTileEntityOffset(0, 0, 0); - } //Makes sure we're on the list - teslaNodeSet.add(this); + teslaSimpleNodeSetAdd(new TeslaCoverConnection(aTileEntity.getIGregTechTileEntityOffset(0, 0, 0), + getTeslaReceptionCapability())); } - return super.doCoverThings(aSide, aInputRedstone, aCoverID, aCoverVariable, aTileEntity, aTimer); } @@ -57,39 +49,7 @@ public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior implements ITeslaCon return 200; } - @Override public byte getTeslaReceptionCapability() { return 2; } - - @Override - public float getTeslaReceptionCoefficient() { - return 1; - } - - @Override - public boolean isTeslaReadyToReceive() { - return true; - } - - @Override - public long getTeslaStoredEnergy() { - return IGT.getStoredEU(); - } - - @Override - public Vec3Impl getTeslaPosition() { - return new Vec3Impl(IGT); - } - - @Override - public Integer getTeslaDimension() { - return IGT.getWorld().provider.dimensionId; - } - - @Override - public boolean teslaInjectEnergy(long teslaVoltageInjected) { - //Same as in the microwave transmitters, this does not account for amp limits - return IGT.injectEnergyUnits((byte) 1, teslaVoltageInjected, 1L) > 0L; - } } diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil_Ultimate.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil_Ultimate.java index 028ac3a4d6..3417d7ae20 100644 --- a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil_Ultimate.java +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil_Ultimate.java @@ -31,8 +31,7 @@ public class GT_Cover_TM_TeslaCoil_Ultimate extends GT_Cover_TM_TeslaCoil { public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { return true; } - - @Override + public byte getTeslaReceptionCapability() { return 1; } diff --git a/src/main/java/com/github/technus/tectech/thing/item/EnderFluidLinkCover.java b/src/main/java/com/github/technus/tectech/thing/item/EnderFluidLinkCover.java new file mode 100644 index 0000000000..57a882ec26 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/item/EnderFluidLinkCover.java @@ -0,0 +1,47 @@ +package com.github.technus.tectech.thing.item; + +import com.github.technus.tectech.util.CommonValues; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import java.util.List; + +import static com.github.technus.tectech.Reference.MODID; +import static com.github.technus.tectech.thing.CustomItemList.enderLinkFluidCover; +import static net.minecraft.util.StatCollector.translateToLocal; + +public final class EnderFluidLinkCover extends Item { + public static EnderFluidLinkCover INSTANCE; + + private EnderFluidLinkCover() { + setHasSubtypes(true); + setUnlocalizedName("tm.enderfluidlinkcover"); + setTextureName(MODID + ":itemEnderFluidLinkCover"); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer ep, List aList, boolean boo) { + aList.add(CommonValues.BASS_MARK); + aList.add(translateToLocal("item.tm.enderfluidlinkcover.desc.0"));//Ender-Fluid-Enables Machines! + aList.add(EnumChatFormatting.BLUE + translateToLocal("item.tm.enderfluidlinkcover.desc.1"));//Use on any side of a fluid tank to link it to the Ender + aList.add(EnumChatFormatting.BLUE + translateToLocal("item.tm.enderfluidlinkcover.desc.2"));//Ender Tanks so are laggy -Bot from the Chads of NH + } + + public static void run() { + INSTANCE = new EnderFluidLinkCover(); + GameRegistry.registerItem(INSTANCE, INSTANCE.getUnlocalizedName()); + enderLinkFluidCover.set(INSTANCE); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + itemIcon = iconRegister.registerIcon(getIconString()); + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index 93f6e50c5a..580e6195ad 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -8,6 +8,7 @@ import com.github.technus.tectech.mechanics.spark.ThaumSpark; import com.github.technus.tectech.mechanics.structure.Structure; import com.github.technus.tectech.mechanics.structure.adders.IHatchAdder; import com.github.technus.tectech.mechanics.tesla.ITeslaConnectable; +import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Capacitor; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti; @@ -19,6 +20,9 @@ import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedExtendedFacingTexture; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.util.Vec3Impl; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.MultimapBuilder; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.Materials; @@ -35,6 +39,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; +import java.util.HashSet; import static com.github.technus.tectech.mechanics.structure.Structure.adders; import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.*; @@ -47,6 +52,11 @@ import static java.lang.Math.*; import static net.minecraft.util.StatCollector.translateToLocal; public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_MultiblockBase_EM implements IConstructable, ITeslaConnectable { + //Interface fields + private final Multimap<Integer, ITeslaConnectableSimple> teslaNodeMap = MultimapBuilder.treeKeys().linkedListValues().build(); + private final HashSet<ThaumSpark> sparkList = new HashSet<>(); + private int sparkCount = 10; + //region variables private static final int transferRadiusTowerFromConfig = TecTech.configTecTech.TESLA_MULTI_RANGE_TOWER;//Default is 32 private static final int transferRadiusTransceiverFromConfig = TecTech.configTecTech.TESLA_MULTI_RANGE_TRANSCEIVER;//Default is 16 @@ -73,8 +83,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private final ArrayList<GT_MetaTileEntity_Hatch_Capacitor> eCapacitorHatches = new ArrayList<>(); //Capacitor hatches which determine the max voltage tier and count of amps - private int sortTime = 0; //Scan timer used for tesla search intervals - private long energyCapacity = 0; //Total energy storage limited by capacitors private long outputVoltageMax = 0; //Tesla voltage output limited by capacitors private int vTier = -1; //Tesla voltage tier limited by capacitors @@ -451,13 +459,12 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock @Override public void onRemoval() { super.onRemoval(); - if (this.getBaseMetaTileEntity().isClientSide()) { - return; - } - teslaNodeSet.remove(this); - for (GT_MetaTileEntity_Hatch_Capacitor cap : eCapacitorHatches) { - if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { - cap.getBaseMetaTileEntity().setActive(false); + if (!getBaseMetaTileEntity().isClientSide()) { + teslaSimpleNodeSetRemove(this); + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCapacitorHatches) { + if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { + cap.getBaseMetaTileEntity().setActive(false); + } } } } @@ -528,7 +535,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); energyCapacity = aNBT.getLong("eEnergyCapacity"); - teslaNodeSet.add(this); + teslaSimpleNodeSetAdd(this); } @Override @@ -548,14 +555,13 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock public void onFirstTick_EM(IGregTechTileEntity aBaseMetaTileEntity) { super.onFirstTick_EM(aBaseMetaTileEntity); if (!aBaseMetaTileEntity.isClientSide()) { - teslaNodeSet.add(this); + teslaSimpleNodeSetAdd(this); + generateTeslaNodeMap(this); } } @Override public boolean onRunningTick(ItemStack aStack) { - IGregTechTileEntity mte = getBaseMetaTileEntity(); - //Hysteresis based ePowerPass setting float energyFrac = (float) getEUVar() / energyCapacity; @@ -569,15 +575,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock ePowerPass = false; } - //Create the teslaNodeMap - if (sortTime == sortTimeMinSetting.get()) { - sortTime = 0; - sortTimeDisplay.updateStatus(); - generateTeslaNodeMap(this); - } - sortTime++; - sortTimeDisplay.set(sortTime); - //Power Limit Settings if (outputVoltageSetting.get() > 0) { outputVoltage = min(outputVoltageMax, (long) outputVoltageSetting.get()); @@ -598,22 +595,24 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock transferRadiusTransceiverDisplay.set(transferRadiusTower * 2); transferRadiusCoverUltimateDisplay.set(transferRadiusTower); - //Clean the teslaNodeMap - cleanTeslaNodeMap(this); - //Power transfer outputCurrentDisplay.set(powerTeslaNodeMap(this)); - if (!sparkList.isEmpty()) { - NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), - mte.getWorld().provider.dimensionId, - posTop.get0(), - posTop.get1(), - posTop.get2(), - 256); + //Randomly send all the sparks out once every 3 to 5 seconds + sparkCount--; + if (sparkCount == 0){ + IGregTechTileEntity mte = getBaseMetaTileEntity(); + sparkCount = 10; + if(!sparkList.isEmpty()){ + NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), + mte.getWorld().provider.dimensionId, + mte.getXCoord(), + mte.getYCoord(), + mte.getZCoord(), + 256); + sparkList.clear(); + } } - sparkList.clear(); - return true; } @@ -702,6 +701,16 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock } @Override + public Multimap<Integer, ITeslaConnectableSimple> getTeslaNodeMap() { + return teslaNodeMap; + } + + @Override + public HashSet<ThaumSpark> getSparkList() { + return sparkList; + } + + @Override public byte getTeslaTransmissionCapability() { return 1; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index 388a253b27..8c3fb9410b 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -1,17 +1,19 @@ package com.github.technus.tectech.thing.metaTileEntity.single;
import com.github.technus.tectech.mechanics.tesla.ITeslaConnectable;
+import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple;
import com.github.technus.tectech.util.CommonValues;
import com.github.technus.tectech.TecTech;
import com.github.technus.tectech.loader.NetworkDispatcher;
import com.github.technus.tectech.mechanics.spark.RendererMessage;
import com.github.technus.tectech.mechanics.spark.ThaumSpark;
-import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_TM_teslaCoil;
import com.github.technus.tectech.util.Util;
import com.github.technus.tectech.util.Vec3Impl;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.MultimapBuilder;
import eu.usrv.yamcore.auxiliary.PlayerChatHelper;
import gregtech.api.interfaces.ITexture;
-import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicBatteryBuffer;
@@ -23,6 +25,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.reflect.FieldUtils;
import java.util.Arrays;
+import java.util.HashSet;
import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.*;
import static com.github.technus.tectech.util.CommonValues.V;
@@ -32,12 +35,14 @@ import static net.minecraft.util.StatCollector.translateToLocal; import static net.minecraft.util.StatCollector.translateToLocalFormatted;
public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer implements ITeslaConnectable {
+ //Interface fields
+ private final Multimap<Integer, ITeslaConnectableSimple> teslaNodeMap = MultimapBuilder.treeKeys().linkedListValues().build();
+ private final HashSet<ThaumSpark> sparkList = new HashSet<>();
+ private int sparkCount = 10;
+
private final static int transferRadiusMax = TecTech.configTecTech.TESLA_SINGLE_RANGE;//Default is 20
private final static int perBlockLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_PER_BLOCK;//Default is 1
private final static float overDriveLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_FACTOR_OVERDRIVE;//Default is 0.25F
-
- private byte sparkCount = 0;
-
private final static int transferRadiusMin = 4;//Minimum user configurable
private int transferRadius = transferRadiusMax;//Default transferRadius setting
@@ -55,9 +60,6 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB private String clientLocale = "en_US";
- private int sortTime = 0;//Sorting tick counter
- private final static int sortTimeMax = 100;//Sorting tick counter limit, so we only sort once every 5 seconds
-
public GT_MetaTileEntity_TeslaCoil(int aID, String aName, String aNameRegional, int aTier, int aSlotCount) {
super(aID, aName, aNameRegional, aTier, "", aSlotCount);
Util.setTier(aTier, this);
@@ -179,51 +181,12 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB return new GT_MetaTileEntity_TeslaCoil(mName, mTier, mDescription, mTextures, mInventory.length);
}
- private void thaumLightning(IGregTechTileEntity mte, IGregTechTileEntity node) {
- int x = mte.getXCoord();
- int y = mte.getYCoord();
- int z = mte.getZCoord();
-
- byte xR;
- byte yR;
- byte zR;
-
- IMetaTileEntity nodeInside = node.getMetaTileEntity();
- if (nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil) {
- GT_MetaTileEntity_TM_teslaCoil nodeTesla = (GT_MetaTileEntity_TM_teslaCoil) nodeInside;
- xR = (byte) (nodeTesla.posTop.get0() - x);
- yR = (byte) (nodeTesla.posTop.get1() - y);
- zR = (byte) (nodeTesla.posTop.get2() - z);
- } else {
- xR = (byte) (node.getXCoord() - x);
- yR = (byte) (node.getYCoord() - y);
- zR = (byte) (node.getZCoord() - z);
- }
-
- int wID = mte.getWorld().provider.dimensionId;
-
- sparkList.add(new ThaumSpark(x, y, z, xR, yR, zR, wID));
- }
-
- private long[] getOutputVoltage(long outputVoltage, int distance, boolean overDriveToggle) {
- long outputVoltageInjectable;
- long outputVoltageConsumption;
-
- if (overDriveToggle) {
- outputVoltageInjectable = outputVoltage;
- outputVoltageConsumption = outputVoltage + (distance * perBlockLoss) + (long) Math.round(overDriveLoss * outputVoltage);
- } else {
- outputVoltageInjectable = outputVoltage - (distance * perBlockLoss);
- outputVoltageConsumption = outputVoltage;
- }
- return new long[]{outputVoltageInjectable, outputVoltageConsumption};
- }
-
@Override
public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
super.onFirstTick(aBaseMetaTileEntity);
if (!aBaseMetaTileEntity.isClientSide()) {
- teslaNodeSet.add(this);
+ teslaSimpleNodeSetAdd(this);
+ generateTeslaNodeMap(this);
}
}
@@ -231,14 +194,14 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB public void onRemoval() {
super.onRemoval();
if (!this.getBaseMetaTileEntity().isClientSide()) {
- teslaNodeSet.remove(this);
+ teslaSimpleNodeSetRemove(this);
}
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
- teslaNodeSet.add(this);
+ teslaSimpleNodeSetAdd(this);
}
@Override
@@ -260,41 +223,36 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB powerPassToggle = false;
}
- //Create the teslaNodeMap
- if (sortTime == sortTimeMax) {
- sortTime = 0;
- generateTeslaNodeMap(this);
- }
- sortTime++;
-
//Send Power
powerTeslaNodeMap(this);
- sparkCount++;
- if (sparkCount == 60 && !sparkList.isEmpty()) {
- sparkCount = 0;
- NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList),
- aBaseMetaTileEntity.getWorld().provider.dimensionId,
- aBaseMetaTileEntity.getXCoord(),
- aBaseMetaTileEntity.getYCoord(),
- aBaseMetaTileEntity.getZCoord(),
- 256);
+ //Randomly send all the sparks out once every 3 to 5 seconds
+ sparkCount--;
+ if (sparkCount == 0){
+ sparkCount = 10;
+ if(!sparkList.isEmpty()){
+ NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList),
+ aBaseMetaTileEntity.getWorld().provider.dimensionId,
+ aBaseMetaTileEntity.getXCoord(),
+ aBaseMetaTileEntity.getYCoord(),
+ aBaseMetaTileEntity.getZCoord(),
+ 256);
+ sparkList.clear();
+ }
}
- sparkList.clear();
}
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
- if (aBaseMetaTileEntity.isClientSide()) {
- return true;
- }
- try {
- EntityPlayerMP player = (EntityPlayerMP) aPlayer;
- clientLocale = (String) FieldUtils.readField(player, "translator", true);
- } catch (Exception e) {
- clientLocale = "en_US";
+ if (aBaseMetaTileEntity.isServerSide()) {
+ try {
+ EntityPlayerMP player = (EntityPlayerMP) aPlayer;
+ clientLocale = (String) FieldUtils.readField(player, "translator", true);
+ } catch (Exception e) {
+ clientLocale = "en_US";
+ }
+ aBaseMetaTileEntity.openGUI(aPlayer);
}
- aBaseMetaTileEntity.openGUI(aPlayer);
return true;
}
@@ -309,6 +267,16 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB }
@Override
+ public Multimap<Integer, ITeslaConnectableSimple> getTeslaNodeMap() {
+ return teslaNodeMap;
+ }
+
+ @Override
+ public HashSet<ThaumSpark> getSparkList() {
+ return sparkList;
+ }
+
+ @Override
public byte getTeslaTransmissionCapability() {
return 2;
}
diff --git a/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png Binary files differnew file mode 100644 index 0000000000..010bc0888d --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png diff --git a/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png.mcmeta new file mode 100644 index 0000000000..5e86a7cd5f --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation":{ + "frametime":8 + } +}
\ No newline at end of file diff --git a/src/main/resources/assets/tectech/lang/en_US.lang b/src/main/resources/assets/tectech/lang/en_US.lang index b81b865b22..9f49d692b8 100644 --- a/src/main/resources/assets/tectech/lang/en_US.lang +++ b/src/main/resources/assets/tectech/lang/en_US.lang @@ -87,6 +87,11 @@ item.tm.teslaCover.desc.4=Who the hell uses cables anyway? item.tm.teslaStaff.name=Tesla Staff item.tm.teslaStaff.desc=Power of the gods, at the whim of a mortal! +item.tm.enderfluidlinkcover.name=Ender Fluid Link Cover +item.tm.enderfluidlinkcover.desc.0=Ender-Fluid-Enables Machines! +item.tm.enderfluidlinkcover.desc.1=Use on any side of a fluid tank to link it to the Ender +item.tm.enderfluidlinkcover.desc.2=Ender Tanks so are laggy -Bot from the Chads of NH + #Death Messages death.attack.microwaving=%1$s was dehydrated by radiation. death.attack.microwaving.player=%1$s was dehydrated by radiation while fighting %2$s. diff --git a/src/main/resources/assets/tectech/lang/zh_CN.lang b/src/main/resources/assets/tectech/lang/zh_CN.lang index cfa23fb88d..c01c8f2757 100644 --- a/src/main/resources/assets/tectech/lang/zh_CN.lang +++ b/src/main/resources/assets/tectech/lang/zh_CN.lang @@ -42,7 +42,7 @@ item.em.constructable.desc.0=触发可构造界面 item.em.constructable.desc.1=显示多方块结构细节, item.em.constructable.desc.2=只可在多方块控制器上使用. item.em.constructable.desc.3=(在创造模式下潜行右键可直接构造) -item.em.constructable.desc.4=数量影响等级/模式/类型 +item.em.constructable.desc.4=堆叠数量影响等级/模式/类型 item.em.EuMeterGT.name=GT EU电表 item.em.EuMeterGT.desc.0=测量EU相关的基本内容 @@ -64,6 +64,8 @@ item.tm.teslaCoilCapacitor.1.name=MV特斯拉电容 item.tm.teslaCoilCapacitor.2.name=HV特斯拉电容 item.tm.teslaCoilCapacitor.3.name=EV特斯拉电容 item.tm.teslaCoilCapacitor.4.name=IV特斯拉电容 +item.tm.teslaCoilCapacitor.5.name=LuV特斯拉电容 +item.tm.teslaCoilCapacitor.6.name=ZPM特斯拉电容 item.tm.teslaCoilCapacitor.desc.0=存储量: item.tm.teslaCoilCapacitor.desc.1=EU;充能速度: item.tm.teslaCoilCapacitor.desc.2=把这个破碎的东西浸入某种辛辣的水中! @@ -402,12 +404,12 @@ gt.blockmachines.hatch.certain.tier.10.name=未定元解析器 X gt.blockmachines.hatch.certain.desc.0=你真的很确定吗? gt.blockmachines.hatch.certain.desc.1=盒子里的薛定谔方程 -gt.blockmachines.hatch.datain.tier.07.name=副光学连接端口 +gt.blockmachines.hatch.datain.tier.07.name=副光学接口 gt.blockmachines.hatch.datain.desc.0=多方块机器的数据输入 gt.blockmachines.hatch.datain.desc.1=高速光纤接口 gt.blockmachines.hatch.datain.desc.2=启用前必须涂色 -gt.blockmachines.hatch.dataout.tier.07.name=主光学连接端口 +gt.blockmachines.hatch.dataout.tier.07.name=主光学接口 gt.blockmachines.hatch.dataout.desc.0=多方块机器的数据输出 gt.blockmachines.hatch.dataout.desc.1=高速光纤接口 gt.blockmachines.hatch.dataout.desc.2=启用前必须涂色 @@ -518,6 +520,7 @@ gt.blockcasingsBA0.2.name=HV超导初级特斯拉绕组 gt.blockcasingsBA0.3.name=EV超导初级特斯拉绕组 gt.blockcasingsBA0.4.name=IV超导初级特斯拉绕组 gt.blockcasingsBA0.5.name=LuV超导初级特斯拉绕组 +gt.blockcasingsBA0.9.name=ZPM超导初级特斯拉绕组 gt.blockcasingsBA0.0.desc.0=最高电圧 gt.blockcasingsBA0.0.desc.1=有的人称这为神迹,另一些人把这叫做物理. gt.blockcasingsBA0.6.name=特斯拉基座机械方块 @@ -575,12 +578,12 @@ gt.blockmachines.multimachine.tm.teslaCoil.cfgo.7=充能进度显示 gt.blockmachines.multimachine.tm.teslaCoil.cfgo.8=扫描时间显示 gt.blockmachines.multimachine.em.switch.name=QoS网络交换机 -gt.blockmachines.multimachine.em.switch.hint=1 - 基础仓室、光学连接端口或电子计算机机械方块 +gt.blockmachines.multimachine.em.switch.hint=1 - 基础仓室、光学接口或电子计算机机械方块 gt.blockmachines.multimachine.em.switch.desc.0=用户控制的计算力路由 gt.blockmachines.multimachine.em.switch.desc.1=服务质量是必须的 gt.blockmachines.multimachine.em.computer.name=量子计算机 -gt.blockmachines.multimachine.em.computer.hint.0=1 - 基础仓室、光学连接端口或电子计算机机械方块 +gt.blockmachines.multimachine.em.computer.hint.0=1 - 基础仓室、光学接口或电子计算机机械方块 gt.blockmachines.multimachine.em.computer.hint.1=2 - 计算机箱或进阶电子计算机械方块 gt.blockmachines.multimachine.em.computer.desc=你需要它来处理上面的这串数字 gt.blockmachines.multimachine.em.computer.cfgi.0=超频比 @@ -639,7 +642,7 @@ gt.blockmachines.multimachine.em.scanner.desc.0=它是如何存在的? gt.blockmachines.multimachine.em.scanner.desc.1=我!不!知!道!(至少暂时是这样) gt.blockmachines.multimachine.em.research.name=研究站 -gt.blockmachines.multimachine.em.research.hint.0=1 - 基础仓室、光学连接端口或电子计算机械方块 +gt.blockmachines.multimachine.em.research.hint.0=1 - 基础仓室、光学接口或电子计算机械方块 gt.blockmachines.multimachine.em.research.hint.1=2 - 物品固定容器 gt.blockmachines.multimachine.em.research.desc.0=哲学家们甚至... gt.blockmachines.multimachine.em.research.desc.1=从来不曾梦见它! @@ -762,7 +765,7 @@ gt.blockmachines.machine.tt.tesla.desc.1=富人的闪电洪炉 gt.blockmachines.debug.tt.pollutor.name=Debug污染生成机 gt.blockmachines.debug.tt.pollutor.desc.0=该死的genny破产了! gt.blockmachines.debug.tt.pollutor.desc.1=无限的生产者/消费者 -gt.blockmachines.debug.tt.pollutor.desc.2=我只是想要一个? +gt.blockmachines.debug.tt.pollutor.desc.2=因为我需要一个? gt.blockmachines.debug.tt.data.name=Debug数据仓 gt.blockmachines.debug.tt.data.desc.0=量子数据输出 gt.blockmachines.debug.tt.data.desc.1=高速光纤接口 @@ -811,7 +814,7 @@ tt.keyword.Efficiency=效率 #Button that allows to pass power to other machines tt.keyword.PowerPass=导能 #Button that vents EM -tt.keyword.SafeVoid=安全罩 +tt.keyword.SafeVoid=安全销毁 tt.keyword.Parametrizer=参数仪 tt.keyword.Value=值 tt.keyword.Input=输入 @@ -823,7 +826,7 @@ tt.keyword.PacketHistory=封包记录 tt.keyphrase.LIFE_TIME=寿命 tt.keyphrase.CARRIES_COLOR=有色 -tt.keyphrase.提示方块:Details=提示细节 +tt.keyphrase.Hint_Details=提示细节 tt.keyphrase.At_current_energy_level=在当前能级 #Used when 0 Elemental Matter Stacks tt.keyphrase.No_Stacks=空 diff --git a/src/main/resources/assets/tectech/textures/items/itemEnderFluidLinkCover.png b/src/main/resources/assets/tectech/textures/items/itemEnderFluidLinkCover.png Binary files differnew file mode 100644 index 0000000000..201f7e4090 --- /dev/null +++ b/src/main/resources/assets/tectech/textures/items/itemEnderFluidLinkCover.png |