From 55c834d5808db1c66b4b66b8bae667c3202e6d6a Mon Sep 17 00:00:00 2001 From: qubka Date: Thu, 24 Sep 2020 18:04:35 +0100 Subject: [PATCH] Remove unneeded allocation and also added types to canInput methods --- forge/src/main/java/tesseract/controller/Energy.java | 5 +++-- forge/src/main/java/tesseract/controller/Fluid.java | 7 ++++--- forge/src/main/java/tesseract/controller/Utils.java | 2 +- src/main/java/tesseract/api/fluid/FluidConsumer.java | 2 +- src/main/java/tesseract/api/fluid/IFluidNode.java | 2 +- src/main/java/tesseract/api/item/IItemNode.java | 2 +- src/main/java/tesseract/api/item/ItemConsumer.java | 2 +- src/main/java/tesseract/graph/Graph.java | 2 +- src/main/java/tesseract/graph/Grid.java | 4 ++-- src/main/java/tesseract/graph/Group.java | 4 ++-- src/main/java/tesseract/graph/Path.java | 4 ++-- 11 files changed, 19 insertions(+), 17 deletions(-) diff --git a/forge/src/main/java/tesseract/controller/Energy.java b/forge/src/main/java/tesseract/controller/Energy.java index 1959955e..99ceb708 100644 --- a/forge/src/main/java/tesseract/controller/Energy.java +++ b/forge/src/main/java/tesseract/controller/Energy.java @@ -1,9 +1,10 @@ package tesseract.controller; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.Explosion; import tesseract.api.gt.GTController; +import static net.minecraft.world.Explosion.Mode.*; + // TODO: Make explosions depend on voltage, amp public class Energy extends GTController { @@ -18,7 +19,7 @@ public Energy(int dim) { @Override public void onNodeOverVoltage(int dim, long pos, int voltage) { - Utils.getServerWorld(dim).ifPresent(w -> Utils.createExplosion(w, BlockPos.fromLong(pos), 4.0F, Explosion.Mode.BREAK)); + Utils.getServerWorld(dim).ifPresent(w -> Utils.createExplosion(w, BlockPos.fromLong(pos), 4.0F, DESTROY)); } @Override diff --git a/forge/src/main/java/tesseract/controller/Fluid.java b/forge/src/main/java/tesseract/controller/Fluid.java index 7a4db565..01dcbe67 100644 --- a/forge/src/main/java/tesseract/controller/Fluid.java +++ b/forge/src/main/java/tesseract/controller/Fluid.java @@ -3,13 +3,14 @@ import net.minecraft.block.Blocks; import net.minecraft.fluid.Fluids; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.Explosion; import tesseract.api.fluid.FluidController; import tesseract.api.fluid.FluidData; import tesseract.api.fluid.IFluidNode; import javax.annotation.Nonnull; +import static net.minecraft.world.Explosion.Mode.*; + // TODO: Make explosions depend on pressure, capacity, temperature public class Fluid extends FluidController> { @@ -24,12 +25,12 @@ public Fluid(int dim) { @Override public void onPipeOverPressure(int dim, long pos, int pressure) { - Utils.getServerWorld(dim).ifPresent(w -> Utils.createExplosion(w, BlockPos.fromLong(pos), 4.0F, Explosion.Mode.BREAK)); + Utils.getServerWorld(dim).ifPresent(w -> Utils.createExplosion(w, BlockPos.fromLong(pos), 4.0F, DESTROY)); } @Override public void onPipeOverCapacity(int dim, long pos, int capacity) { - Utils.getServerWorld(dim).ifPresent(w -> Utils.createExplosion(w, BlockPos.fromLong(pos), 1.0F, Explosion.Mode.NONE)); + Utils.getServerWorld(dim).ifPresent(w -> Utils.createExplosion(w, BlockPos.fromLong(pos), 1.0F, BREAK)); } @Override diff --git a/forge/src/main/java/tesseract/controller/Utils.java b/forge/src/main/java/tesseract/controller/Utils.java index 25a5cc3f..bebf44e3 100644 --- a/forge/src/main/java/tesseract/controller/Utils.java +++ b/forge/src/main/java/tesseract/controller/Utils.java @@ -19,7 +19,7 @@ public static Optional getServerWorld(int dimension) { } public static void createExplosion(ServerWorld world, BlockPos pos, float explosionRadius, Explosion.Mode modeIn) { - world.createExplosion(null, pos.getX(), pos.getY() + 0.0625D, pos.getZ(), explosionRadius, true, modeIn); + world.createExplosion(null, pos.getX(), pos.getY() + 0.0625D, pos.getZ(), explosionRadius, modeIn == Explosion.Mode.DESTROY, modeIn); world.spawnParticle(ParticleTypes.SMOKE, pos.getX(), pos.getY() + 0.5D, pos.getZ(), 1, 0, 0, 0, 0.0D); } diff --git a/src/main/java/tesseract/api/fluid/FluidConsumer.java b/src/main/java/tesseract/api/fluid/FluidConsumer.java index eb8cd12e..2faac698 100644 --- a/src/main/java/tesseract/api/fluid/FluidConsumer.java +++ b/src/main/java/tesseract/api/fluid/FluidConsumer.java @@ -43,7 +43,7 @@ public int insert(FluidData data, boolean simulate) { * @param fluid The Fluid to be queried. * @return If the tank can hold the fluid (EVER, not at the time of query). */ - public boolean canHold(Object fluid) { + public boolean canHold(T fluid) { return node.canInput(fluid, input); } diff --git a/src/main/java/tesseract/api/fluid/IFluidNode.java b/src/main/java/tesseract/api/fluid/IFluidNode.java index 60c8e4b1..1de4bb9f 100644 --- a/src/main/java/tesseract/api/fluid/IFluidNode.java +++ b/src/main/java/tesseract/api/fluid/IFluidNode.java @@ -73,5 +73,5 @@ public interface IFluidNode extends IConnectable { * @param direction Direction to the input. * @return If the tank can input the fluid (EVER, not at the time of query). */ - boolean canInput(Object fluid, Dir direction); + boolean canInput(T fluid, Dir direction); } diff --git a/src/main/java/tesseract/api/item/IItemNode.java b/src/main/java/tesseract/api/item/IItemNode.java index 209da095..af822786 100644 --- a/src/main/java/tesseract/api/item/IItemNode.java +++ b/src/main/java/tesseract/api/item/IItemNode.java @@ -83,5 +83,5 @@ public interface IItemNode extends IConnectable { * @param direction Direction to the input. * @return If the storage can input the item (EVER, not at the time of query). */ - boolean canInput(Object item, Dir direction); + boolean canInput(T item, Dir direction); } diff --git a/src/main/java/tesseract/api/item/ItemConsumer.java b/src/main/java/tesseract/api/item/ItemConsumer.java index b4e7be2c..0a29a66e 100644 --- a/src/main/java/tesseract/api/item/ItemConsumer.java +++ b/src/main/java/tesseract/api/item/ItemConsumer.java @@ -41,7 +41,7 @@ public int insert(ItemData data, boolean simulate) { * @param item The Item to be queried. * @return If the storage can hold the item (EVER, not at the time of query). */ - public boolean canAccept(Object item) { + public boolean canAccept(T item) { return node.canInput(item, input); } diff --git a/src/main/java/tesseract/graph/Graph.java b/src/main/java/tesseract/graph/Graph.java index d89fc6f2..4ee566aa 100644 --- a/src/main/java/tesseract/graph/Graph.java +++ b/src/main/java/tesseract/graph/Graph.java @@ -51,7 +51,7 @@ public int countGroups() { * @return Gets the groups map. */ public Int2ObjectMap> getGroups() { - return Int2ObjectMaps.unmodifiable(groups); + return groups; } /** diff --git a/src/main/java/tesseract/graph/Grid.java b/src/main/java/tesseract/graph/Grid.java index 271d647c..315c4386 100644 --- a/src/main/java/tesseract/graph/Grid.java +++ b/src/main/java/tesseract/graph/Grid.java @@ -107,14 +107,14 @@ public int countNodes() { * @return Returns connectors map. */ public Long2ObjectMap> getConnectors() { - return Long2ObjectMaps.unmodifiable(connectors); + return connectors; } /** * @return Returns nodes map. */ public Long2ByteMap getNodes() { - return Long2ByteMaps.unmodifiable(nodes); + return nodes; } /** diff --git a/src/main/java/tesseract/graph/Group.java b/src/main/java/tesseract/graph/Group.java index 9d292b14..eef73bfa 100644 --- a/src/main/java/tesseract/graph/Group.java +++ b/src/main/java/tesseract/graph/Group.java @@ -197,14 +197,14 @@ public Set getBlocks() { * @return Returns nodes map. */ public Long2ObjectMap> getNodes() { - return Long2ObjectMaps.unmodifiable(nodes); + return nodes; } /** * @return Returns grids set. */ public Int2ObjectMap> getGrids() { - return Int2ObjectMaps.unmodifiable(grids); + return grids; } /** diff --git a/src/main/java/tesseract/graph/Path.java b/src/main/java/tesseract/graph/Path.java index 980bf682..6d732266 100644 --- a/src/main/java/tesseract/graph/Path.java +++ b/src/main/java/tesseract/graph/Path.java @@ -63,14 +63,14 @@ public Node target() { * @return Gets the full connectors path. */ public Long2ObjectMap getFull() { - return Long2ObjectMaps.unmodifiable(full); + return full; } /** * @return Gets the crossroad connectors path. */ public Long2ObjectMap getCross() { - return Long2ObjectMaps.unmodifiable(cross); + return cross; } /**