From 45207ae2bbc5324c355d9a06cf8a83ac3931d15e Mon Sep 17 00:00:00 2001 From: Calclavia Date: Mon, 10 Mar 2014 06:22:37 +0800 Subject: [PATCH] Quantum gates now transport fluids! --- .../electrical/Electrical.java | 2 +- .../quantum/gate/IQuantumGate.java | 8 +- .../quantum/gate/ItemQuantumGlyph.java | 2 +- .../quantum/gate/PartQuantumGlyph.java | 95 +++++++++++++++++-- .../quantum/gate/QuantumGateManager.java | 2 +- .../quantum/gate/TraitQuantumGate.java | 62 +++++++++++- .../core/ResonantInduction.java | 2 +- 7 files changed, 156 insertions(+), 17 deletions(-) diff --git a/electrical/src/main/java/resonantinduction/electrical/Electrical.java b/electrical/src/main/java/resonantinduction/electrical/Electrical.java index 02cad60b6..d32493f60 100644 --- a/electrical/src/main/java/resonantinduction/electrical/Electrical.java +++ b/electrical/src/main/java/resonantinduction/electrical/Electrical.java @@ -52,7 +52,7 @@ import cpw.mods.fml.common.registry.GameRegistry; * @author Calclavia * */ -@Mod(modid = Electrical.ID, name = Electrical.NAME, version = Reference.VERSION, dependencies = "before:ThermalExpansion;after:ResonantInduction|Mechanical;required-after:" + ResonantInduction.ID) +@Mod(modid = Electrical.ID, name = Electrical.NAME, version = Reference.VERSION, dependencies = "before:ThermalExpansion;before:Mekanism;after:ResonantInduction|Mechanical;required-after:" + ResonantInduction.ID) @NetworkMod(channels = Reference.CHANNEL, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class) public class Electrical { diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/IQuantumGate.java b/electrical/src/main/java/resonantinduction/quantum/gate/IQuantumGate.java index 68777b47a..299a35b71 100644 --- a/electrical/src/main/java/resonantinduction/quantum/gate/IQuantumGate.java +++ b/electrical/src/main/java/resonantinduction/quantum/gate/IQuantumGate.java @@ -1,7 +1,9 @@ package resonantinduction.quantum.gate; -import net.minecraft.entity.Entity; import icbm.api.IBlockFrequency; +import net.minecraft.entity.Entity; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.IFluidHandler; /** * Only TileEntities should implement this. @@ -9,7 +11,9 @@ import icbm.api.IBlockFrequency; * @author Calclavia * */ -public interface IQuantumGate extends IBlockFrequency +public interface IQuantumGate extends IBlockFrequency, IFluidHandler { public void transport(Entity entity); + + FluidTank getQuantumTank(); } diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/ItemQuantumGlyph.java b/electrical/src/main/java/resonantinduction/quantum/gate/ItemQuantumGlyph.java index f0286cf93..9c66b87a1 100644 --- a/electrical/src/main/java/resonantinduction/quantum/gate/ItemQuantumGlyph.java +++ b/electrical/src/main/java/resonantinduction/quantum/gate/ItemQuantumGlyph.java @@ -68,7 +68,7 @@ public class ItemQuantumGlyph extends JItemMultiPart implements IHighlight } else { - pos.offset(side); + //pos.offset(side); } } diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/PartQuantumGlyph.java b/electrical/src/main/java/resonantinduction/quantum/gate/PartQuantumGlyph.java index 0ca98a30d..9e27da775 100644 --- a/electrical/src/main/java/resonantinduction/quantum/gate/PartQuantumGlyph.java +++ b/electrical/src/main/java/resonantinduction/quantum/gate/PartQuantumGlyph.java @@ -4,6 +4,7 @@ import icbm.api.IBlockFrequency; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Set; @@ -14,6 +15,14 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; +import net.minecraftforge.fluids.IFluidTank; import resonantinduction.electrical.Electrical; import universalelectricity.api.vector.VectorWorld; import codechicken.lib.data.MCDataInput; @@ -60,7 +69,9 @@ public class PartQuantumGlyph extends JCuboidPart implements TSlottedPart, JNorm public void onWorldJoin() { if (((IQuantumGate) tile()).getFrequency() != -1) + { FrequencyGrid.instance().register((IQuantumGate) tile()); + } } @Override @@ -134,24 +145,25 @@ public class PartQuantumGlyph extends JCuboidPart implements TSlottedPart, JNorm @Override public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack) { - if (!world().isRemote) + if (player.isSneaking()) { - if (player.isSneaking()) + if (!world().isRemote) { transport(player); } - else - { - int frequency = ((IBlockFrequency) tile()).getFrequency(); + } + else + { + int frequency = ((IBlockFrequency) tile()).getFrequency(); - if (frequency > -1) + if (frequency > -1) + { + if (!world().isRemote) { + System.out.println(getQuantumTank()); player.addChatMessage("Quantum Gate Frequency: " + frequency); } - else - { - player.addChatMessage("Quantum Gate not set up."); - } + return false; } } @@ -254,4 +266,67 @@ public class PartQuantumGlyph extends JCuboidPart implements TSlottedPart, JNorm } + /** + * Synced Fluid + */ + static final HashMap quantumTanks = new HashMap(); + + @Override + public FluidTank getQuantumTank() + { + int frequency = ((IQuantumGate) tile()).getFrequency(); + + if (frequency > -1) + { + if (!quantumTanks.containsKey(frequency)) + quantumTanks.put(frequency, new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)); + + return quantumTanks.get(frequency); + } + + return null; + } + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) + { + if (((IQuantumGate) tile()).getFrequency() != -1) + return getQuantumTank().fill(resource, doFill); + return 0; + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) + { + if (((IQuantumGate) tile()).getFrequency() != -1) + return getQuantumTank().drain(resource.amount, doDrain); + return null; + } + + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + if (((IQuantumGate) tile()).getFrequency() != -1) + return getQuantumTank().drain(maxDrain, doDrain); + return null; + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) + { + return ((IQuantumGate) tile()).getFrequency() != -1; + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) + { + return ((IQuantumGate) tile()).getFrequency() != -1; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) + { + return new FluidTankInfo[] { getQuantumTank().getInfo() }; + } + } diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/QuantumGateManager.java b/electrical/src/main/java/resonantinduction/quantum/gate/QuantumGateManager.java index de9d3462a..9ac4bd09a 100644 --- a/electrical/src/main/java/resonantinduction/quantum/gate/QuantumGateManager.java +++ b/electrical/src/main/java/resonantinduction/quantum/gate/QuantumGateManager.java @@ -32,7 +32,7 @@ public class QuantumGateManager if (currentEntity instanceof EntityPlayerMP) { - if (playerCooldown.get(((EntityPlayerMP) currentEntity).username) == null || (System.currentTimeMillis() - playerCooldown.get(((EntityPlayerMP) currentEntity).username) > 2000)) + if (playerCooldown.get(((EntityPlayerMP) currentEntity).username) == null || (System.currentTimeMillis() - playerCooldown.get(((EntityPlayerMP) currentEntity).username) > 1000)) { EntityPlayerMP player = (EntityPlayerMP) currentEntity; diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/TraitQuantumGate.java b/electrical/src/main/java/resonantinduction/quantum/gate/TraitQuantumGate.java index 208ad4250..546cbe6ef 100644 --- a/electrical/src/main/java/resonantinduction/quantum/gate/TraitQuantumGate.java +++ b/electrical/src/main/java/resonantinduction/quantum/gate/TraitQuantumGate.java @@ -10,16 +10,40 @@ import mffs.api.fortron.FrequencyGrid; import net.minecraft.entity.Entity; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidTankInfo; import universalelectricity.api.vector.VectorWorld; import codechicken.multipart.TMultiPart; import codechicken.multipart.TileMultipart; public class TraitQuantumGate extends TileMultipart implements IQuantumGate { + public PartQuantumGlyph get() + { + for (TMultiPart part : jPartList()) + { + if (part instanceof PartQuantumGlyph) + { + return ((PartQuantumGlyph) part); + } + } + + return null; + } + + @Override + public FluidTank getQuantumTank() + { + return get().getQuantumTank(); + } + @Override public void transport(Entity entity) { - + get().transport(entity); } @Override @@ -49,4 +73,40 @@ public class TraitQuantumGate extends TileMultipart implements IQuantumGate } + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) + { + return get().fill(from, resource, doFill); + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) + { + return get().drain(from, resource, doDrain); + } + + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + return get().drain(from, maxDrain, doDrain); + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) + { + return get().canFill(from, fluid); + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) + { + return get().canDrain(from, fluid); + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) + { + return get().getTankInfo(from); + } + } diff --git a/src/main/java/resonantinduction/core/ResonantInduction.java b/src/main/java/resonantinduction/core/ResonantInduction.java index 945c318ea..aaebbe26f 100644 --- a/src/main/java/resonantinduction/core/ResonantInduction.java +++ b/src/main/java/resonantinduction/core/ResonantInduction.java @@ -47,7 +47,7 @@ import cpw.mods.fml.common.registry.GameRegistry; * * @author Calclavia */ -@Mod(modid = ResonantInduction.ID, name = ResonantInduction.NAME, version = Reference.VERSION, dependencies = "required-after:ForgeMultipart@[1.0.0.244,);required-after:CalclaviaCore;before:IC2") +@Mod(modid = ResonantInduction.ID, name = ResonantInduction.NAME, version = Reference.VERSION, dependencies = "required-after:ForgeMultipart@[1.0.0.244,);required-after:CalclaviaCore;before:ThermalExpansion;before:Mekanism") @NetworkMod(channels = Reference.CHANNEL, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class) @ModstatInfo(prefix = "resonantin") public class ResonantInduction