diff --git a/src/api/java/buildcraft/api/blueprints/MappingRegistry.java b/src/api/java/buildcraft/api/blueprints/MappingRegistry.java index 1f6b6d861..dbe66e320 100644 --- a/src/api/java/buildcraft/api/blueprints/MappingRegistry.java +++ b/src/api/java/buildcraft/api/blueprints/MappingRegistry.java @@ -6,7 +6,6 @@ package buildcraft.api.blueprints; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.HashMap; import java.util.Map.Entry; @@ -407,16 +406,19 @@ public class MappingRegistry { } public void addToCrashReport(CrashReportCategory cat) { - Comparator> comparator = (e1, e2) -> e1.getValue() - e2.getValue(); - cat.addCrashSection("Item Map Count", itemToId.size()); - itemToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), Item.itemRegistry.getNameForObject( - e.getKey()))); + for (Entry e : itemToId.entrySet()) { + cat.addCrashSection(" - ID " + e.getValue(), Item.itemRegistry.getNameForObject(e.getKey())); + } cat.addCrashSection("Block Map Count", blockToId.size()); - blockToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), e.getKey())); + for (Entry e : blockToId.entrySet()) { + cat.addCrashSection(" - ID " + e.getValue(), Block.blockRegistry.getNameForObject(e.getKey())); + } cat.addCrashSection("Entity Map Count", entityToId.size()); - entityToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), e.getKey())); + for (Entry, Integer> e : entityToId.entrySet()) { + cat.addCrashSection(" - ID " + e.getValue(), e.getKey()); + } } } diff --git a/src/api/java/buildcraft/api/core/EnumPipePart.java b/src/api/java/buildcraft/api/core/EnumPipePart.java index f3ea8d6fb..2f97777cb 100644 --- a/src/api/java/buildcraft/api/core/EnumPipePart.java +++ b/src/api/java/buildcraft/api/core/EnumPipePart.java @@ -1,17 +1,15 @@ package buildcraft.api.core; -import java.util.Locale; -import java.util.Map; - import com.google.common.collect.Maps; - +import io.netty.buffer.ByteBuf; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase.NBTPrimitive; import net.minecraft.nbt.NBTTagString; import net.minecraft.util.EnumFacing; import net.minecraft.util.IStringSerializable; -import io.netty.buffer.ByteBuf; +import java.util.Locale; +import java.util.Map; public enum EnumPipePart implements IStringSerializable,INetworkLoadable_BC8 { DOWN(EnumFacing.DOWN), @@ -36,6 +34,10 @@ public enum EnumPipePart implements IStringSerializable,INetworkLoadable_BC8> registeredIdentifiers; static { - registeredIdentifiers.put("mincraft:tile", () -> new Tile(0, null)); - registeredIdentifiers.put("mincraft:entity", () -> new MovableEntity(0, null)); + registeredIdentifiers.put("mincraft:tile", new Supplier() { + @Override + public Identifier get() { + return new Tile(0, null); + } + }); + registeredIdentifiers.put("mincraft:entity", new Supplier() { + @Override + public Identifier get() { + return new MovableEntity(0, null); + } + }); } protected final int dimId; @@ -161,18 +172,27 @@ public abstract class Identifier { this.uniqueId = uniqueId; } + private Entity get(World world) { + for (Entity entity : world.loadedEntityList) { + if (entity.getPersistentID().equals(uniqueId)) { + return entity; + } + } + return null; + } + @Override public Entity getByIdentifier(MinecraftServer server) { World world = server.worldServerForDimension(dimId); if (world == null || world.provider.getDimensionId() != dimId) return null; - return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null); + return get(world); } @Override public boolean isLoaded(MinecraftServer server) { World world = server.worldServerForDimension(dimId); if (world == null || world.provider.getDimensionId() != dimId) return false; - return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null) != null; + return get(world) != null; } @Override @@ -180,7 +200,7 @@ public abstract class Identifier { public Entity getByIdentifierClient() { World world = Minecraft.getMinecraft().theWorld; if (world == null || world.provider.getDimensionId() != dimId) return null; - return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null); + return get(world); } @Override @@ -188,7 +208,7 @@ public abstract class Identifier { public boolean isLoadedClient() { World world = Minecraft.getMinecraft().theWorld; if (world == null || world.provider.getDimensionId() != dimId) return false; - return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null) != null; + return get(world) != null; } @Override diff --git a/src/api/java/buildcraft/api/core/package-info.java b/src/api/java/buildcraft/api/core/package-info.java index 0d8264ada..f0b642a91 100644 --- a/src/api/java/buildcraft/api/core/package-info.java +++ b/src/api/java/buildcraft/api/core/package-info.java @@ -2,7 +2,7 @@ * * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ -@API(apiVersion = "2.0", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core") +@API(apiVersion = "2.1", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core") package buildcraft.api.core; import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/fuels/IFuelManager.java b/src/api/java/buildcraft/api/fuels/IFuelManager.java index decf3ff77..367818270 100644 --- a/src/api/java/buildcraft/api/fuels/IFuelManager.java +++ b/src/api/java/buildcraft/api/fuels/IFuelManager.java @@ -7,29 +7,21 @@ package buildcraft.api.fuels; import java.util.Collection; import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; public interface IFuelManager { IFuel addFuel(IFuel fuel); IFuel addFuel(Fluid fluid, int powerPerCycle, int totalBurningTime); - // IFuel addFuel(FluidStack fuel, int rfPerBucket, int burnTimePerBucket); - // IDirtyFuel addDirtyFuel(Fluid fuel, int powerPerCycle, int totalBurningTime, FluidStack residue); + IDirtyFuel addDirtyFuel(Fluid fuel, int powerPerCycle, int totalBurningTime, FluidStack residue); Collection getFuels(); IFuel getFuel(Fluid fluid); - // TODO! - // public interface IFuel { - // FluidStack getFuelIngrediant(); - // - // int rfPerBucket(); - // - // int burnTimePerBucket(); - // } - // - // public interface IDirtyFuel extends IFuel { - // FluidStack getResidue(); - // } + public interface IDirtyFuel extends IFuel { + /** @return The residue fluidstack, per bucket of original fuel. */ + FluidStack getResidue(); + } } diff --git a/src/api/java/buildcraft/api/gates/GateExpansionModelKey.java b/src/api/java/buildcraft/api/gates/GateExpansionModelKey.java new file mode 100644 index 000000000..85763f19d --- /dev/null +++ b/src/api/java/buildcraft/api/gates/GateExpansionModelKey.java @@ -0,0 +1,36 @@ +package buildcraft.api.gates; + +import java.util.Arrays; + +import net.minecraft.util.EnumWorldBlockLayer; + +public class GateExpansionModelKey> { + public final EnumWorldBlockLayer layer; + public final IExpansionBaker baker; + private final int hash; + + public GateExpansionModelKey(EnumWorldBlockLayer layer, IExpansionBaker baker) { + if (layer != EnumWorldBlockLayer.CUTOUT && layer != EnumWorldBlockLayer.TRANSLUCENT) { + throw new IllegalArgumentException("Unsuported layer! Was " + layer + ", wanted CUTOUT or TRANSLUCENT"); + } + if (baker == null) throw new NullPointerException("baker"); + this.layer = layer; + this.baker = baker; + hash = Arrays.hashCode(new int[] { layer.hashCode(), System.identityHashCode(baker) }); + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + GateExpansionModelKey other = (GateExpansionModelKey) obj; + if (baker != other.baker) return false; + return true; + } +} diff --git a/src/api/java/buildcraft/api/gates/IExpansionBaker.java b/src/api/java/buildcraft/api/gates/IExpansionBaker.java new file mode 100644 index 000000000..846cfe598 --- /dev/null +++ b/src/api/java/buildcraft/api/gates/IExpansionBaker.java @@ -0,0 +1,13 @@ +package buildcraft.api.gates; + +import com.google.common.collect.ImmutableList; + +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.vertex.VertexFormat; + +public interface IExpansionBaker> { + /** @return The vertex format used to generate the quads. */ + VertexFormat getVertexFormat(); + + ImmutableList bake(K key); +} diff --git a/src/api/java/buildcraft/api/gates/IGateExpansion.java b/src/api/java/buildcraft/api/gates/IGateExpansion.java index f197c0ca7..2dad21324 100644 --- a/src/api/java/buildcraft/api/gates/IGateExpansion.java +++ b/src/api/java/buildcraft/api/gates/IGateExpansion.java @@ -4,12 +4,9 @@ * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ package buildcraft.api.gates; -import java.util.List; - -import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumWorldBlockLayer; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -26,9 +23,5 @@ public interface IGateExpansion { void textureStitch(TextureMap map); @SideOnly(Side.CLIENT) - IGateStaticRenderState getRenderState(); - - public interface IGateStaticRenderState { - List bake(VertexFormat format); - } + GateExpansionModelKey getRenderModelKey(EnumWorldBlockLayer layer); } diff --git a/src/api/java/buildcraft/api/properties/BuildCraftExtendedProperty.java b/src/api/java/buildcraft/api/properties/BuildCraftExtendedProperty.java index c1998b193..e0ba3a62d 100644 --- a/src/api/java/buildcraft/api/properties/BuildCraftExtendedProperty.java +++ b/src/api/java/buildcraft/api/properties/BuildCraftExtendedProperty.java @@ -22,7 +22,7 @@ public class BuildCraftExtendedProperty> extends BuildCr } public static BuildCraftExtendedProperty create(String name, final double min, final double max) { - return new BuildCraftExtendedProperty<>(name, Double.class, new Predicate() { + return new BuildCraftExtendedProperty(name, Double.class, new Predicate() { @Override public boolean apply(Double input) { return input >= min && input <= max; diff --git a/src/api/java/buildcraft/api/recipes/IComplexRefineryRecipeManager.java b/src/api/java/buildcraft/api/recipes/IComplexRefineryRecipeManager.java index 320cf67f5..5623b5eaa 100644 --- a/src/api/java/buildcraft/api/recipes/IComplexRefineryRecipeManager.java +++ b/src/api/java/buildcraft/api/recipes/IComplexRefineryRecipeManager.java @@ -1,31 +1,23 @@ package buildcraft.api.recipes; -import java.util.HashSet; import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; + +import com.google.common.base.Predicate; import net.minecraftforge.fluids.FluidStack; public interface IComplexRefineryRecipeManager { IHeatableRecipe createHeatingRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks); - default IHeatableRecipe addHeatableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting) { - return getHeatableRegistry().addRecipe(createHeatingRecipe(in, out, heatFrom, heatTo, ticks), replaceExisting); - } + IHeatableRecipe addHeatableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting); ICoolableRecipe createCoolableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks); - default ICoolableRecipe addCoolableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting) { - return getCoolableRegistry().addRecipe(createCoolableRecipe(in, out, heatFrom, heatTo, ticks), replaceExisting); - } + ICoolableRecipe addCoolableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting); IDistilationRecipe createDistilationRecipe(FluidStack in, FluidStack outGas, FluidStack outLiquid, int ticks); - default IDistilationRecipe addDistilationRecipe(FluidStack in, FluidStack outGas, FluidStack outLiquid, int ticks, boolean replaceExisting) { - return getDistilationRegistry().addRecipe(createDistilationRecipe(in, outGas, outLiquid, ticks), replaceExisting); - } + IDistilationRecipe addDistilationRecipe(FluidStack in, FluidStack outGas, FluidStack outLiquid, int ticks, boolean replaceExisting); IComplexRefineryRegistry getHeatableRegistry(); @@ -36,20 +28,12 @@ public interface IComplexRefineryRecipeManager { public interface IComplexRefineryRegistry { /** @return an unmodifiable set containing all of the distilation recipies that satisfy the given predicate. All * of the recipe objects are guarenteed to never be null. */ - Stream getRecipes(Predicate toReturn); - - default Set getRecipesAsSet(Predicate toReturn) { - return getRecipes(toReturn).collect(Collectors.toCollection(() -> new HashSet<>())); - } + Set getRecipes(Predicate toReturn); /** @return an unmodifiable set containing all of the distilation recipies. */ - default Set getAllRecipes() { - return getRecipesAsSet(r -> true); - } + Set getAllRecipes(); - default R getRecipeForInput(FluidStack fluid) { - return getRecipes(r -> r.in().equals(fluid)).findAny().orElse(null); - } + R getRecipeForInput(FluidStack fluid); Set removeRecipes(Predicate toRemove); diff --git a/src/api/java/buildcraft/api/statements/IActionInternal.java b/src/api/java/buildcraft/api/statements/IActionInternal.java index 845bbab32..621c317e8 100644 --- a/src/api/java/buildcraft/api/statements/IActionInternal.java +++ b/src/api/java/buildcraft/api/statements/IActionInternal.java @@ -8,8 +8,8 @@ public interface IActionInternal extends IStatement { void actionActivate(IStatementContainer source, IStatementParameter[] parameters); - /** @return True if this action should only be fired for the first tick of it being active. */ - default boolean singleActionTick() { - return false; + public interface IActionInternalSingle extends IActionInternal { + /** @return True if this action should only be fired for the first tick of it being active. */ + boolean singleActionTick(); } } diff --git a/src/api/java/buildcraft/api/statements/StatementManager.java b/src/api/java/buildcraft/api/statements/StatementManager.java index 04e559c47..166541ac1 100644 --- a/src/api/java/buildcraft/api/statements/StatementManager.java +++ b/src/api/java/buildcraft/api/statements/StatementManager.java @@ -145,6 +145,10 @@ public final class StatementManager { } private static IStatementParameter createParameter(Class param) { + if (param == null) { + return null; + } + try { return param.newInstance(); } catch (InstantiationException e) { diff --git a/src/api/java/buildcraft/api/transport/IPipeTile.java b/src/api/java/buildcraft/api/transport/IPipeTile.java index 5ed528422..d8d38c234 100644 --- a/src/api/java/buildcraft/api/transport/IPipeTile.java +++ b/src/api/java/buildcraft/api/transport/IPipeTile.java @@ -6,6 +6,7 @@ package buildcraft.api.transport; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; @@ -23,6 +24,8 @@ public interface IPipeTile extends IInjectable { World getWorldBC(); + BlockPos getPosBC(); + /** True if the pipe is connected to the block/pipe in the specific direction * * @param with diff --git a/src/api/java/buildcraft/api/transport/package-info.java b/src/api/java/buildcraft/api/transport/package-info.java index 7ab0064d3..004c271a1 100644 --- a/src/api/java/buildcraft/api/transport/package-info.java +++ b/src/api/java/buildcraft/api/transport/package-info.java @@ -2,7 +2,7 @@ * * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ -@API(apiVersion = "4.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport") +@API(apiVersion = "5.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport") package buildcraft.api.transport; import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IInsertionManager.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IInsertionManager.java index fff014268..0ae64a68a 100644 --- a/src/api/java/buildcraft/api/transport/pipe_bc8/IInsertionManager.java +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IInsertionManager.java @@ -24,15 +24,6 @@ public interface IInsertionManager { boolean tryInsertFluid(IPipeContentsEditableFluid fluid, Object extractor, EnumFacing direction, boolean simulate); - default boolean tryInsert(IPipeContentsEditable contents, Object extractor, EnumFacing direction, boolean simulate) { - if (contents instanceof IPipeContentsEditableItem) { - return tryInsertItems((IPipeContentsEditableItem) contents, extractor, direction, simulate); - } else if (contents instanceof IPipeContentsEditableFluid) { - return tryInsertFluid((IPipeContentsEditableFluid) contents, extractor, direction, simulate); - } - return false; - } - /** @return True if {@link #tryExtractItems(IStackFilter, Object, EnumFacing, boolean)} can return a non-null * value at any future point in time. */ boolean acceptsItems(); diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipe_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipe_BC8.java index b327a1d21..66dc2037c 100644 --- a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipe_BC8.java +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipe_BC8.java @@ -39,16 +39,12 @@ public interface IPipe_BC8 extends INBTLoadable_BC8 { /** Makes this pipe send a client update at some point in the future. This might send it now, or it might send it * next tick. */ - default void scheduleClientUpdate(IPipeListener listener) { - sendClientUpdate(listener); - } + void scheduleClientUpdate(IPipeListener listener); /** Makes this pipe re-render its static parts. */ void sendRenderUpdate(); /** Makes this pipe send a render update at some point in the future. This might send it now, or it might send it in * a few ticks time. */ - default void scheduleRenderUpdate() { - sendRenderUpdate(); - } + void scheduleRenderUpdate(); } diff --git a/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableDynamicRenderer.java b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableDynamicRenderer.java index 2601a356d..61c69bed4 100644 --- a/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableDynamicRenderer.java +++ b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableDynamicRenderer.java @@ -2,8 +2,12 @@ package buildcraft.api.transport.pluggable; import net.minecraft.util.EnumFacing; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import buildcraft.api.transport.IPipe; +@SideOnly(Side.CLIENT) public interface IPipePluggableDynamicRenderer { void renderDynamicPluggable(IPipe pipe, EnumFacing side, PipePluggable pipePluggable, double x, double y, double z); } diff --git a/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableStaticRenderer.java b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableStaticRenderer.java deleted file mode 100644 index e4bfc3f60..000000000 --- a/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableStaticRenderer.java +++ /dev/null @@ -1,19 +0,0 @@ -package buildcraft.api.transport.pluggable; - -import java.util.List; - -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.util.EnumFacing; - -import buildcraft.api.transport.IPipe; - -public interface IPipePluggableStaticRenderer { - List bakeCutout(IPipeRenderState render, IPipePluggableState pluggableState, IPipe pipe, PipePluggable pluggable, EnumFacing face); - - /** Use this if you need to render in the translucent pass. */ - public interface Translucent extends IPipePluggableStaticRenderer { - /** For performance return a list that is as small as possible */ - List bakeTranslucent(IPipeRenderState render, IPipePluggableState pluggableState, IPipe pipe, PipePluggable pluggable, - EnumFacing face); - } -} diff --git a/src/api/java/buildcraft/api/transport/pluggable/IPluggableModelBaker.java b/src/api/java/buildcraft/api/transport/pluggable/IPluggableModelBaker.java new file mode 100644 index 000000000..829eedaa8 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/IPluggableModelBaker.java @@ -0,0 +1,17 @@ +package buildcraft.api.transport.pluggable; + +import com.google.common.collect.ImmutableList; + +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.vertex.VertexFormat; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public interface IPluggableModelBaker> { + /** @return The vertex format used to generate the quads. */ + VertexFormat getVertexFormat(); + + ImmutableList bake(K key); +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/PipePluggable.java b/src/api/java/buildcraft/api/transport/pluggable/PipePluggable.java index 02a0bd3ab..5d505904c 100644 --- a/src/api/java/buildcraft/api/transport/pluggable/PipePluggable.java +++ b/src/api/java/buildcraft/api/transport/pluggable/PipePluggable.java @@ -7,6 +7,8 @@ package buildcraft.api.transport.pluggable; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumWorldBlockLayer; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -46,14 +48,14 @@ public abstract class PipePluggable implements INBTStoreable, ISerializable { public abstract AxisAlignedBB getBoundingBox(EnumFacing side); - @SideOnly(Side.CLIENT) - public abstract IPipePluggableStaticRenderer getRenderer(); - @SideOnly(Side.CLIENT) public IPipePluggableDynamicRenderer getDynamicRenderer() { return null; } + @SideOnly(Side.CLIENT) + public abstract PluggableModelKey getModelRenderKey(EnumWorldBlockLayer layer, EnumFacing side); + public boolean requiresRenderUpdate(PipePluggable old) { return true; } diff --git a/src/api/java/buildcraft/api/transport/pluggable/PluggableModelKey.java b/src/api/java/buildcraft/api/transport/pluggable/PluggableModelKey.java new file mode 100644 index 000000000..3094cbb22 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/PluggableModelKey.java @@ -0,0 +1,45 @@ +package buildcraft.api.transport.pluggable; + +import java.util.Arrays; +import java.util.Objects; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumWorldBlockLayer; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public abstract class PluggableModelKey> { + public final EnumWorldBlockLayer layer; + public final IPluggableModelBaker baker; + public final EnumFacing side; + private final int hash; + + public PluggableModelKey(EnumWorldBlockLayer layer, IPluggableModelBaker baker, EnumFacing side) { + this.layer = layer; + if (layer != EnumWorldBlockLayer.CUTOUT && layer != EnumWorldBlockLayer.TRANSLUCENT) { + throw new IllegalArgumentException("Can only use CUTOUT or TRANSLUCENT at the moment (was " + layer + ")"); + } + if (baker == null) throw new NullPointerException("baker"); + this.baker = baker; + this.side = side; + /* Don't inclue the block layer in the hash code as there are different caches for cutout and translucent */ + this.hash = Arrays.hashCode(new int[] { System.identityHashCode(baker), Objects.hashCode(side) }); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + PluggableModelKey other = (PluggableModelKey) obj; + if (baker != other.baker) return false; + if (side != other.side) return false; + return true; + } + + @Override + public int hashCode() { + return hash; + } +}