From 0194b54cd206dccb79ebd83b07287c50c43f360e Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Tue, 8 Sep 2015 20:37:18 -0400 Subject: [PATCH] Update CoFH API to 1.0.13 --- src/main/java/cofh/api/CoFHAPIProps.java | 2 +- .../cofh/api/transport/IEnderDestination.java | 21 ++++ .../api/transport/IEnderEnergyHandler.java | 8 +- .../api/transport/IEnderFluidHandler.java | 8 +- .../cofh/api/transport/IEnderItemHandler.java | 10 +- .../java/cofh/api/transport/IItemDuct.java | 6 +- .../api/transport/RegistryEnderAttuned.java | 118 ++++++++++++++++-- 7 files changed, 148 insertions(+), 25 deletions(-) create mode 100644 src/main/java/cofh/api/transport/IEnderDestination.java diff --git a/src/main/java/cofh/api/CoFHAPIProps.java b/src/main/java/cofh/api/CoFHAPIProps.java index 775d8d2..7f000d4 100644 --- a/src/main/java/cofh/api/CoFHAPIProps.java +++ b/src/main/java/cofh/api/CoFHAPIProps.java @@ -6,6 +6,6 @@ public class CoFHAPIProps { } - public static final String VERSION = "1.7.10R1.0.3"; + public static final String VERSION = "1.7.10R1.0.13"; } diff --git a/src/main/java/cofh/api/transport/IEnderDestination.java b/src/main/java/cofh/api/transport/IEnderDestination.java new file mode 100644 index 0000000..f3042a7 --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderDestination.java @@ -0,0 +1,21 @@ +package cofh.api.transport; + +public interface IEnderDestination extends IEnderAttuned { + + public boolean isNotValid(); + + public int x(); + + public int y(); + + public int z(); + + public int dimension(); + + public int getDestination(); + + public boolean setDestination(int frequency); + + public boolean clearDestination(); + +} diff --git a/src/main/java/cofh/api/transport/IEnderEnergyHandler.java b/src/main/java/cofh/api/transport/IEnderEnergyHandler.java index 0886be7..892a5c6 100644 --- a/src/main/java/cofh/api/transport/IEnderEnergyHandler.java +++ b/src/main/java/cofh/api/transport/IEnderEnergyHandler.java @@ -2,9 +2,9 @@ package cofh.api.transport; /** * This interface is implemented on Ender Attuned objects which can receive Energy (Redstone Flux). - * + * * @author King Lemming - * + * */ public interface IEnderEnergyHandler extends IEnderAttuned { @@ -15,7 +15,7 @@ public interface IEnderEnergyHandler extends IEnderAttuned { /** * This should be checked to see if the Ender Attuned object can currently receive energy (Redstone Flux). - * + * * Note: In practice, this can (and should) be used to ensure that something does not send to itself. */ boolean canReceiveEnergy(); @@ -23,7 +23,7 @@ public interface IEnderEnergyHandler extends IEnderAttuned { /** * This tells the Ender Attuned object to receive energy. This returns the amount remaining, *not* the amount received - a return of 0 means that all energy * was received! - * + * * @param energy * Amount of energy to be received. * @param simulate diff --git a/src/main/java/cofh/api/transport/IEnderFluidHandler.java b/src/main/java/cofh/api/transport/IEnderFluidHandler.java index 3927fe1..2f509e8 100644 --- a/src/main/java/cofh/api/transport/IEnderFluidHandler.java +++ b/src/main/java/cofh/api/transport/IEnderFluidHandler.java @@ -4,9 +4,9 @@ import net.minecraftforge.fluids.FluidStack; /** * This interface is implemented on Ender Attuned objects which can receive Fluid. - * + * * @author King Lemming - * + * */ public interface IEnderFluidHandler extends IEnderAttuned { @@ -17,7 +17,7 @@ public interface IEnderFluidHandler extends IEnderAttuned { /** * This should be checked to see if the Ender Attuned object can currently receive a FluidStack. - * + * * Note: In practice, this can (and should) be used to ensure that something does not send to itself. */ boolean canReceiveFluid(); @@ -25,7 +25,7 @@ public interface IEnderFluidHandler extends IEnderAttuned { /** * This tells the Ender Attuned object to receive a FluidStack. This returns what remains of the original stack, *not* the amount received - a null return * means that the entire stack was received! - * + * * @param fluid * FluidStack to be received. * @param simulate diff --git a/src/main/java/cofh/api/transport/IEnderItemHandler.java b/src/main/java/cofh/api/transport/IEnderItemHandler.java index 2944a00..d5dad8f 100644 --- a/src/main/java/cofh/api/transport/IEnderItemHandler.java +++ b/src/main/java/cofh/api/transport/IEnderItemHandler.java @@ -4,9 +4,9 @@ import net.minecraft.item.ItemStack; /** * This interface is implemented on Ender Attuned objects which can receive Items. - * + * * @author King Lemming - * + * */ public interface IEnderItemHandler extends IEnderAttuned { @@ -17,7 +17,7 @@ public interface IEnderItemHandler extends IEnderAttuned { /** * This should be checked to see if the Ender Attuned object can currently receive an ItemStack. - * + * * Note: In practice, this can (and should) be used to ensure that something does not send to itself. */ boolean canReceiveItems(); @@ -25,10 +25,10 @@ public interface IEnderItemHandler extends IEnderAttuned { /** * This tells the Ender Attuned object to receive an ItemStack. This returns what remains of the original stack, *not* the amount received - a null return * means that the entire stack was received! - * + * * This function does not support simulation because Inventory manipulation in Minecraft is an absolute mess and it would be a computational liability to do * so. - * + * * @param item * ItemStack to be received. * @return An ItemStack representing how much is remaining. diff --git a/src/main/java/cofh/api/transport/IItemDuct.java b/src/main/java/cofh/api/transport/IItemDuct.java index 4c50c85..6733834 100644 --- a/src/main/java/cofh/api/transport/IItemDuct.java +++ b/src/main/java/cofh/api/transport/IItemDuct.java @@ -5,16 +5,16 @@ import net.minecraftforge.common.util.ForgeDirection; /** * This interface is implemented on ItemDucts. Use it to attempt to eject items into an entry point. - * + * * @author Zeldo Kavira, King Lemming - * + * */ public interface IItemDuct { /** * Insert an ItemStack into the IItemDuct. Will only accept items if there is a valid destination. This returns what is remaining of the original stack - a * null return means that the entire stack was accepted/routed! - * + * * @param from * Orientation the item is inserted from. * @param item diff --git a/src/main/java/cofh/api/transport/RegistryEnderAttuned.java b/src/main/java/cofh/api/transport/RegistryEnderAttuned.java index 0f91b21..9213d95 100644 --- a/src/main/java/cofh/api/transport/RegistryEnderAttuned.java +++ b/src/main/java/cofh/api/transport/RegistryEnderAttuned.java @@ -1,7 +1,5 @@ package cofh.api.transport; -import gnu.trove.map.hash.THashMap; - import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -10,23 +8,69 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.config.Configuration; public final class RegistryEnderAttuned { - public static Map>> inputItem = new THashMap>>(); - public static Map>> inputFluid = new THashMap>>(); - public static Map>> inputEnergy = new THashMap>>(); + public static Map>> inputItem = new HashMap>>(); + public static Map>> inputFluid = new HashMap>>(); + public static Map>> inputEnergy = new HashMap>>(); - public static Map>> outputItem = new THashMap>>(); - public static Map>> outputFluid = new THashMap>>(); - public static Map>> outputEnergy = new THashMap>>(); + public static Map>> outputItem = new HashMap>>(); + public static Map>> outputFluid = new HashMap>>(); + public static Map>> outputEnergy = new HashMap>>(); + + public static Map> outputTeleport = new HashMap>(); public static Configuration linkConf; public static Map clientFrequencyNames = new LinkedHashMap(); public static Map clientFrequencyNamesReversed = new LinkedHashMap(); + private static class EnderDestination { + + private final int dimension; + private final int x, y, z; + private IEnderDestination output; + + public EnderDestination(IEnderDestination output) { + + x = output.x(); + y = output.y(); + z = output.z(); + dimension = output.dimension(); + this.output = output; + } + + public boolean hasOutput() { + + return DimensionManager.isDimensionRegistered(dimension); + } + + public IEnderDestination getOutput() { + + if (output == null || output.isNotValid()) { + output = null; + if (!DimensionManager.isDimensionRegistered(dimension)) { + return null; + } + WorldServer world = DimensionManager.getWorld(dimension); + if (world == null) { + DimensionManager.initDimension(dimension); + world = DimensionManager.getWorld(dimension); + } + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IEnderDestination) { + output = (IEnderDestination) te; + } + } + return output; + } + } + public static void clear() { inputItem.clear(); @@ -85,6 +129,31 @@ public final class RegistryEnderAttuned { return outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()); } + public static boolean hasDestination(IEnderDestination theAttuned) { + + return hasDestination(theAttuned, true); + } + + public static boolean hasDestination(IEnderDestination theAttuned, boolean to) { + + Map map = outputTeleport.get(theAttuned.getChannelString()); + if (map == null) { + return false; + } + EnderDestination dest = map.get(to ? theAttuned.getDestination() : theAttuned.getFrequency()); + return dest == null ? false : dest.hasOutput(); + } + + public static IEnderDestination getDestination(IEnderDestination theAttuned) { + + Map map = outputTeleport.get(theAttuned.getChannelString()); + if (map == null) { + return null; + } + EnderDestination dest = map.get(theAttuned.getDestination()); + return dest == null ? null : dest.getOutput(); + } + /* HELPER FUNCTIONS */ public static void addItemHandler(IEnderItemHandler theAttuned) { @@ -164,6 +233,16 @@ public final class RegistryEnderAttuned { } } + public static void addDestination(IEnderDestination theAttuned) { + + if (!hasDestination(theAttuned, false)) { + if (outputTeleport.get(theAttuned.getChannelString()) == null) { + outputTeleport.put(theAttuned.getChannelString(), new HashMap()); + } + outputTeleport.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new EnderDestination(theAttuned)); + } + } + public static void removeItemHandler(IEnderItemHandler theAttuned) { if (inputItem.get(theAttuned.getChannelString()) != null) { @@ -224,6 +303,23 @@ public final class RegistryEnderAttuned { } } + public static void removeDestination(IEnderDestination theAttuned) { + + Map map = outputTeleport.get(theAttuned.getChannelString()); + if (map == null) { + return; + } + EnderDestination dest = map.get(theAttuned.getFrequency()); + if (dest == null) { + return; + } + if (dest.dimension == theAttuned.dimension()) { + if (dest.x == theAttuned.x() && dest.y == theAttuned.x() && dest.z == theAttuned.x()) { + map.remove(theAttuned.getFrequency()); + } + } + } + public static void add(IEnderAttuned theAttuned) { if (theAttuned instanceof IEnderItemHandler) { @@ -235,6 +331,9 @@ public final class RegistryEnderAttuned { if (theAttuned instanceof IEnderEnergyHandler) { addEnergyHandler((IEnderEnergyHandler) theAttuned); } + if (theAttuned instanceof IEnderDestination) { + addDestination((IEnderDestination) theAttuned); + } } public static void remove(IEnderAttuned theAttuned) { @@ -248,6 +347,9 @@ public final class RegistryEnderAttuned { if (theAttuned instanceof IEnderEnergyHandler) { removeEnergyHandler((IEnderEnergyHandler) theAttuned); } + if (theAttuned instanceof IEnderDestination) { + removeDestination((IEnderDestination) theAttuned); + } } public static void sortClientNames() {