Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded allocations and also added types to canInput methods #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions forge/src/main/java/tesseract/controller/Energy.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions forge/src/main/java/tesseract/controller/Fluid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> extends FluidController<T, IFluidNode<T>> {

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion forge/src/main/java/tesseract/controller/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Optional<ServerWorld> 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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tesseract/api/fluid/FluidConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int insert(FluidData<T> 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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tesseract/api/fluid/IFluidNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ public interface IFluidNode<T> 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);
}
2 changes: 1 addition & 1 deletion src/main/java/tesseract/api/item/IItemNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ public interface IItemNode<T> 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);
}
2 changes: 1 addition & 1 deletion src/main/java/tesseract/api/item/ItemConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public int insert(ItemData<T> 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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tesseract/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public int countGroups() {
* @return Gets the groups map.
*/
public Int2ObjectMap<Group<C, N>> getGroups() {
return Int2ObjectMaps.unmodifiable(groups);
return groups;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tesseract/graph/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ public int countNodes() {
* @return Returns connectors map.
*/
public Long2ObjectMap<Cache<C>> getConnectors() {
return Long2ObjectMaps.unmodifiable(connectors);
return connectors;
}

/**
* @return Returns nodes map.
*/
public Long2ByteMap getNodes() {
return Long2ByteMaps.unmodifiable(nodes);
return nodes;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tesseract/graph/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ public Set<Long> getBlocks() {
* @return Returns nodes map.
*/
public Long2ObjectMap<Cache<N>> getNodes() {
return Long2ObjectMaps.unmodifiable(nodes);
return nodes;
}

/**
* @return Returns grids set.
*/
public Int2ObjectMap<Grid<C>> getGrids() {
return Int2ObjectMaps.unmodifiable(grids);
return grids;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tesseract/graph/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public Node target() {
* @return Gets the full connectors path.
*/
public Long2ObjectMap<C> getFull() {
return Long2ObjectMaps.unmodifiable(full);
return full;
}

/**
* @return Gets the crossroad connectors path.
*/
public Long2ObjectMap<C> getCross() {
return Long2ObjectMaps.unmodifiable(cross);
return cross;
}

/**
Expand Down