From 04372a6426b673b1adbce37a709ecfa8ffa96b59 Mon Sep 17 00:00:00 2001 From: Richard Freimer Date: Wed, 17 Apr 2019 11:24:44 -0400 Subject: [PATCH 1/8] Various fixes to data not loading properly (#5407) * Cleanup redstone handling of TileEntitySidedPipe Properly mark the transmitters as dirty if the redstone mode changed during refresh * Fix not updating tank capacity when loading TEFluidTank from NBT * Make transmitters fix invalid connections on load * Address comments and call refreshConnections() directly. --- .../common/tile/TileEntityFluidTank.java | 3 +- .../tile/transmitter/TileEntitySidedPipe.java | 69 ++++++++++--------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/main/java/mekanism/common/tile/TileEntityFluidTank.java b/src/main/java/mekanism/common/tile/TileEntityFluidTank.java index c7a7e272d..d92a6167e 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFluidTank.java +++ b/src/main/java/mekanism/common/tile/TileEntityFluidTank.java @@ -288,9 +288,10 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc tier = FluidTankTier.values()[nbtTags.getInteger("tier")]; clientActive = isActive = nbtTags.getBoolean("isActive"); editMode = ContainerEditMode.values()[nbtTags.getInteger("editMode")]; + //Needs to be outside the hasKey check because this is just based on the tier which is known information + fluidTank.setCapacity(tier.getStorage()); if (nbtTags.hasKey("fluidTank")) { - fluidTank.setCapacity(tier.getStorage()); fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank")); } } diff --git a/src/main/java/mekanism/common/tile/transmitter/TileEntitySidedPipe.java b/src/main/java/mekanism/common/tile/transmitter/TileEntitySidedPipe.java index 502caf7df..81c235175 100644 --- a/src/main/java/mekanism/common/tile/transmitter/TileEntitySidedPipe.java +++ b/src/main/java/mekanism/common/tile/transmitter/TileEntitySidedPipe.java @@ -10,13 +10,12 @@ import mekanism.api.Coord4D; import mekanism.api.EnumColor; import mekanism.api.IConfigurable; import mekanism.api.Range4D; +import mekanism.api.TileNetworkList; import mekanism.api.transmitters.IBlockableConnection; import mekanism.api.transmitters.ITransmitter; import mekanism.api.transmitters.TransmissionType; import mekanism.common.Mekanism; -import mekanism.common.tier.BaseTier; import mekanism.common.base.ITileNetwork; -import mekanism.api.TileNetworkList; import mekanism.common.block.BlockTransmitter; import mekanism.common.block.property.PropertyConnection; import mekanism.common.block.states.BlockStateTransmitter.TransmitterType; @@ -25,6 +24,7 @@ import mekanism.common.capabilities.Capabilities; import mekanism.common.integration.multipart.MultipartMekanism; import mekanism.common.integration.multipart.MultipartTileNetworkJoiner; import mekanism.common.network.PacketTileEntity.TileEntityMessage; +import mekanism.common.tier.BaseTier; import mekanism.common.util.CapabilityUtils; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MultipartUtils; @@ -60,13 +60,13 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet public byte currentTransmitterConnections = 0x00; public boolean sendDesc = false; - public boolean redstonePowered = false; + private boolean redstonePowered = false; - public boolean redstoneReactive = false; + private boolean redstoneReactive = false; public boolean forceUpdate = true; - public boolean redstoneSet = false; + private boolean redstoneSet = false; public ConnectionType[] connectionTypes = {ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL}; @@ -312,18 +312,20 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet @Override public boolean canConnect(EnumFacing side) { - if (!redstoneSet) { - if (redstoneReactive) { - redstonePowered = MekanismUtils.isGettingPowered(getWorld(), new Coord4D(getPos(), getWorld())); - } else { - redstonePowered = false; + if (handlesRedstone()) { + if (!redstoneSet) { + if (redstoneReactive) { + redstonePowered = MekanismUtils.isGettingPowered(getWorld(), new Coord4D(getPos(), getWorld())); + } else { + redstonePowered = false; + } + + redstoneSet = true; } - redstoneSet = true; - } - - if (handlesRedstone() && redstoneReactive && redstonePowered) { - return false; + if (redstoneReactive && redstonePowered) { + return false; + } } if (Mekanism.hooks.MCMPLoaded) { @@ -401,13 +403,20 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet } public void refreshConnections() { - if (redstoneReactive) { - redstonePowered = MekanismUtils.isGettingPowered(getWorld(), new Coord4D(getPos(), getWorld())); - } else { - redstonePowered = false; - } + if (handlesRedstone()) { + boolean previouslyPowered = redstonePowered; + if (redstoneReactive) { + redstonePowered = MekanismUtils.isGettingPowered(getWorld(), new Coord4D(getPos(), getWorld())); + } else { + redstonePowered = false; + } + //If the redstone mode changed properly update the connection to other transmitters/networks + if (previouslyPowered != redstonePowered) { + notifyTileChange(); + } - redstoneSet = true; + redstoneSet = true; + } if (!getWorld().isRemote) { byte possibleTransmitters = getPossibleTransmitterConnections(); @@ -479,6 +488,10 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet @Override public void onLoad() { onWorldJoin(); + if (getPossibleTransmitterConnections() != currentTransmitterConnections) { + //Mark the transmitters as invalidated if they do not match what we have stored/calculated + refreshConnections(); + } super.onLoad(); } @@ -487,16 +500,7 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet } public void onNeighborBlockChange(EnumFacing side) { - if (handlesRedstone()) { - boolean prevPowered = redstonePowered; - refreshConnections(); - - if (prevPowered != redstonePowered) { - markDirtyTransmitters(); - } - } else { - refreshConnections(); - } + refreshConnections(); } public void onPartChanged(IMultipart part) { @@ -632,8 +636,7 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet @Override public boolean hasCapability(@Nonnull Capability capability, EnumFacing facing) { return capability == Capabilities.CONFIGURABLE_CAPABILITY || capability == Capabilities.TILE_NETWORK_CAPABILITY - || - capability == Capabilities.BLOCKABLE_CONNECTION_CAPABILITY || super.hasCapability(capability, facing); + || capability == Capabilities.BLOCKABLE_CONNECTION_CAPABILITY || super.hasCapability(capability, facing); } @Override From a5d9a5a2c1d01fbde08c7f955670919e221cf108 Mon Sep 17 00:00:00 2001 From: pupnewfster Date: Wed, 17 Apr 2019 12:01:23 -0400 Subject: [PATCH 2/8] Fix redstone bug described in #5407 turns out it did have to call markDirtyTransmitters and notifyTileChange was not enough --- .../common/tile/transmitter/TileEntitySidedPipe.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/mekanism/common/tile/transmitter/TileEntitySidedPipe.java b/src/main/java/mekanism/common/tile/transmitter/TileEntitySidedPipe.java index 81c235175..da96e434f 100644 --- a/src/main/java/mekanism/common/tile/transmitter/TileEntitySidedPipe.java +++ b/src/main/java/mekanism/common/tile/transmitter/TileEntitySidedPipe.java @@ -412,7 +412,10 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet } //If the redstone mode changed properly update the connection to other transmitters/networks if (previouslyPowered != redstonePowered) { - notifyTileChange(); + //Has to be markDirtyTransmitters instead of notify tile change + // or it will not properly tell the neighboring connections that + // it is no longer valid + markDirtyTransmitters(); } redstoneSet = true; From 260b5454049e817740429444e534d7ab39d02ff3 Mon Sep 17 00:00:00 2001 From: Thiakil Date: Fri, 19 Apr 2019 21:58:46 +0800 Subject: [PATCH 3/8] Load Mekanism Tools config before creating the materials so the config actually takes effect. Fixes #5412 --- src/main/java/mekanism/tools/common/MekanismTools.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/mekanism/tools/common/MekanismTools.java b/src/main/java/mekanism/tools/common/MekanismTools.java index c00ba4bed..3ce669a1c 100644 --- a/src/main/java/mekanism/tools/common/MekanismTools.java +++ b/src/main/java/mekanism/tools/common/MekanismTools.java @@ -93,6 +93,9 @@ public class MekanismTools implements IModule { @EventHandler public void preInit(FMLPreInitializationEvent event) { + //Load the config + proxy.loadConfiguration(); + addItems(); } @@ -104,9 +107,6 @@ public class MekanismTools implements IModule { //Register this class to the event bus for special mob spawning (mobs with Mekanism armor/tools) MinecraftForge.EVENT_BUS.register(this); - //Load the proxy - proxy.loadConfiguration(); - //Finalization Mekanism.logger.info("Loaded 'Mekanism: Tools' module."); } @@ -147,10 +147,6 @@ public class MekanismTools implements IModule { armorSTEEL = getArmorMaterial("STEEL", MekanismConfig.current().tools.armorSTEEL, SoundEvents.ITEM_ARMOR_EQUIP_IRON); - if (Mekanism.configuration.hasChanged()) { - Mekanism.configuration.save(); - } - ToolsItems.initializeItems(); ToolsItems.setHarvestLevels(); } From e187bc1bb89f52bb2d162a79368c6fd3234bf4e6 Mon Sep 17 00:00:00 2001 From: Thiakil Date: Fri, 19 Apr 2019 22:44:23 +0800 Subject: [PATCH 4/8] Robit teleportation fix. Closes #5415 --- src/main/java/mekanism/common/entity/EntityRobit.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/mekanism/common/entity/EntityRobit.java b/src/main/java/mekanism/common/entity/EntityRobit.java index 7d835242c..d93320dc8 100644 --- a/src/main/java/mekanism/common/entity/EntityRobit.java +++ b/src/main/java/mekanism/common/entity/EntityRobit.java @@ -312,11 +312,11 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine setFollowing(false); if (world.provider.getDimension() != homeLocation.dimensionId) { - changeDimension(homeLocation.dimensionId); + changeDimension(homeLocation.dimensionId, (world1, entity, yaw) -> entity.setLocationAndAngles(homeLocation.x + 0.5, homeLocation.y + 0.3, homeLocation.z + 0.5, yaw, rotationPitch)); + } else { + setPositionAndUpdate(homeLocation.x + 0.5, homeLocation.y + 0.3, homeLocation.z + 0.5); } - setPositionAndUpdate(homeLocation.x + 0.5, homeLocation.y + 0.3, homeLocation.z + 0.5); - motionX = 0; motionY = 0; motionZ = 0; From bbcea85fc48e326137df367ff427718f363151ba Mon Sep 17 00:00:00 2001 From: Xander Date: Sat, 20 Apr 2019 13:38:14 +0800 Subject: [PATCH 5/8] Respect NONE connection mode for Pipe Connections (#5387) * prevent Out of Bounds exception in factory ItemMeshDefinition * prevent Out of Bounds error in item stack display name * Respect NONE connection between pipes. Fixes #4781 * prevent fluid/gas pipes from connecting if their contents arent the same (part 1) * prevent some case of incorrect network merges that would convert/void a fluid/gas * Add a way to check if a network is compatible with an buffer Used for checking the orphan's buffer against the external network * rename some generic type variables for readability * introduce BUFFER generic type variable * Fix missing null check causing new pipes not being able to be added to a network * More checks for when there is an invalid factory * bump api version & use a constant for all * add default method to not break binary compat * Refresh if a connection exists if a transmitter failed to combine two networks Fallback to the network's buffer as if we have not saved any data yet the TE's buffer may still be null * Add a way to get the pipes buffer falling back to the network, rather than doing it from the same method. This ensures that there is no accidental leakage where the count of the buffer matters * Return a null buffer for pressurized tube buffer if the stack is empty * Allow merging of networks when they are able to connect again Visuals still need a minor update to sync the type it should be rendering * Update network visuals when networks merge * allow unconnected sides to have their mode set - except logistical transporters which already used that function, they only can un-NONE their unconnected sides --- src/main/java/mekanism/api/MekanismAPI.java | 5 + .../mekanism/api/energy/package-info.java | 3 +- .../java/mekanism/api/gas/package-info.java | 3 +- .../mekanism/api/infuse/package-info.java | 3 +- .../mekanism/api/lasers/package-info.java | 3 +- src/main/java/mekanism/api/package-info.java | 2 +- .../api/transmitters/DynamicNetwork.java | 67 +++++---- .../api/transmitters/IGridTransmitter.java | 52 +++++-- .../TransmitterNetworkRegistry.java | 39 ++++-- .../api/transmitters/package-info.java | 3 +- .../java/mekanism/client/ClientProxy.java | 11 +- .../java/mekanism/client/jei/MekanismJEI.java | 5 +- .../java/mekanism/common/base/IFactory.java | 10 ++ .../common/base/ILogisticalTransporter.java | 2 +- .../capabilities/DefaultGridTransmitter.java | 9 +- .../DefaultLogisticalTransporter.java | 8 +- .../common/item/ItemBlockMachine.java | 56 +++++--- .../network/PacketTransmitterUpdate.java | 77 ++++------- .../TileEntityLogisticalTransporter.java | 4 +- .../transmitter/TileEntityMechanicalPipe.java | 25 +++- .../TileEntityPressurizedTube.java | 33 ++++- .../tile/transmitter/TileEntitySidedPipe.java | 69 ++++++++-- .../TileEntityThermodynamicConductor.java | 4 +- .../transmitter/TileEntityTransmitter.java | 130 +++++++++++++++++- .../transmitter/TileEntityUniversalCable.java | 4 +- .../common/transmitters/Transmitter.java | 8 +- .../common/transmitters/TransmitterImpl.java | 43 ++++-- .../common/transmitters/TransporterImpl.java | 2 +- .../transmitters/grid/EnergyNetwork.java | 36 +++-- .../transmitters/grid/FluidNetwork.java | 63 ++++++--- .../common/transmitters/grid/GasNetwork.java | 85 +++++++----- .../common/transmitters/grid/HeatNetwork.java | 8 +- .../transmitters/grid/InventoryNetwork.java | 4 +- .../mekanism/common/util/RecipeUtils.java | 7 +- 34 files changed, 635 insertions(+), 248 deletions(-) diff --git a/src/main/java/mekanism/api/MekanismAPI.java b/src/main/java/mekanism/api/MekanismAPI.java index c8b28f3f7..0c1554826 100644 --- a/src/main/java/mekanism/api/MekanismAPI.java +++ b/src/main/java/mekanism/api/MekanismAPI.java @@ -15,6 +15,11 @@ import org.apache.logging.log4j.LogManager; public class MekanismAPI { + /** + * The version of the api classes - may not always match the mod's version + */ + public static final String API_VERSION = "9.7.2"; + /** * Mekanism debug mode */ diff --git a/src/main/java/mekanism/api/energy/package-info.java b/src/main/java/mekanism/api/energy/package-info.java index f59f1b64a..acd53e5b5 100644 --- a/src/main/java/mekanism/api/energy/package-info.java +++ b/src/main/java/mekanism/api/energy/package-info.java @@ -1,5 +1,6 @@ -@API(apiVersion = "9.0.0", owner = "mekanism", provides = "MekanismAPI|energy") +@API(apiVersion = MekanismAPI.API_VERSION, owner = "mekanism", provides = "MekanismAPI|energy") package mekanism.api.energy; +import mekanism.api.MekanismAPI; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/mekanism/api/gas/package-info.java b/src/main/java/mekanism/api/gas/package-info.java index fdb11cf87..2a162b794 100644 --- a/src/main/java/mekanism/api/gas/package-info.java +++ b/src/main/java/mekanism/api/gas/package-info.java @@ -1,5 +1,6 @@ -@API(apiVersion = "9.1.0", owner = "mekanism", provides = "MekanismAPI|gas") +@API(apiVersion = MekanismAPI.API_VERSION, owner = "mekanism", provides = "MekanismAPI|gas") package mekanism.api.gas; +import mekanism.api.MekanismAPI; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/mekanism/api/infuse/package-info.java b/src/main/java/mekanism/api/infuse/package-info.java index 41734f41c..04e996cec 100644 --- a/src/main/java/mekanism/api/infuse/package-info.java +++ b/src/main/java/mekanism/api/infuse/package-info.java @@ -1,5 +1,6 @@ -@API(apiVersion = "9.0.0", owner = "mekanism", provides = "MekanismAPI|infuse") +@API(apiVersion = MekanismAPI.API_VERSION, owner = "mekanism", provides = "MekanismAPI|infuse") package mekanism.api.infuse; +import mekanism.api.MekanismAPI; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/mekanism/api/lasers/package-info.java b/src/main/java/mekanism/api/lasers/package-info.java index 8377e3061..70ce4489f 100644 --- a/src/main/java/mekanism/api/lasers/package-info.java +++ b/src/main/java/mekanism/api/lasers/package-info.java @@ -1,5 +1,6 @@ -@API(apiVersion = "9.0.0", owner = "mekanism", provides = "MekanismAPI|laser") +@API(apiVersion = MekanismAPI.API_VERSION, owner = "mekanism", provides = "MekanismAPI|laser") package mekanism.api.lasers; +import mekanism.api.MekanismAPI; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/mekanism/api/package-info.java b/src/main/java/mekanism/api/package-info.java index be9037791..e3616d2c8 100644 --- a/src/main/java/mekanism/api/package-info.java +++ b/src/main/java/mekanism/api/package-info.java @@ -1,4 +1,4 @@ -@API(apiVersion = "9.0.0", owner = "mekanism", provides = "MekanismAPI|core") +@API(apiVersion = MekanismAPI.API_VERSION, owner = "mekanism", provides = "MekanismAPI|core") package mekanism.api; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/mekanism/api/transmitters/DynamicNetwork.java b/src/main/java/mekanism/api/transmitters/DynamicNetwork.java index f54fd3b7a..52f9dbb58 100644 --- a/src/main/java/mekanism/api/transmitters/DynamicNetwork.java +++ b/src/main/java/mekanism/api/transmitters/DynamicNetwork.java @@ -10,6 +10,7 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map.Entry; import java.util.Set; +import javax.annotation.Nullable; import mekanism.api.Coord4D; import mekanism.api.IClientTicker; import mekanism.api.Range4D; @@ -22,15 +23,17 @@ import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.eventhandler.Event; import org.apache.commons.lang3.tuple.Pair; -public abstract class DynamicNetwork> implements IClientTicker, INetworkDataHandler { +public abstract class DynamicNetwork, BUFFER> implements + IClientTicker, INetworkDataHandler { - public LinkedHashSet> transmitters = Sets.newLinkedHashSet(); - public LinkedHashSet> transmittersToAdd = Sets.newLinkedHashSet(); - public LinkedHashSet> transmittersAdded = Sets.newLinkedHashSet(); + public LinkedHashSet> transmitters = Sets.newLinkedHashSet(); + public LinkedHashSet> transmittersToAdd = Sets.newLinkedHashSet(); + public LinkedHashSet> transmittersAdded = Sets.newLinkedHashSet(); - public HashMap possibleAcceptors = new HashMap<>(); + public HashMap possibleAcceptors = new HashMap<>(); public HashMap> acceptorDirections = new HashMap<>(); - public HashMap, EnumSet> changedAcceptors = Maps.newHashMap(); + public HashMap, EnumSet> changedAcceptors = Maps + .newHashMap(); protected Range4D packetRange = null; protected int capacity = 0; protected double meanCapacity = 0; @@ -40,13 +43,13 @@ public abstract class DynamicNetwork> implemen protected World world = null; private Set updateQueue = new LinkedHashSet<>(); - public void addNewTransmitters(Collection> newTransmitters) { + public void addNewTransmitters(Collection> newTransmitters) { transmittersToAdd.addAll(newTransmitters); } public void commit() { if (!transmittersToAdd.isEmpty()) { - for (IGridTransmitter transmitter : transmittersToAdd) { + for (IGridTransmitter transmitter : transmittersToAdd) { if (transmitter.isValid()) { if (world == null) { world = transmitter.world(); @@ -56,7 +59,7 @@ public abstract class DynamicNetwork> implemen updateTransmitterOnSide(transmitter, side); } - transmitter.setTransmitterNetwork((N) this); + transmitter.setTransmitterNetwork((NETWORK) this); absorbBuffer(transmitter); transmitters.add(transmitter); } @@ -69,8 +72,9 @@ public abstract class DynamicNetwork> implemen } if (!changedAcceptors.isEmpty()) { - for (Entry, EnumSet> entry : changedAcceptors.entrySet()) { - IGridTransmitter transmitter = entry.getKey(); + for (Entry, EnumSet> entry : changedAcceptors + .entrySet()) { + IGridTransmitter transmitter = entry.getKey(); if (transmitter.isValid()) { EnumSet directionsChanged = entry.getValue(); @@ -85,8 +89,8 @@ public abstract class DynamicNetwork> implemen } } - public void updateTransmitterOnSide(IGridTransmitter transmitter, EnumFacing side) { - A acceptor = transmitter.getAcceptor(side); + public void updateTransmitterOnSide(IGridTransmitter transmitter, EnumFacing side) { + ACCEPTOR acceptor = transmitter.getAcceptor(side); Coord4D acceptorCoord = transmitter.coord().offset(side); EnumSet directions = acceptorDirections.get(acceptorCoord); @@ -114,7 +118,12 @@ public abstract class DynamicNetwork> implemen } - public abstract void absorbBuffer(IGridTransmitter transmitter); + @Nullable + public BUFFER getBuffer() { + return null; + } + + public abstract void absorbBuffer(IGridTransmitter transmitter); public abstract void clampBuffer(); @@ -126,12 +135,12 @@ public abstract class DynamicNetwork> implemen clampBuffer(); //Update all shares - for (IGridTransmitter transmitter : transmitters) { + for (IGridTransmitter transmitter : transmitters) { transmitter.updateShare(); } //Now invalidate the transmitters - for (IGridTransmitter transmitter : transmitters) { + for (IGridTransmitter transmitter : transmitters) { invalidateTransmitter(transmitter); } @@ -139,7 +148,7 @@ public abstract class DynamicNetwork> implemen deregister(); } - public void invalidateTransmitter(IGridTransmitter transmitter) { + public void invalidateTransmitter(IGridTransmitter transmitter) { if (!world.isRemote && transmitter.isValid()) { transmitter.takeShare(); transmitter.setTransmitterNetwork(null); @@ -147,7 +156,7 @@ public abstract class DynamicNetwork> implemen } } - public void acceptorChanged(IGridTransmitter transmitter, EnumFacing side) { + public void acceptorChanged(IGridTransmitter transmitter, EnumFacing side) { EnumSet directions = changedAcceptors.get(transmitter); if (directions != null) { @@ -159,9 +168,9 @@ public abstract class DynamicNetwork> implemen TransmitterNetworkRegistry.registerChangedNetwork(this); } - public void adoptTransmittersAndAcceptorsFrom(N net) { - for (IGridTransmitter transmitter : net.transmitters) { - transmitter.setTransmitterNetwork((N) this); + public void adoptTransmittersAndAcceptorsFrom(NETWORK net) { + for (IGridTransmitter transmitter : net.transmitters) { + transmitter.setTransmitterNetwork((NETWORK) this); transmitters.add(transmitter); transmittersAdded.add(transmitter); } @@ -196,7 +205,7 @@ public abstract class DynamicNetwork> implemen return null; } - IGridTransmitter initTransmitter = transmitters.iterator().next(); + IGridTransmitter initTransmitter = transmitters.iterator().next(); Coord4D initCoord = initTransmitter.coord(); int minX = initCoord.x; @@ -285,7 +294,7 @@ public abstract class DynamicNetwork> implemen return world; } - public abstract Set> getAcceptors(Object data); + public abstract Set> getAcceptors(Object data); public void tick() { onUpdate(); @@ -333,7 +342,7 @@ public abstract class DynamicNetwork> implemen public void clientTick() { } - public void queueClientUpdate(Collection> newTransmitters) { + public void queueClientUpdate(Collection> newTransmitters) { transmittersAdded.addAll(newTransmitters); updateDelay = 5; } @@ -342,9 +351,17 @@ public abstract class DynamicNetwork> implemen updateQueue.add(new DelayQueue(player)); } + public boolean isCompatibleWith(NETWORK other) { + return true; + } + + public boolean compatibleWithBuffer(BUFFER buffer) { + return true; + } + public static class TransmittersAddedEvent extends Event { - public DynamicNetwork network; + public DynamicNetwork network; public boolean newNetwork; public Collection newTransmitters; diff --git a/src/main/java/mekanism/api/transmitters/IGridTransmitter.java b/src/main/java/mekanism/api/transmitters/IGridTransmitter.java index 7a153adbf..2d37d55bb 100644 --- a/src/main/java/mekanism/api/transmitters/IGridTransmitter.java +++ b/src/main/java/mekanism/api/transmitters/IGridTransmitter.java @@ -1,11 +1,12 @@ package mekanism.api.transmitters; import java.util.Collection; +import javax.annotation.Nullable; import mekanism.api.Coord4D; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; -public interface IGridTransmitter> extends ITransmitter { +public interface IGridTransmitter, BUFFER> extends ITransmitter { boolean hasTransmitterNetwork(); @@ -14,14 +15,14 @@ public interface IGridTransmitter> extends ITr * * @return network this transmitter is using */ - N getTransmitterNetwork(); + NETWORK getTransmitterNetwork(); /** * Sets this transmitter segment's network to a new value. * * @param network - network to set to */ - void setTransmitterNetwork(N network); + void setTransmitterNetwork(NETWORK network); void setRequestsUpdate(); @@ -45,7 +46,7 @@ public interface IGridTransmitter> extends ITr Coord4D getAdjacentConnectableTransmitterCoord(EnumFacing side); - A getAcceptor(EnumFacing side); + ACCEPTOR getAcceptor(EnumFacing side); boolean isValid(); @@ -53,15 +54,50 @@ public interface IGridTransmitter> extends ITr void setOrphan(boolean orphaned); - N createEmptyNetwork(); + NETWORK createEmptyNetwork(); - N mergeNetworks(Collection toMerge); + NETWORK mergeNetworks(Collection toMerge); - N getExternalNetwork(Coord4D from); + NETWORK getExternalNetwork(Coord4D from); void takeShare(); void updateShare(); - Object getBuffer(); + /** + * @return The transmitter's buffer. + */ + @Nullable + BUFFER getBuffer(); + + /** + * If the transmitter does not have a buffer this will try to fallback on the network's buffer. + * @return The transmitter's buffer, or if null the network's buffer. + */ + @Nullable + default BUFFER getBufferWithFallback() { + BUFFER buffer = getBuffer(); + //If we don't have a buffer try falling back to the network's buffer + if (buffer == null && hasTransmitterNetwork()) { + return getTransmitterNetwork().getBuffer(); + } + return buffer; + } + + default boolean isCompatibleWith(IGridTransmitter other){ + return true; + } + + /** + * Gets called on an orphan if at least one attempted network fails to connect + * due to having connected to another network that is incompatible with the + * next attempted ones. + * + * This is primarily used for if extra handling needs to be done, such as + * refreshing the connections visually on a minor delay so that it has + * time to have the buffer no longer be null and properly compare the + * connection. + */ + default void connectionFailed() { + } } diff --git a/src/main/java/mekanism/api/transmitters/TransmitterNetworkRegistry.java b/src/main/java/mekanism/api/transmitters/TransmitterNetworkRegistry.java index 8bb75d8b1..77e7927eb 100644 --- a/src/main/java/mekanism/api/transmitters/TransmitterNetworkRegistry.java +++ b/src/main/java/mekanism/api/transmitters/TransmitterNetworkRegistry.java @@ -130,10 +130,10 @@ public class TransmitterNetworkRegistry { orphanTransmitters.clear(); } - public > DynamicNetwork getNetworkFromOrphan( - IGridTransmitter startOrphan) { + public , BUFFER> DynamicNetwork getNetworkFromOrphan( + IGridTransmitter startOrphan) { if (startOrphan.isValid() && startOrphan.isOrphan()) { - OrphanPathFinder finder = new OrphanPathFinder<>(startOrphan); + OrphanPathFinder finder = new OrphanPathFinder<>(startOrphan); finder.start(); N network; @@ -167,6 +167,13 @@ public class TransmitterNetworkRegistry { network.addNewTransmitters(finder.connectedTransmitters); + if (finder.someNetworksFailed) { + //At least one network that connection was attempted with is not compatible + // So inform this transmitter that there was a failed connection attempt + // so that it can refresh the connections + startOrphan.connectionFailed(); + } + return network; } @@ -197,18 +204,20 @@ public class TransmitterNetworkRegistry { return strings; } - public class OrphanPathFinder> { + public class OrphanPathFinder, BUFFER> { - public IGridTransmitter startPoint; + public IGridTransmitter startPoint; public HashSet iterated = Sets.newHashSet(); - public HashSet> connectedTransmitters = Sets.newHashSet(); + public HashSet> connectedTransmitters = Sets.newHashSet(); public HashSet networksFound = Sets.newHashSet(); private Deque queue = new LinkedList<>(); - public OrphanPathFinder(IGridTransmitter start) { + public boolean someNetworksFailed; + + public OrphanPathFinder(IGridTransmitter start) { startPoint = start; } @@ -231,9 +240,10 @@ public class TransmitterNetworkRegistry { iterated.add(from); if (orphanTransmitters.containsKey(from)) { - IGridTransmitter transmitter = orphanTransmitters.get(from); + IGridTransmitter transmitter = orphanTransmitters.get(from); - if (transmitter.isValid() && transmitter.isOrphan()) { + if (transmitter.isValid() && transmitter.isOrphan() && (connectedTransmitters.isEmpty() + || connectedTransmitters.stream().anyMatch(existing -> existing.isCompatibleWith(transmitter)))) { connectedTransmitters.add(transmitter); transmitter.setOrphan(false); @@ -256,8 +266,15 @@ public class TransmitterNetworkRegistry { public void addNetworkToIterated(Coord4D from) { N net = startPoint.getExternalNetwork(from); - if (net != null) { - networksFound.add(net); + //Make sure that there is an external network and that it is compatible with this buffer + if (net != null && net.compatibleWithBuffer(startPoint.getBuffer())) { + if (networksFound.isEmpty() || networksFound.iterator().next().isCompatibleWith(net)) { + networksFound.add(net); + } else { + //If it a network was found but it is incompatible, then mark we have a failed + // network so we can inform the transmitter it should do a tick delayed refresh + someNetworksFailed = true; + } } } } diff --git a/src/main/java/mekanism/api/transmitters/package-info.java b/src/main/java/mekanism/api/transmitters/package-info.java index 5af98bb0a..76788ca45 100644 --- a/src/main/java/mekanism/api/transmitters/package-info.java +++ b/src/main/java/mekanism/api/transmitters/package-info.java @@ -1,5 +1,6 @@ -@API(apiVersion = "9.0.0", owner = "mekanism", provides = "MekanismAPI|transmitter") +@API(apiVersion = MekanismAPI.API_VERSION, owner = "mekanism", provides = "MekanismAPI|transmitter") package mekanism.api.transmitters; +import mekanism.api.MekanismAPI; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index 9b20f0dda..e1715c609 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -111,8 +111,6 @@ import mekanism.common.CommonProxy; import mekanism.common.Mekanism; import mekanism.common.MekanismBlocks; import mekanism.common.MekanismItems; -import mekanism.common.tier.BaseTier; -import mekanism.common.tier.GasTankTier; import mekanism.common.base.IFactory.RecipeType; import mekanism.common.base.ISideConfiguration; import mekanism.common.base.IUpgradeTile; @@ -144,6 +142,8 @@ import mekanism.common.item.ItemPortableTeleporter; import mekanism.common.item.ItemSeismicReader; import mekanism.common.item.ItemWalkieTalkie; import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage; +import mekanism.common.tier.BaseTier; +import mekanism.common.tier.GasTankTier; import mekanism.common.tile.TileEntityAdvancedFactory; import mekanism.common.tile.TileEntityAmbientAccumulator; import mekanism.common.tile.TileEntityBin; @@ -175,7 +175,6 @@ import mekanism.common.tile.TileEntityGasTank; import mekanism.common.tile.TileEntityInductionCasing; import mekanism.common.tile.TileEntityLaserAmplifier; import mekanism.common.tile.TileEntityLaserTractorBeam; -import mekanism.common.tile.TileEntityLogisticalSorter; import mekanism.common.tile.TileEntityMetallurgicInfuser; import mekanism.common.tile.TileEntityOredictionificator; import mekanism.common.tile.TileEntityOsmiumCompressor; @@ -670,8 +669,10 @@ public class ClientProxy extends CommonProxy { if (type == MachineType.BASIC_FACTORY || type == MachineType.ADVANCED_FACTORY || type == MachineType.ELITE_FACTORY) { - RecipeType recipe = RecipeType.values()[((ItemBlockMachine) stack.getItem()).getRecipeType(stack)]; - resource = "mekanism:" + type.getName() + "_" + recipe.getName(); + RecipeType recipe = ((ItemBlockMachine) stack.getItem()).getRecipeTypeOrNull(stack); + if (recipe != null) { + resource = "mekanism:" + type.getName() + "_" + recipe.getName(); + } } return machineResources.get(resource); diff --git a/src/main/java/mekanism/client/jei/MekanismJEI.java b/src/main/java/mekanism/client/jei/MekanismJEI.java index 1d2043d8b..162018547 100644 --- a/src/main/java/mekanism/client/jei/MekanismJEI.java +++ b/src/main/java/mekanism/client/jei/MekanismJEI.java @@ -61,7 +61,10 @@ public class MekanismJEI implements IModPlugin { } if (itemStack.getItem() instanceof IFactory) { - ret += ":" + RecipeType.values()[((IFactory) itemStack.getItem()).getRecipeType(itemStack)].getName(); + RecipeType recipeType = ((IFactory) itemStack.getItem()).getRecipeTypeOrNull(itemStack); + if (recipeType != null) { + ret += ":" + recipeType.getName(); + } } if (itemStack.getItem() instanceof ItemBlockGasTank) { diff --git a/src/main/java/mekanism/common/base/IFactory.java b/src/main/java/mekanism/common/base/IFactory.java index 75062439e..d2b48331b 100644 --- a/src/main/java/mekanism/common/base/IFactory.java +++ b/src/main/java/mekanism/common/base/IFactory.java @@ -3,6 +3,7 @@ package mekanism.common.base; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import javax.annotation.Nullable; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; import mekanism.common.InfuseStorage; @@ -44,6 +45,15 @@ public interface IFactory { */ int getRecipeType(ItemStack itemStack); + /** + * Gets the recipe type this Factory currently has. + * + * @param itemStack - stack to check + * @return RecipeType or null if it has invalid NBT + */ + @Nullable + RecipeType getRecipeTypeOrNull(ItemStack itemStack); + /** * Sets the recipe type of this Smelting Factory to a new value. * diff --git a/src/main/java/mekanism/common/base/ILogisticalTransporter.java b/src/main/java/mekanism/common/base/ILogisticalTransporter.java index a8a69585a..d5c13b470 100644 --- a/src/main/java/mekanism/common/base/ILogisticalTransporter.java +++ b/src/main/java/mekanism/common/base/ILogisticalTransporter.java @@ -12,7 +12,7 @@ import mekanism.common.transmitters.grid.InventoryNetwork; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; -public interface ILogisticalTransporter extends IGridTransmitter, IBlockableConnection { +public interface ILogisticalTransporter extends IGridTransmitter, IBlockableConnection { TransitResponse insert(Coord4D original, TransitRequest request, EnumColor color, boolean doEmit, int min); diff --git a/src/main/java/mekanism/common/capabilities/DefaultGridTransmitter.java b/src/main/java/mekanism/common/capabilities/DefaultGridTransmitter.java index 1edb2d086..4185f213f 100644 --- a/src/main/java/mekanism/common/capabilities/DefaultGridTransmitter.java +++ b/src/main/java/mekanism/common/capabilities/DefaultGridTransmitter.java @@ -13,7 +13,7 @@ import net.minecraftforge.common.capabilities.CapabilityManager; /** * Created by ben on 03/05/16. */ -public class DefaultGridTransmitter> implements IGridTransmitter { +public class DefaultGridTransmitter, BUFFER> implements IGridTransmitter { public static void register() { CapabilityManager.INSTANCE.register(IGridTransmitter.class, new NullStorage<>(), DefaultGridTransmitter::new); @@ -130,7 +130,7 @@ public class DefaultGridTransmitter> implement } @Override - public Object getBuffer() { + public BUFFER getBuffer() { return null; } @@ -142,4 +142,9 @@ public class DefaultGridTransmitter> implement public TransmissionType getTransmissionType() { return null; } + + @Override + public boolean isCompatibleWith(IGridTransmitter other) { + return false; + } } diff --git a/src/main/java/mekanism/common/capabilities/DefaultLogisticalTransporter.java b/src/main/java/mekanism/common/capabilities/DefaultLogisticalTransporter.java index 55a8ee7eb..159b51959 100644 --- a/src/main/java/mekanism/common/capabilities/DefaultLogisticalTransporter.java +++ b/src/main/java/mekanism/common/capabilities/DefaultLogisticalTransporter.java @@ -3,6 +3,7 @@ package mekanism.common.capabilities; import java.util.Collection; import mekanism.api.Coord4D; import mekanism.api.EnumColor; +import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.TransmissionType; import mekanism.common.base.ILogisticalTransporter; import mekanism.common.capabilities.DefaultStorageHelper.NullStorage; @@ -188,7 +189,7 @@ public class DefaultLogisticalTransporter implements ILogisticalTransporter { } @Override - public Object getBuffer() { + public Void getBuffer() { return null; } @@ -200,4 +201,9 @@ public class DefaultLogisticalTransporter implements ILogisticalTransporter { public TransmissionType getTransmissionType() { return null; } + + @Override + public boolean isCompatibleWith(IGridTransmitter other) { + return false; + } } diff --git a/src/main/java/mekanism/common/item/ItemBlockMachine.java b/src/main/java/mekanism/common/item/ItemBlockMachine.java index d8ba765f0..7f6ee9166 100644 --- a/src/main/java/mekanism/common/item/ItemBlockMachine.java +++ b/src/main/java/mekanism/common/item/ItemBlockMachine.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import mekanism.api.Coord4D; import mekanism.api.EnumColor; import mekanism.api.Range4D; @@ -17,8 +18,6 @@ import mekanism.client.MekKeyHandler; import mekanism.client.MekanismClient; import mekanism.client.MekanismKeyHandler; import mekanism.common.Mekanism; -import mekanism.common.tier.BaseTier; -import mekanism.common.tier.FluidTankTier; import mekanism.common.Upgrade; import mekanism.common.base.FluidItemWrapper; import mekanism.common.base.IFactory; @@ -45,6 +44,8 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.security.ISecurityItem; import mekanism.common.security.ISecurityTile; import mekanism.common.security.ISecurityTile.SecurityMode; +import mekanism.common.tier.BaseTier; +import mekanism.common.tier.FluidTankTier; import mekanism.common.tile.TileEntityFactory; import mekanism.common.tile.TileEntityFluidTank; import mekanism.common.tile.TileEntityQuantumEntangloporter; @@ -144,19 +145,19 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec if (type == MachineType.BASIC_FACTORY || type == MachineType.ADVANCED_FACTORY || type == MachineType.ELITE_FACTORY) { - BaseTier tier = type == MachineType.BASIC_FACTORY ? BaseTier.BASIC - : (type == MachineType.ADVANCED_FACTORY ? BaseTier.ADVANCED : BaseTier.ELITE); + BaseTier tier = type.factoryTier.getBaseTier(); - if (I18n.canTranslate( - "tile." + tier.getSimpleName() + RecipeType.values()[getRecipeType(itemstack)].getTranslationKey() - + "Factory")) { - return LangUtils.localize( - "tile." + tier.getSimpleName() + RecipeType.values()[getRecipeType(itemstack)].getTranslationKey() - + "Factory"); + RecipeType recipeType = getRecipeTypeOrNull(itemstack); + if (recipeType != null) { + + String langKey = "tile." + tier.getSimpleName() + recipeType.getTranslationKey() + "Factory"; + if (I18n.canTranslate(langKey)) { + return LangUtils.localize(langKey); + } + + return tier.getLocalizedName() + " " + recipeType.getLocalizedName() + " " + super + .getItemStackDisplayName(itemstack); } - - return tier.getLocalizedName() + " " + RecipeType.values()[getRecipeType(itemstack)].getLocalizedName() - + " " + super.getItemStackDisplayName(itemstack); } else if (type == MachineType.FLUID_TANK) { return LangUtils.localize("tile.FluidTank" + getBaseTier(itemstack).getSimpleName() + ".name"); } @@ -222,9 +223,12 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec if (type == MachineType.BASIC_FACTORY || type == MachineType.ADVANCED_FACTORY || type == MachineType.ELITE_FACTORY) { - list.add( - EnumColor.INDIGO + LangUtils.localize("tooltip.recipeType") + ": " + EnumColor.GREY + RecipeType - .values()[getRecipeType(itemstack)].getLocalizedName()); + + RecipeType recipeType = getRecipeTypeOrNull(itemstack); + if (recipeType != null) { + list.add(EnumColor.INDIGO + LangUtils.localize("tooltip.recipeType") + ": " + EnumColor.GREY + + recipeType.getLocalizedName()); + } } if (type == MachineType.FLUID_TANK) { @@ -361,8 +365,10 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec if (tileEntity instanceof TileEntityFactory) { TileEntityFactory factory = (TileEntityFactory) tileEntity; - RecipeType recipeType = RecipeType.values()[getRecipeType(stack)]; - factory.setRecipeType(recipeType); + RecipeType recipeType = getRecipeTypeOrNull(stack); + if (recipeType != null) { + factory.setRecipeType(recipeType); + } world.notifyNeighborsOfStateChange(pos, tileEntity.getBlockType(), true); Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tileEntity), @@ -529,6 +535,16 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec return itemStack.getTagCompound().getInteger("recipeType"); } + @Nullable + @Override + public RecipeType getRecipeTypeOrNull(ItemStack itemStack) { + int recipeType = getRecipeType(itemStack); + if (recipeType < RecipeType.values().length) { + return RecipeType.values()[recipeType]; + } + return null; + } + @Override public void setRecipeType(int type, ItemStack itemStack) { if (itemStack.getTagCompound() == null) { @@ -627,9 +643,9 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec if (machineType.isFactory()) { // 200*tier.processes*recipeType.getEnergyUsage(); // From TileEntityFactory - RecipeType recipeType = RecipeType.values()[getRecipeType(itemStack)]; + RecipeType recipeType = getRecipeTypeOrNull(itemStack); int tierProcess = machineType.factoryTier.processes; - double baseMaxEnergy = 200 * tierProcess * recipeType.getEnergyUsage(); + double baseMaxEnergy = 200 * tierProcess * (recipeType == null ? 1 : recipeType.getEnergyUsage()); return MekanismUtils.getMaxEnergy(itemStack, baseMaxEnergy); } diff --git a/src/main/java/mekanism/common/network/PacketTransmitterUpdate.java b/src/main/java/mekanism/common/network/PacketTransmitterUpdate.java index 99d549e33..5c7c60915 100644 --- a/src/main/java/mekanism/common/network/PacketTransmitterUpdate.java +++ b/src/main/java/mekanism/common/network/PacketTransmitterUpdate.java @@ -7,12 +7,10 @@ import mekanism.api.Coord4D; import mekanism.api.gas.Gas; import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; -import mekanism.api.gas.IGasHandler; import mekanism.api.transmitters.DynamicNetwork; import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.TransmissionType; import mekanism.common.PacketHandler; -import mekanism.common.base.EnergyAcceptorWrapper; import mekanism.common.capabilities.Capabilities; import mekanism.common.config.MekanismConfig; import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage; @@ -25,7 +23,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; @@ -40,14 +37,21 @@ public class PacketTransmitterUpdate implements IMessageHandler - { - if (message.packetType == PacketType.UPDATE) { - TileEntity tileEntity = message.coord4D.getTileEntity(player.world); + PacketHandler.handlePacket(() -> { + if (message.coord4D == null) { + return; + } + TileEntity tileEntity = message.coord4D.getTileEntity(player.world); - if (CapabilityUtils.hasCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null)) { - IGridTransmitter transmitter = CapabilityUtils - .getCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null); + if (CapabilityUtils.hasCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null)) { + IGridTransmitter transmitter = CapabilityUtils + .getCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null); + if (transmitter == null) { + //Should never be the case, but removes the warning + return; + } + + if (message.packetType == PacketType.UPDATE) { DynamicNetwork network = transmitter.hasTransmitterNetwork() && !message.newNetwork ? transmitter .getTransmitterNetwork() : transmitter.createEmptyNetwork(); network.register(); @@ -63,37 +67,21 @@ public class PacketTransmitterUpdate implements IMessageHandler) transmitter) - .getTransmitterNetwork().clientEnergyScale = message.power; + TransmissionType transmissionType = transmitter.getTransmissionType(); + if (message.packetType == PacketType.ENERGY) { + if (transmissionType == TransmissionType.ENERGY) { + ((EnergyNetwork) transmitter.getTransmitterNetwork()).clientEnergyScale = message.power; } - } - } else if (message.packetType == PacketType.GAS) { - TileEntity tileEntity = message.coord4D.getTileEntity(player.world); - - if (CapabilityUtils.hasCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null)) { - IGridTransmitter transmitter = CapabilityUtils - .getCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null); - - if (transmitter.hasTransmitterNetwork() - && transmitter.getTransmissionType() == TransmissionType.GAS) { - GasNetwork net = ((IGridTransmitter) transmitter) - .getTransmitterNetwork(); + } else if (message.packetType == PacketType.GAS) { + if (transmissionType == TransmissionType.GAS) { + GasNetwork net = (GasNetwork) transmitter.getTransmitterNetwork(); if (message.gasType != null) { net.refGas = message.gasType; @@ -102,18 +90,9 @@ public class PacketTransmitterUpdate implements IMessageHandler) transmitter) - .getTransmitterNetwork(); + } else if (message.packetType == PacketType.FLUID) { + if (transmissionType == TransmissionType.FLUID) { + FluidNetwork net = (FluidNetwork) transmitter.getTransmitterNetwork(); if (message.fluidType != null) { net.refFluid = message.fluidType; diff --git a/src/main/java/mekanism/common/tile/transmitter/TileEntityLogisticalTransporter.java b/src/main/java/mekanism/common/tile/transmitter/TileEntityLogisticalTransporter.java index bc6b61791..34239c24a 100644 --- a/src/main/java/mekanism/common/tile/transmitter/TileEntityLogisticalTransporter.java +++ b/src/main/java/mekanism/common/tile/transmitter/TileEntityLogisticalTransporter.java @@ -42,7 +42,7 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.fml.common.FMLCommonHandler; -public class TileEntityLogisticalTransporter extends TileEntityTransmitter { +public class TileEntityLogisticalTransporter extends TileEntityTransmitter { private final int SYNC_PACKET = 1; private final int BATCH_PACKET = 2; @@ -385,7 +385,7 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter implements +public class TileEntityMechanicalPipe extends TileEntityTransmitter implements IFluidHandlerWrapper { public PipeTier tier = PipeTier.BASIC; @@ -167,6 +167,19 @@ public class TileEntityMechanicalPipe extends TileEntityTransmitter implements IGasHandler { +public class TileEntityPressurizedTube extends TileEntityTransmitter implements + IGasHandler { public TubeTier tier = TubeTier.BASIC; @@ -169,6 +171,19 @@ public class TileEntityPressurizedTube extends TileEntityTransmitter implements +public class TileEntityThermodynamicConductor extends TileEntityTransmitter implements IHeatTransfer { public ConductorTier tier = ConductorTier.BASIC; @@ -58,7 +58,7 @@ public class TileEntityThermodynamicConductor extends TileEntityTransmitter> extends TileEntitySidedPipe implements - IAlloyInteraction { +public abstract class TileEntityTransmitter, BUFFER> extends + TileEntitySidedPipe implements IAlloyInteraction { - public TransmitterImpl transmitterDelegate; + public TransmitterImpl transmitterDelegate; public boolean unloaded = true; - public boolean dataRequest = false; + public boolean delayedRefresh = false; private N lastClientNetwork = null; @@ -35,7 +38,7 @@ public abstract class TileEntityTransmitter> e transmitterDelegate = new TransmitterImpl<>(this); } - public TransmitterImpl getTransmitter() { + public TransmitterImpl getTransmitter() { return transmitterDelegate; } @@ -58,6 +61,13 @@ public abstract class TileEntityTransmitter> e public void update() { super.update(); + if (delayedRefresh) { + //Gets run the tick after the variable has been set. This is enough + // time to ensure that the transmitter has been registered. + delayedRefresh = false; + refreshConnections(); + } + if (getWorld().isRemote) { if (!dataRequest) { dataRequest = true; @@ -105,6 +115,103 @@ public abstract class TileEntityTransmitter> e } } + protected boolean canHaveIncompatibleNetworks() { + return false; + } + + @Override + protected void recheckConnections(byte newlyEnabledTransmitters) { + if (canHaveIncompatibleNetworks() && getTransmitter().hasTransmitterNetwork()) { + //We only need to check if we can have incompatible networks and if we actually have a network + boolean networkUpdated = false; + for (EnumFacing side : EnumFacing.values()) { + if (connectionMapContainsSide(newlyEnabledTransmitters, side)) { + //Recheck the side that is now enabled, as we manually merge this + // cannot be simplified to a first match is good enough + networkUpdated |= recheckConnectionPrechecked(side); + } + } + if (networkUpdated) { + refreshNetwork(); + } + } + } + + @Override + protected void recheckConnection(EnumFacing side) { + if (canHaveIncompatibleNetworks() && getTransmitter().hasTransmitterNetwork()) { + //We only need to check if we can have incompatible networks and if we actually have a network + if (recheckConnectionPrechecked(side)) { + refreshNetwork(); + } + } + } + + private void refreshNetwork() { + //Queue an update for all the transmitters in the network just in case something went wrong + // and to update the rendering of them + N network = getTransmitter().getTransmitterNetwork(); + network.queueClientUpdate(network.transmitters); + //Copy values into a set so that we don't risk a CME + Set> transmitters = new HashSet<>(network.transmitters); + //TODO: Make some better way of refreshing the connections, given we only need to refresh + // connections to ourself anyways + // The best way to do this is probably by making a method that updates the values for + // the valid transmitters manually if the network is the same object. + for (IGridTransmitter transmitter : transmitters) { + if (transmitter instanceof TransmitterImpl) { + //Refresh the connections because otherwise sometimes they need to wait for a block update + ((TransmitterImpl) transmitter).containingTile.refreshConnections(); + } + } + } + + private boolean recheckConnectionPrechecked(EnumFacing side) { + N network = getTransmitter().getTransmitterNetwork(); + TileEntity tileEntity = getWorld().getTileEntity(getPos().offset(side)); + if (tileEntity instanceof TileEntityTransmitter) { + TileEntityTransmitter other = (TileEntityTransmitter) tileEntity; + //The other one should always have the same incompatible networks state as us + // But just in case it doesn't just check the boolean + if (other.canHaveIncompatibleNetworks() && other.getTransmitter().hasTransmitterNetwork()) { + N otherNetwork = (N) other.getTransmitter().getTransmitterNetwork(); + if (network != otherNetwork && network.isCompatibleWith(otherNetwork)) { + //We have two networks that are now compatible and they are not the same source network + // The most common cause they would be same source network is that they would merge + // from the first pipe checking when it attempts to reconnect, and then the second + // pipe still is going to be checking the connection. + + if (getBufferWithFallback() == null) { + //If we don't have any use them as primary network + N tempNetwork = network; + network = otherNetwork; + otherNetwork = tempNetwork; + } + + // Manually merge the networks. + // This code is not in network registry as there is special handling needed to ensure + // it visually updates properly. There also were above checks that get us to a certain + // point where we can make some assumptions about the networks and if it is actually + // valid to merge them when otherwise people may try to merge things when they shouldn't + // be merged causing unexpected bugs. + network.adoptTransmittersAndAcceptorsFrom(otherNetwork); + //Unregister the other network + otherNetwork.deregister(); + //Commit the changes of the new network + network.commit(); + + //We did not have these as part of the update because they got directly added + // This means that we have to update the capacity/buffer and queue client updates + // ourselves + network.updateCapacity(); + network.clampBuffer(); + return true; + } + } + } + return false; + } + public abstract A getCachedAcceptor(EnumFacing side); protected TileEntity getCachedTile(EnumFacing side) { @@ -169,7 +276,18 @@ public abstract class TileEntityTransmitter> e public abstract int getCapacity(); - public abstract Object getBuffer(); + @Nullable + public abstract BUFFER getBuffer(); + + @Nullable + public BUFFER getBufferWithFallback() { + BUFFER buffer = getBuffer(); + //If we don't have a buffer try falling back to the network's buffer + if (buffer == null && getTransmitter().hasTransmitterNetwork()) { + return getTransmitter().getTransmitterNetwork().getBuffer(); + } + return buffer; + } public abstract void takeShare(); diff --git a/src/main/java/mekanism/common/tile/transmitter/TileEntityUniversalCable.java b/src/main/java/mekanism/common/tile/transmitter/TileEntityUniversalCable.java index 1a6446878..77876aeee 100644 --- a/src/main/java/mekanism/common/tile/transmitter/TileEntityUniversalCable.java +++ b/src/main/java/mekanism/common/tile/transmitter/TileEntityUniversalCable.java @@ -40,7 +40,7 @@ import net.minecraftforge.fml.common.Optional; @Optional.InterfaceList( @Optional.Interface(iface = "cofh.redstoneflux.api.IEnergyReceiver", modid = MekanismHooks.REDSTONEFLUX_MOD_ID) ) -public class TileEntityUniversalCable extends TileEntityTransmitter implements +public class TileEntityUniversalCable extends TileEntityTransmitter implements IStrictEnergyAcceptor, IStrictEnergyStorage, IEnergyReceiver { public CableTier tier = CableTier.BASIC; @@ -240,7 +240,7 @@ public class TileEntityUniversalCable extends TileEntityTransmitter> implements IGridTransmitter { +public abstract class Transmitter, BUFFER> implements IGridTransmitter { - public N theNetwork = null; + public NETWORK theNetwork = null; public boolean orphaned = true; @Override - public N getTransmitterNetwork() { + public NETWORK getTransmitterNetwork() { return theNetwork; } @Override - public void setTransmitterNetwork(N network) { + public void setTransmitterNetwork(NETWORK network) { if (theNetwork == network) { return; } diff --git a/src/main/java/mekanism/common/transmitters/TransmitterImpl.java b/src/main/java/mekanism/common/transmitters/TransmitterImpl.java index d375e709d..00ad822f0 100644 --- a/src/main/java/mekanism/common/transmitters/TransmitterImpl.java +++ b/src/main/java/mekanism/common/transmitters/TransmitterImpl.java @@ -1,6 +1,7 @@ package mekanism.common.transmitters; import java.util.Collection; +import javax.annotation.Nullable; import mekanism.api.Coord4D; import mekanism.api.transmitters.DynamicNetwork; import mekanism.api.transmitters.IGridTransmitter; @@ -12,11 +13,11 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; -public class TransmitterImpl> extends Transmitter { +public class TransmitterImpl, BUFFER> extends Transmitter { - public TileEntityTransmitter containingTile; + public TileEntityTransmitter containingTile; - public TransmitterImpl(TileEntityTransmitter multiPart) { + public TransmitterImpl(TileEntityTransmitter multiPart) { setTileEntity(multiPart); } @@ -61,7 +62,20 @@ public class TransmitterImpl> extends Transmit } @Override - public A getAcceptor(EnumFacing side) { + public boolean isCompatibleWith(IGridTransmitter other) { + if (other instanceof TransmitterImpl) { + return containingTile.isValidTransmitter(((TransmitterImpl) other).containingTile); + } + return true;//allow non-Transmitter impls to connect? + } + + @Override + public void connectionFailed() { + containingTile.delayedRefresh = true; + } + + @Override + public ACCEPTOR getAcceptor(EnumFacing side) { return getTileEntity().getCachedAcceptor(side); } @@ -78,12 +92,12 @@ public class TransmitterImpl> extends Transmit } @Override - public N createEmptyNetwork() { + public NETWORK createEmptyNetwork() { return getTileEntity().createNewNetwork(); } @Override - public N getExternalNetwork(Coord4D from) { + public NETWORK getExternalNetwork(Coord4D from) { TileEntity tile = from.getTileEntity(world()); if (CapabilityUtils.hasCapability(tile, Capabilities.GRID_TRANSMITTER_CAPABILITY, null)) { @@ -91,7 +105,7 @@ public class TransmitterImpl> extends Transmit .getCapability(tile, Capabilities.GRID_TRANSMITTER_CAPABILITY, null); if (TransmissionType.checkTransmissionType(transmitter, getTransmissionType())) { - return ((IGridTransmitter) transmitter).getTransmitterNetwork(); + return ((IGridTransmitter) transmitter).getTransmitterNetwork(); } } @@ -108,13 +122,20 @@ public class TransmitterImpl> extends Transmit containingTile.updateShare(); } + @Nullable @Override - public Object getBuffer() { + public BUFFER getBuffer() { return getTileEntity().getBuffer(); } + @Nullable @Override - public N mergeNetworks(Collection toMerge) { + public BUFFER getBufferWithFallback() { + return getTileEntity().getBufferWithFallback(); + } + + @Override + public NETWORK mergeNetworks(Collection toMerge) { return getTileEntity().createNetworkByMerging(toMerge); } @@ -128,11 +149,11 @@ public class TransmitterImpl> extends Transmit containingTile.sendDesc = true; } - public TileEntityTransmitter getTileEntity() { + public TileEntityTransmitter getTileEntity() { return containingTile; } - public void setTileEntity(TileEntityTransmitter containingPart) { + public void setTileEntity(TileEntityTransmitter containingPart) { this.containingTile = containingPart; } } diff --git a/src/main/java/mekanism/common/transmitters/TransporterImpl.java b/src/main/java/mekanism/common/transmitters/TransporterImpl.java index 0f89943c1..44e6e4f57 100644 --- a/src/main/java/mekanism/common/transmitters/TransporterImpl.java +++ b/src/main/java/mekanism/common/transmitters/TransporterImpl.java @@ -36,7 +36,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraftforge.common.util.Constants.NBT; -public class TransporterImpl extends TransmitterImpl implements ILogisticalTransporter { +public class TransporterImpl extends TransmitterImpl implements ILogisticalTransporter { private Map transit = new HashMap<>(); diff --git a/src/main/java/mekanism/common/transmitters/grid/EnergyNetwork.java b/src/main/java/mekanism/common/transmitters/grid/EnergyNetwork.java index 080703336..d5fcd18ca 100644 --- a/src/main/java/mekanism/common/transmitters/grid/EnergyNetwork.java +++ b/src/main/java/mekanism/common/transmitters/grid/EnergyNetwork.java @@ -7,6 +7,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.annotation.Nullable; import mekanism.api.Coord4D; import mekanism.api.energy.EnergyStack; import mekanism.api.transmitters.DynamicNetwork; @@ -20,7 +21,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.eventhandler.Event; import org.apache.commons.lang3.tuple.Pair; -public class EnergyNetwork extends DynamicNetwork { +public class EnergyNetwork extends DynamicNetwork { public double clientEnergyScale = 0; public EnergyStack buffer = new EnergyStack(0); @@ -34,15 +35,6 @@ public class EnergyNetwork extends DynamicNetwork networks) { for (EnergyNetwork net : networks) { if (net != null) { - if (net.jouleBufferLastTick > jouleBufferLastTick || net.clientEnergyScale > clientEnergyScale) { - clientEnergyScale = net.clientEnergyScale; - jouleBufferLastTick = net.jouleBufferLastTick; - joulesTransmitted = net.joulesTransmitted; - lastPowerScale = net.lastPowerScale; - } - - buffer.amount += net.buffer.amount; - adoptTransmittersAndAcceptorsFrom(net); net.deregister(); } @@ -51,13 +43,31 @@ public class EnergyNetwork extends DynamicNetwork jouleBufferLastTick || net.clientEnergyScale > clientEnergyScale) { + clientEnergyScale = net.clientEnergyScale; + jouleBufferLastTick = net.jouleBufferLastTick; + joulesTransmitted = net.joulesTransmitted; + lastPowerScale = net.lastPowerScale; + } + + buffer.amount += net.buffer.amount; + super.adoptTransmittersAndAcceptorsFrom(net); + } + public static double round(double d) { return Math.round(d * 10000) / 10000; } + @Nullable + public EnergyStack getBuffer() { + return buffer; + } + @Override - public void absorbBuffer(IGridTransmitter transmitter) { - EnergyStack energy = (EnergyStack) transmitter.getBuffer(); + public void absorbBuffer(IGridTransmitter transmitter) { + EnergyStack energy = transmitter.getBuffer(); buffer.amount += energy.amount; energy.amount = 0; } @@ -78,7 +88,7 @@ public class EnergyNetwork extends DynamicNetwork cable : transmitters) { + for (IGridTransmitter cable : transmitters) { reciprocalSum += 1.0 / (double) cable.getCapacity(); } diff --git a/src/main/java/mekanism/common/transmitters/grid/FluidNetwork.java b/src/main/java/mekanism/common/transmitters/grid/FluidNetwork.java index d1b523a44..664770a17 100644 --- a/src/main/java/mekanism/common/transmitters/grid/FluidNetwork.java +++ b/src/main/java/mekanism/common/transmitters/grid/FluidNetwork.java @@ -7,6 +7,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.annotation.Nullable; import mekanism.api.Coord4D; import mekanism.api.transmitters.DynamicNetwork; import mekanism.api.transmitters.IGridTransmitter; @@ -25,7 +26,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.eventhandler.Event; import org.apache.commons.lang3.tuple.Pair; -public class FluidNetwork extends DynamicNetwork { +public class FluidNetwork extends DynamicNetwork { public int transferDelay = 0; @@ -47,21 +48,6 @@ public class FluidNetwork extends DynamicNetwork { public FluidNetwork(Collection networks) { for (FluidNetwork net : networks) { if (net != null) { - if (net.buffer != null) { - if (buffer == null) { - buffer = net.buffer.copy(); - } else { - if (buffer.getFluid() == net.buffer.getFluid()) { - buffer.amount += net.buffer.amount; - } else if (net.buffer.amount > buffer.amount) { - buffer = net.buffer.copy(); - } - - } - - net.buffer = null; - } - adoptTransmittersAndAcceptorsFrom(net); net.deregister(); } @@ -73,15 +59,37 @@ public class FluidNetwork extends DynamicNetwork { } @Override - public void absorbBuffer(IGridTransmitter transmitter) { - Object b = transmitter.getBuffer(); + public void adoptTransmittersAndAcceptorsFrom(FluidNetwork net) { + if (net.buffer != null) { + if (buffer == null) { + buffer = net.buffer.copy(); + } else { + if (buffer.getFluid() == net.buffer.getFluid()) { + buffer.amount += net.buffer.amount; + } else if (net.buffer.amount > buffer.amount) { + buffer = net.buffer.copy(); + } - if (!(b instanceof FluidStack) || ((FluidStack) b).getFluid() == null || ((FluidStack) b).amount == 0) { + } + + net.buffer = null; + } + super.adoptTransmittersAndAcceptorsFrom(net); + } + + @Nullable + public FluidStack getBuffer() { + return buffer; + } + + @Override + public void absorbBuffer(IGridTransmitter transmitter) { + FluidStack fluid = transmitter.getBuffer(); + + if (fluid == null || fluid.getFluid() == null || fluid.amount == 0) { return; } - FluidStack fluid = (FluidStack) b; - if (buffer == null || buffer.getFluid() == null || buffer.amount == 0) { buffer = fluid.copy(); fluid.amount = 0; @@ -108,7 +116,7 @@ public class FluidNetwork extends DynamicNetwork { int numCables = transmitters.size(); double sum = 0; - for (IGridTransmitter pipe : transmitters) { + for (IGridTransmitter pipe : transmitters) { sum += pipe.getCapacity(); } @@ -309,6 +317,17 @@ public class FluidNetwork extends DynamicNetwork { return prevTransferAmount + " mB/t"; } + @Override + public boolean isCompatibleWith(FluidNetwork other) { + return super.isCompatibleWith(other) && (this.buffer == null || other.buffer == null || this.buffer + .isFluidEqual(other.buffer)); + } + + @Override + public boolean compatibleWithBuffer(FluidStack buffer) { + return super.compatibleWithBuffer(buffer) && (this.buffer == null || buffer == null || this.buffer.isFluidEqual(buffer)); + } + public static class FluidTransferEvent extends Event { public final FluidNetwork fluidNetwork; diff --git a/src/main/java/mekanism/common/transmitters/grid/GasNetwork.java b/src/main/java/mekanism/common/transmitters/grid/GasNetwork.java index 5b5e012cc..b0a7b3c70 100644 --- a/src/main/java/mekanism/common/transmitters/grid/GasNetwork.java +++ b/src/main/java/mekanism/common/transmitters/grid/GasNetwork.java @@ -7,6 +7,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.annotation.Nullable; import mekanism.api.Coord4D; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; @@ -29,7 +30,7 @@ import org.apache.commons.lang3.tuple.Pair; * * @author aidancbrady */ -public class GasNetwork extends DynamicNetwork { +public class GasNetwork extends DynamicNetwork { public int transferDelay = 0; @@ -51,33 +52,6 @@ public class GasNetwork extends DynamicNetwork { public GasNetwork(Collection networks) { for (GasNetwork net : networks) { if (net != null) { - if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { - if (net.refGas != null && net.gasScale > gasScale) { - gasScale = net.gasScale; - refGas = net.refGas; - buffer = net.buffer; - - net.gasScale = 0; - net.refGas = null; - net.buffer = null; - } - } else { - if (net.buffer != null) { - if (buffer == null) { - buffer = net.buffer.copy(); - } else { - if (buffer.isGasEqual(net.buffer)) { - buffer.amount += net.buffer.amount; - } else if (net.buffer.amount > buffer.amount) { - buffer = net.buffer.copy(); - } - - } - - net.buffer = null; - } - } - adoptTransmittersAndAcceptorsFrom(net); net.deregister(); } @@ -89,15 +63,48 @@ public class GasNetwork extends DynamicNetwork { } @Override - public void absorbBuffer(IGridTransmitter transmitter) { - Object b = transmitter.getBuffer(); + public void adoptTransmittersAndAcceptorsFrom(GasNetwork net) { + if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { + if (net.refGas != null && net.gasScale > gasScale) { + gasScale = net.gasScale; + refGas = net.refGas; + buffer = net.buffer; - if (!(b instanceof GasStack) || ((GasStack) b).getGas() == null || ((GasStack) b).amount == 0) { + net.gasScale = 0; + net.refGas = null; + net.buffer = null; + } + } else { + if (net.buffer != null) { + if (buffer == null) { + buffer = net.buffer.copy(); + } else { + if (buffer.isGasEqual(net.buffer)) { + buffer.amount += net.buffer.amount; + } else if (net.buffer.amount > buffer.amount) { + buffer = net.buffer.copy(); + } + + } + net.buffer = null; + } + } + super.adoptTransmittersAndAcceptorsFrom(net); + } + + @Nullable + public GasStack getBuffer() { + return buffer; + } + + @Override + public void absorbBuffer(IGridTransmitter transmitter) { + GasStack gas = transmitter.getBuffer(); + + if (gas == null || gas.getGas() == null || gas.amount == 0) { return; } - GasStack gas = (GasStack) b; - if (buffer == null || buffer.getGas() == null || buffer.amount == 0) { buffer = gas.copy(); gas.amount = 0; @@ -303,6 +310,18 @@ public class GasNetwork extends DynamicNetwork { return prevTransferAmount + "/t"; } + @Override + public boolean isCompatibleWith(GasNetwork other) { + return super.isCompatibleWith(other) && (this.buffer == null || other.buffer == null || this.buffer + .isGasEqual(other.buffer)); + } + + @Override + public boolean compatibleWithBuffer(GasStack buffer) { + return super.compatibleWithBuffer(buffer) && (this.buffer == null || buffer == null || this.buffer + .isGasEqual(buffer)); + } + public static class GasTransferEvent extends Event { public final GasNetwork gasNetwork; diff --git a/src/main/java/mekanism/common/transmitters/grid/HeatNetwork.java b/src/main/java/mekanism/common/transmitters/grid/HeatNetwork.java index 33ce47f30..ff2981b00 100644 --- a/src/main/java/mekanism/common/transmitters/grid/HeatNetwork.java +++ b/src/main/java/mekanism/common/transmitters/grid/HeatNetwork.java @@ -15,7 +15,7 @@ import org.apache.commons.lang3.tuple.Pair; //import mekanism.common.multipart.MultipartTransmitter; -public class HeatNetwork extends DynamicNetwork { +public class HeatNetwork extends DynamicNetwork { public double meanTemp = 0; @@ -55,7 +55,7 @@ public class HeatNetwork extends DynamicNetwork { } @Override - public void absorbBuffer(IGridTransmitter transmitter) { + public void absorbBuffer(IGridTransmitter transmitter) { } @Override @@ -76,7 +76,7 @@ public class HeatNetwork extends DynamicNetwork { double newHeatTransferred = 0; if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - for (IGridTransmitter transmitter : transmitters) { + for (IGridTransmitter transmitter : transmitters) { if (transmitter instanceof TransmitterImpl && ((TransmitterImpl) transmitter).getTileEntity() .hasCapability(Capabilities.HEAT_TRANSFER_CAPABILITY, null)) { IHeatTransfer heatTransmitter = (IHeatTransfer) ((TransmitterImpl) transmitter).getTileEntity() @@ -87,7 +87,7 @@ public class HeatNetwork extends DynamicNetwork { } } - for (IGridTransmitter transmitter : transmitters) { + for (IGridTransmitter transmitter : transmitters) { if (transmitter instanceof TransmitterImpl && ((TransmitterImpl) transmitter).getTileEntity() .hasCapability(Capabilities.HEAT_TRANSFER_CAPABILITY, null)) { IHeatTransfer heatTransmitter = (IHeatTransfer) ((TransmitterImpl) transmitter).getTileEntity() diff --git a/src/main/java/mekanism/common/transmitters/grid/InventoryNetwork.java b/src/main/java/mekanism/common/transmitters/grid/InventoryNetwork.java index ce58e1483..ea0a9e89f 100644 --- a/src/main/java/mekanism/common/transmitters/grid/InventoryNetwork.java +++ b/src/main/java/mekanism/common/transmitters/grid/InventoryNetwork.java @@ -18,7 +18,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraftforge.fml.common.FMLCommonHandler; -public class InventoryNetwork extends DynamicNetwork { +public class InventoryNetwork extends DynamicNetwork { public InventoryNetwork() { } @@ -82,7 +82,7 @@ public class InventoryNetwork extends DynamicNetwork transmitter) { + public void absorbBuffer(IGridTransmitter transmitter) { } @Override diff --git a/src/main/java/mekanism/common/util/RecipeUtils.java b/src/main/java/mekanism/common/util/RecipeUtils.java index f69d9149c..db5df4230 100644 --- a/src/main/java/mekanism/common/util/RecipeUtils.java +++ b/src/main/java/mekanism/common/util/RecipeUtils.java @@ -7,6 +7,7 @@ import mekanism.api.gas.GasStack; import mekanism.api.gas.IGasItem; import mekanism.common.Upgrade; import mekanism.common.base.IFactory; +import mekanism.common.base.IFactory.RecipeType; import mekanism.common.base.ITierItem; import mekanism.common.block.states.BlockStateBasic.BasicBlockType; import mekanism.common.block.states.BlockStateMachine.MachineType; @@ -47,8 +48,10 @@ public class RecipeUtils { if (target.getItem() instanceof IFactory && input.getItem() instanceof IFactory) { if (isFactory(target) && isFactory(input)) { - return ((IFactory) target.getItem()).getRecipeType(target) == ((IFactory) input.getItem()) - .getRecipeType(input); + RecipeType recipeTypeInput = ((IFactory) input.getItem()).getRecipeTypeOrNull(input); + //If either factory has invalid NBT don't crash it + return recipeTypeInput != null + && ((IFactory) target.getItem()).getRecipeTypeOrNull(target) == recipeTypeInput; } } From 0dba7cb5841c9bc32b9c11a76f54f0ab97313142 Mon Sep 17 00:00:00 2001 From: Xander Date: Sat, 20 Apr 2019 13:38:41 +0800 Subject: [PATCH 6/8] use getters & setters for InfuseStorage (#5416) * use getters & setters for InfuseStorage to prevent type/amount discrepancies * Fix a few checks when reading from network/NBT * Fix some spacing I screwed up by accident * fix metallurgic infuser gui texture for dark gauge --- .../java/mekanism/client/gui/GuiFactory.java | 6 +- .../client/gui/GuiMetallurgicInfuser.java | 8 +-- .../MetallurgicInfuserRecipeCategory.java | 2 +- .../MetallurgicInfuserRecipeWrapper.java | 6 +- .../java/mekanism/common/InfuseStorage.java | 59 +++++++++++++++++- .../java/mekanism/common/base/IFactory.java | 2 +- .../commands/MekRecipesCommand.java | 4 +- .../helpers/IngredientHelper.java | 2 +- .../inventory/container/ContainerFactory.java | 2 +- .../ContainerMetallurgicInfuser.java | 6 +- .../common/recipe/inputs/InfusionInput.java | 10 +-- .../common/tile/TileEntityFactory.java | 57 ++++++++--------- .../tile/TileEntityMetallurgicInfuser.java | 58 +++++++++-------- .../mekanism/gui/guimetallurgicinfuser.png | Bin 17162 -> 4215 bytes 14 files changed, 135 insertions(+), 87 deletions(-) diff --git a/src/main/java/mekanism/client/gui/GuiFactory.java b/src/main/java/mekanism/client/gui/GuiFactory.java index d41d80a3b..7ae50bad6 100644 --- a/src/main/java/mekanism/client/gui/GuiFactory.java +++ b/src/main/java/mekanism/client/gui/GuiFactory.java @@ -76,8 +76,8 @@ public class GuiFactory extends GuiMekanismTile { + ": " + tileEntity.gasTank.getStored() : LangUtils.localize("gui.none"), xAxis, yAxis); } else if (tileEntity.getRecipeType() == RecipeType.INFUSING) { drawHoveringText( - tileEntity.infuseStored.type != null ? tileEntity.infuseStored.type.getLocalizedName() + ": " - + tileEntity.infuseStored.amount : LangUtils.localize("gui.empty"), xAxis, yAxis); + tileEntity.infuseStored.getType() != null ? tileEntity.infuseStored.getType().getLocalizedName() + ": " + + tileEntity.infuseStored.getAmount() : LangUtils.localize("gui.empty"), xAxis, yAxis); } } super.drawGuiContainerForegroundLayer(mouseX, mouseY); @@ -116,7 +116,7 @@ public class GuiFactory extends GuiMekanismTile { } } else if (tileEntity.getRecipeType() == RecipeType.INFUSING) { if (tileEntity.getScaledInfuseLevel(160) > 0) { - displayGauge(8, 78, tileEntity.getScaledInfuseLevel(160), 5, tileEntity.infuseStored.type.sprite); + displayGauge(8, 78, tileEntity.getScaledInfuseLevel(160), 5, tileEntity.infuseStored.getType().sprite); } } super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); diff --git a/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java b/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java index a38276def..276e0fad1 100644 --- a/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java +++ b/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java @@ -71,8 +71,8 @@ public class GuiMetallurgicInfuser extends GuiMekanismTile= 7 && xAxis <= 11 && yAxis >= 17 && yAxis <= 69) { drawHoveringText( - tileEntity.infuseStored.type != null ? tileEntity.infuseStored.type.getLocalizedName() + ": " - + tileEntity.infuseStored.amount : LangUtils.localize("gui.empty"), xAxis, yAxis); + tileEntity.infuseStored.getType() != null ? tileEntity.infuseStored.getType().getLocalizedName() + ": " + + tileEntity.infuseStored.getAmount() : LangUtils.localize("gui.empty"), xAxis, yAxis); } super.drawGuiContainerForegroundLayer(mouseX, mouseY); } @@ -84,11 +84,11 @@ public class GuiMetallurgicInfuser extends GuiMekanismTile inputStacks = Collections.singletonList(recipe.recipeInput.inputStack); - List infuseStacks = MetallurgicInfuserRecipeCategory.getInfuseStacks(recipe.getInput().infuse.type); + List infuseStacks = MetallurgicInfuserRecipeCategory.getInfuseStacks(recipe.getInput().infuse.getType()); ingredients.setInput(VanillaTypes.ITEM, recipe.recipeInput.inputStack); ingredients.setInputLists(VanillaTypes.ITEM, Arrays.asList(inputStacks, infuseStacks)); ingredients.setOutput(VanillaTypes.ITEM, recipe.recipeOutput.output); @@ -37,7 +37,7 @@ public class MetallurgicInfuserRecipeWrapper implements IRecipeWrapper { public void drawInfo(Minecraft mc, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { if (mc.currentScreen != null) { mc.renderEngine.bindTexture(MekanismRenderer.getBlocksTexture()); - mc.currentScreen.drawTexturedModalRect(2, 2, recipe.getInput().infuse.type.sprite, 4, 52); + mc.currentScreen.drawTexturedModalRect(2, 2, recipe.getInput().infuse.getType().sprite, 4, 52); } } @@ -45,7 +45,7 @@ public class MetallurgicInfuserRecipeWrapper implements IRecipeWrapper { public List getTooltipStrings(int mouseX, int mouseY) { if (mouseX >= 2 && mouseX < 6 && mouseY >= 2 && mouseY < 54) { InfuseStorage infuse = recipe.getInput().infuse; - return Collections.singletonList(infuse.type.getLocalizedName() + ": " + infuse.amount); + return Collections.singletonList(infuse.getType().getLocalizedName() + ": " + infuse.getAmount()); } return Collections.emptyList(); } diff --git a/src/main/java/mekanism/common/InfuseStorage.java b/src/main/java/mekanism/common/InfuseStorage.java index 4ccf5ba1a..263fc5937 100644 --- a/src/main/java/mekanism/common/InfuseStorage.java +++ b/src/main/java/mekanism/common/InfuseStorage.java @@ -1,5 +1,6 @@ package mekanism.common; +import mekanism.api.infuse.InfuseObject; import mekanism.api.infuse.InfuseRegistry; import mekanism.api.infuse.InfuseType; import mekanism.common.base.ISustainedData; @@ -8,9 +9,9 @@ import net.minecraft.item.ItemStack; public class InfuseStorage implements ISustainedData { - public InfuseType type; + private InfuseType type; - public int amount; + private int amount; public InfuseStorage() { } @@ -30,6 +31,32 @@ public class InfuseStorage implements ISustainedData { } else if (type == storage.type) { amount = 0; } + if (amount <= 0) { + type = null; + amount = 0; + } + } + + public void increase(InfuseStorage input) { + if (type == null) { + type = input.type; + amount = input.amount; + } else if (type == input.type) { + amount += input.amount; + } else { + Mekanism.logger.error("Tried to increase infusion storage with an incompatible type", new Exception()); + } + } + + public void increase(InfuseObject input) { + if (type == null) { + type = input.type; + amount = input.stored; + } else if (type == input.type) { + amount += input.stored; + } else { + Mekanism.logger.error("Tried to increase infusion storage with an incompatible type", new Exception()); + } } @Override @@ -52,4 +79,30 @@ public class InfuseStorage implements ISustainedData { amount = 0; } } -} + + public InfuseType getType() { + return amount == 0 ? null : type; + } + + public InfuseStorage setType(InfuseType type) { + this.type = type; + return this; + } + + public int getAmount() { + return type == null ? 0 : amount; + } + + public InfuseStorage setAmount(int amount) { + if (amount < 0) { + throw new IllegalArgumentException("Amount must be positive"); + } + this.amount = amount; + return this; + } + + public void setEmpty() { + this.amount = 0; + this.type = null; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/base/IFactory.java b/src/main/java/mekanism/common/base/IFactory.java index d2b48331b..b2a2beb93 100644 --- a/src/main/java/mekanism/common/base/IFactory.java +++ b/src/main/java/mekanism/common/base/IFactory.java @@ -168,7 +168,7 @@ public interface IFactory { } else if (fuelType == MachineFuelType.CHANCE) { return getChanceRecipe(slotStack); } else if (this == INFUSING) { - if (infuse.type != null) { + if (infuse.getType() != null) { return RecipeHandler.getMetallurgicInfuserRecipe(new InfusionInput(infuse, slotStack)); } else { for (Entry entry : Recipe.METALLURGIC_INFUSER.get() diff --git a/src/main/java/mekanism/common/integration/crafttweaker/commands/MekRecipesCommand.java b/src/main/java/mekanism/common/integration/crafttweaker/commands/MekRecipesCommand.java index 02cdc0342..2357ce1f8 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/commands/MekRecipesCommand.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/commands/MekRecipesCommand.java @@ -173,8 +173,8 @@ public class MekRecipesCommand extends CraftTweakerCommand { type = Recipe.METALLURGIC_INFUSER; for (MetallurgicInfuserRecipe recipe : Recipe.METALLURGIC_INFUSER.get().values()) { CraftTweakerAPI.logCommand(String.format("mods.mekanism.infuser.addRecipe(%s, %s, %s, %s)", - recipe.getInput().infuse.type, - recipe.getInput().infuse.amount, + recipe.getInput().infuse.getType(), + recipe.getInput().infuse.getAmount(), RecipeInfoHelper.getItemName(recipe.getInput().inputStack), RecipeInfoHelper.getItemName(recipe.getOutput().output) )); diff --git a/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java b/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java index 5e0162bfe..552d9949b 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java @@ -110,7 +110,7 @@ public class IngredientHelper { } else if (in instanceof InfusionInput) { InfusionInput input = (InfusionInput) in; return matches(input.inputStack, toMatch.getIngredient()) && (toMatch.getInfuseType().isEmpty() || toMatch - .getInfuseType().equalsIgnoreCase(input.infuse.type.name)); + .getInfuseType().equalsIgnoreCase(input.infuse.getType().name)); } else if (in instanceof IntegerInput) { IntegerInput input = (IntegerInput) in; return input.ingredient == toMatch.getAmount(); diff --git a/src/main/java/mekanism/common/inventory/container/ContainerFactory.java b/src/main/java/mekanism/common/inventory/container/ContainerFactory.java index 77d1bc982..5be7dab36 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerFactory.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerFactory.java @@ -109,7 +109,7 @@ public class ContainerFactory extends ContainerMekanism { return ItemStack.EMPTY; } } else if (tileEntity.getRecipeType() == RecipeType.INFUSING && InfuseRegistry.getObject(slotStack) != null - && (tileEntity.infuseStored.type == null || tileEntity.infuseStored.type == InfuseRegistry + && (tileEntity.infuseStored.getType() == null || tileEntity.infuseStored.getType() == InfuseRegistry .getObject(slotStack).type)) { if (transferExtraSlot(slotID, slotStack)) { return ItemStack.EMPTY; diff --git a/src/main/java/mekanism/common/inventory/container/ContainerMetallurgicInfuser.java b/src/main/java/mekanism/common/inventory/container/ContainerMetallurgicInfuser.java index bf76723b8..80228a1ac 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerMetallurgicInfuser.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerMetallurgicInfuser.java @@ -31,8 +31,8 @@ public class ContainerMetallurgicInfuser extends ContainerMekanism { public ItemStack inputStack = ItemStack.EMPTY; public InfusionInput(InfuseStorage storage, ItemStack itemStack) { - infuse = new InfuseStorage(storage.type, storage.amount); + infuse = new InfuseStorage(storage.getType(), storage.getAmount()); inputStack = itemStack; } @@ -47,12 +47,12 @@ public class InfusionInput extends MachineInput { @Override public InfusionInput copy() { - return new InfusionInput(infuse.type, infuse.amount, inputStack.copy()); + return new InfusionInput(infuse.getType(), infuse.getAmount(), inputStack.copy()); } @Override public boolean isValid() { - return infuse.type != null && !inputStack.isEmpty(); + return infuse.getType() != null && !inputStack.isEmpty(); } public boolean use(NonNullList inventory, int index, InfuseStorage infuseStorage, boolean deplete) { @@ -70,7 +70,7 @@ public class InfusionInput extends MachineInput { @Override public int hashIngredients() { - return infuse.type.unlocalizedName.hashCode() << 8 | StackUtils.hashItemStack(inputStack); + return infuse.getType().unlocalizedName.hashCode() << 8 | StackUtils.hashItemStack(inputStack); } @Override @@ -79,7 +79,7 @@ public class InfusionInput extends MachineInput { return !other.isValid(); } - return infuse.type == other.infuse.type && MachineInput.inputItemMatches(inputStack, other.inputStack); + return infuse.getType() == other.infuse.getType() && MachineInput.inputItemMatches(inputStack, other.inputStack); } @Override diff --git a/src/main/java/mekanism/common/tile/TileEntityFactory.java b/src/main/java/mekanism/common/tile/TileEntityFactory.java index 98fec4c5c..65ebb0ea8 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFactory.java +++ b/src/main/java/mekanism/common/tile/TileEntityFactory.java @@ -342,11 +342,6 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt } } - if (infuseStored.amount <= 0) { - infuseStored.amount = 0; - infuseStored.type = null; - } - lastUsage = prev - getEnergy(); prevEnergy = getEnergy(); } @@ -479,7 +474,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt }*/ else if (cached.recipeInput instanceof InfusionInput) { InfusionInput infusionInput = (InfusionInput) cached.recipeInput; recipeInput = infusionInput.inputStack; - secondaryMatch = infuseStored.amount == 0 || infuseStored.type == infusionInput.infuse.type; + secondaryMatch = infuseStored.getAmount() == 0 || infuseStored.getType() == infusionInput.infuse.getType(); } //If there is no cached item input or it doesn't match our fallback // then it is an out of date cache so we compare against the new one @@ -536,13 +531,11 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt inventory.get(4).shrink(1); } } else if (recipeType == RecipeType.INFUSING) { - if (InfuseRegistry.getObject(inventory.get(4)) != null) { - InfuseObject infuse = InfuseRegistry.getObject(inventory.get(4)); - - if (infuseStored.type == null || infuseStored.type == infuse.type) { - if (infuseStored.amount + infuse.stored <= maxInfuse) { - infuseStored.amount += infuse.stored; - infuseStored.type = infuse.type; + InfuseObject pendingInfusionInput = InfuseRegistry.getObject(inventory.get(4)); + if (pendingInfusionInput != null) { + if (infuseStored.getType() == null || infuseStored.getType() == pendingInfusionInput.type) { + if (infuseStored.getAmount() + pendingInfusionInput.stored <= maxInfuse) { + infuseStored.increase(pendingInfusionInput); inventory.get(4).shrink(1); } } @@ -620,8 +613,8 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt } else if (recipeType.getFuelType() == MachineFuelType.DOUBLE) { return recipeType.hasRecipeForExtra(itemstack); } else if (recipeType == RecipeType.INFUSING) { - return InfuseRegistry.getObject(itemstack) != null && (infuseStored.type == null - || infuseStored.type == InfuseRegistry.getObject(itemstack).type); + return InfuseRegistry.getObject(itemstack) != null && (infuseStored.getType() == null + || infuseStored.getType() == InfuseRegistry.getObject(itemstack).type); } } @@ -633,7 +626,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt } public int getScaledInfuseLevel(int i) { - return infuseStored.amount * i / maxInfuse; + return infuseStored.getAmount() * i / maxInfuse; } public int getScaledGasLevel(int i) { @@ -765,8 +758,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt sorting = !sorting; } else if (type == 1) { gasTank.setGas(null); - infuseStored.amount = 0; - infuseStored.type = null; + infuseStored.setEmpty(); } return; @@ -782,9 +774,12 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt sorting = dataStream.readBoolean(); upgraded = dataStream.readBoolean(); lastUsage = dataStream.readDouble(); - infuseStored.amount = dataStream.readInt(); - if (infuseStored.amount > 0) { - infuseStored.type = InfuseRegistry.get(PacketHandler.readString(dataStream)); + int amount = dataStream.readInt(); + if (amount > 0) { + infuseStored.setAmount(amount); + infuseStored.setType(InfuseRegistry.get(PacketHandler.readString(dataStream))); + } else { + infuseStored.setEmpty(); } if (recipeType != oldRecipe) { @@ -816,8 +811,11 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt upgradeComponent.setSupported(Upgrade.GAS, recipeType.fuelEnergyUpgrades()); recipeTicks = nbtTags.getInteger("recipeTicks"); sorting = nbtTags.getBoolean("sorting"); - infuseStored.amount = nbtTags.getInteger("infuseStored"); - infuseStored.type = InfuseRegistry.get(nbtTags.getString("type")); + int amount = nbtTags.getInteger("infuseStored"); + if (amount != 0) { + infuseStored.setAmount(amount); + infuseStored.setType(InfuseRegistry.get(nbtTags.getString("type"))); + } for (int i = 0; i < tier.processes; i++) { progress[i] = nbtTags.getInteger("progress" + i); @@ -834,10 +832,9 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt nbtTags.setInteger("recipeType", recipeType.ordinal()); nbtTags.setInteger("recipeTicks", recipeTicks); nbtTags.setBoolean("sorting", sorting); - nbtTags.setInteger("infuseStored", infuseStored.amount); - - if (infuseStored.type != null) { - nbtTags.setString("type", infuseStored.type.name); + if (infuseStored.getType() != null) { + nbtTags.setString("type", infuseStored.getType().name); + nbtTags.setInteger("infuseStored", infuseStored.getAmount()); } else { nbtTags.setString("type", "null"); } @@ -861,9 +858,9 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt data.add(upgraded); data.add(lastUsage); - data.add(infuseStored.amount); - if (infuseStored.amount > 0) { - data.add(infuseStored.type.name); + data.add(infuseStored.getAmount()); + if (infuseStored.getAmount() > 0) { + data.add(infuseStored.getType().name); } data.add(progress); diff --git a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java index 28e78d05a..25eec1ccb 100644 --- a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java +++ b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java @@ -87,13 +87,11 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i ChargeUtils.discharge(4, this); if (!inventory.get(1).isEmpty()) { - if (InfuseRegistry.getObject(inventory.get(1)) != null) { - InfuseObject infuse = InfuseRegistry.getObject(inventory.get(1)); - - if (infuseStored.type == null || infuseStored.type == infuse.type) { - if (infuseStored.amount + infuse.stored <= MAX_INFUSE) { - infuseStored.amount += infuse.stored; - infuseStored.type = infuse.type; + InfuseObject pendingInfuseInput = InfuseRegistry.getObject(inventory.get(1)); + if (pendingInfuseInput != null) { + if (infuseStored.getType() == null || infuseStored.getType() == pendingInfuseInput.type) { + if (infuseStored.getAmount() + pendingInfuseInput.stored <= MAX_INFUSE) { + infuseStored.increase(pendingInfuseInput); inventory.get(1).shrink(1); } } @@ -122,11 +120,6 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i operatingTicks = 0; } - if (infuseStored.amount <= 0) { - infuseStored.amount = 0; - infuseStored.type = null; - } - prevEnergy = getEnergy(); } } @@ -207,13 +200,13 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i if (slotID == 3) { return false; } else if (slotID == 1) { - return InfuseRegistry.getObject(itemstack) != null && (infuseStored.type == null - || infuseStored.type == InfuseRegistry.getObject(itemstack).type); + return InfuseRegistry.getObject(itemstack) != null && (infuseStored.getType() == null + || infuseStored.getType() == InfuseRegistry.getObject(itemstack).type); } else if (slotID == 0) { return itemstack.getItem() == MekanismItems.SpeedUpgrade || itemstack.getItem() == MekanismItems.EnergyUpgrade; } else if (slotID == 2) { - if (infuseStored.type != null) { + if (infuseStored.getType() != null) { return RecipeHandler.getMetallurgicInfuserRecipe(new InfusionInput(infuseStored, itemstack)) != null; } else { return Recipe.METALLURGIC_INFUSER.get().keySet().stream() @@ -242,15 +235,18 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i } public int getScaledInfuseLevel(int i) { - return infuseStored.amount * i / MAX_INFUSE; + return infuseStored.getAmount() * i / MAX_INFUSE; } @Override public void readFromNBT(NBTTagCompound nbtTags) { super.readFromNBT(nbtTags); - infuseStored.amount = nbtTags.getInteger("infuseStored"); - infuseStored.type = InfuseRegistry.get(nbtTags.getString("type")); + int amount = nbtTags.getInteger("infuseStored"); + if (amount != 0) { + infuseStored.setAmount(amount); + infuseStored.setType(InfuseRegistry.get(nbtTags.getString("type"))); + } } @Nonnull @@ -258,10 +254,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i public NBTTagCompound writeToNBT(NBTTagCompound nbtTags) { super.writeToNBT(nbtTags); - nbtTags.setInteger("infuseStored", infuseStored.amount); - - if (infuseStored.type != null) { - nbtTags.setString("type", infuseStored.type.name); + if (infuseStored.getType() != null) { + nbtTags.setString("type", infuseStored.getType().name); + nbtTags.setInteger("infuseStored", infuseStored.getAmount()); } else { nbtTags.setString("type", "null"); } @@ -274,16 +269,19 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i @Override public void handlePacketData(ByteBuf dataStream) { if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - infuseStored.amount = dataStream.readInt(); + infuseStored.setAmount(dataStream.readInt()); return; } super.handlePacketData(dataStream); if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { - infuseStored.amount = dataStream.readInt(); - if (infuseStored.amount > 0) { - infuseStored.type = InfuseRegistry.get(PacketHandler.readString(dataStream)); + int amount = dataStream.readInt(); + if (amount > 0) { + infuseStored.setAmount(amount); + infuseStored.setType(InfuseRegistry.get(PacketHandler.readString(dataStream))); + } else { + infuseStored.setEmpty(); } } } @@ -292,9 +290,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i public TileNetworkList getNetworkedData(TileNetworkList data) { super.getNetworkedData(data); - data.add(infuseStored.amount); - if (infuseStored.amount > 0) { - data.add(infuseStored.type.name); + data.add(infuseStored.getAmount()); + if (infuseStored.getAmount() > 0) { + data.add(infuseStored.getType().name); } return data; @@ -323,7 +321,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i case 6: return new Object[]{infuseStored}; case 7: - return new Object[]{MAX_INFUSE - infuseStored.amount}; + return new Object[]{MAX_INFUSE - infuseStored.getAmount()}; default: throw new NoSuchMethodException(); } diff --git a/src/main/resources/assets/mekanism/gui/guimetallurgicinfuser.png b/src/main/resources/assets/mekanism/gui/guimetallurgicinfuser.png index a8d74869197a8c6afc0f8d89ba811c2e33d661b5..df1edd647c7e3debba88a085138cf142a877817c 100644 GIT binary patch delta 2155 zcmah|c~BEq7=H`lMnD*q84kCLS`k8SlB|Ry!~+#!0Oe2|mSh84Aq&YOVH`+kty2{c zU3)p6ZIv18h1zP1A}U3uv{lO=T3b0p>xBnJq;mF!08$6_&20AN_kHj8eed`EcJoH0 z7p)BNv;CKfj*eeM>PS7MMiUk((Re+rrE*9BWKGox?Y4gXd)<}-0G#p`ry2lo@v=M! z*tyFa0EhEzEhi2^SvR|IUMN>B5KB<0JVX#G63gYmsE{v^@%S>HK*SY<;$l876r!UG z3ujC0lx%~YKl{uskezKG%%<#+}Hozf>O>+qHM2)$5c(k4*7+Rl1(>V%^ z-S6OQ!d~H|ieN|u21`k}d{{@GB#`0)IWCrQ`BI$Ex2DF@8cJI%v8k_@3C7~(C-CTq4vjcaLrF2N`;DwoJ2d3m}l49&}?8QPFd!@lVpS`RD3 z_Cyo$7$~?^V+A&e@FN|^#^NzL14HQ4WQGsa;-o_hGt4-!cg@Xfr?famab;8*er*IcEj5m&j zInP{%hC$(=l#3|?G*A&dX$dEi`J=lW3NM#=|UE7*X0PCGT~WM`9|{pw?4)7GcNI6I2T=TO$q+ zep zWeTVd*t+=a1yt*1R8QTwPccurVfxa$%Wikn#%=y;*5egF*6rQ2|x9y?^37iK)d z!IHtA0Th@4umO(X_02b5_uh9o`A278?a+e#CxW+J%VvsgTf)Ev1|NLhrT^i%OLXO> z*=CVVoxk;L5eMz;v;ES(ZVsA)fENHDpc4TrL0!!&=yPCR3L=3C#yG$O?%-y-tJ$Zt z&KWccz!MG!W=sPa?qk7;S@V(iI=~q(kHY}0xA4F-9-uAVHp2p$eXZ|tW^>^bb3bSs z?C~!q!u)46-TmD)ssiyYU-(m((Ik$BB^p1l1H)@;ZhasAcV;!e+9q<|@~XtO>Yn~$ zuZNzHdV6)+k)!nKnXR>S-(Qa}JAzGV$F95Y{iVIT=lav()y=KZpfRJz12col2R|c7 zTY1U$){x!@pXGI4IZ*qwb+@VBu@^ZtC~VW7eEF!m=GK$G+Czt)wG}WcOq^ci>dx+$ zo!_lT(B$DhD)u7s#g%*4hU+xKz!&}J^2@rP%PzHF74_7t1noW^0Rv0&ji~o!*_8@4 z{jlJy^Q04-FvF{<<@b;ct#@@D=N+XL`S%YtL`Us*)a(i=GnlZ-Xj9brY`b`qZKkZN zK~~)%o7y-!!^w=`2pr9UP*&j`723g+_^!FUDYD_gfNVLZ@8Gn^!6~1#*ZXwTS9GXQ zIF-r0Wa$hA2jR>cE4@m~noTeBjk_DXO80Hq<#@*;btEuXiFG#kv>UQ??|VZ@8MSjk zj}+aQNSAxfulSXMu6Q?dVrh9ZB=)PaVSTG?YB(bnJF#l0x#GA}%8*{}>o#YGFdf

3i7soG)s8m4|To5$|+|5b?Nep2XNhOGY3W`cdCLx6^WRU*YNAKnG=pB8%vkF$*IjzW_5bAp6 zebXoIr?(4o6?ysLM`xB5t;?U!tWDy)yh8UWpSHOsojV|=`t?kD=DIbR=^MvQ9oqep z?}$d9>|LoLN1}&?2)D$UfKY%8~4{1T>leLuKfqD#vemuHWw z4t)1&)Lq}(_3ZnDh{Kmf^0gal#+JIf46$c~KOGsnam9}72S?u@cB;jl@-CrAgUf=0 zu9FB)osXPPnLOwDW`0HFkx8MSFVW>5)9X{}pS*rFe9ir%Yp%{pDzEA_KQI0;_Y}$X z_@m|l!{W=@sJL}oEF8n2~dU?@z&5LtFkH=j|8(t(;CST;_ zF3E^L;`yW3!hQ~Sb1VJU)w=p@5UKXgUY1(7s^Ibo@(V)nqv`Yd*8Mu{#RSFO%Cd9I zQhUvReDkUGrKreVqFE0=EgrLawwTDV83Q+OIj8b|z&SX2+oh_!+>KE2pn$pkR}Z6Q#gz7V!HV2x zLEXJ}X^-QB6qCcPtb)@*tHRRyFVE)NLC=#P>Piz&rT5%>{bzcheG&fwLW7?oF+@ zoIk&@sc-y;bs3T|ncA);rFI9>t?J+B6I=F;d0pT~JeFEm_q2B~JLg2st(-SiwlDVN z99*{Uz1P7dC#D1mWTLfK*qp$%OZ%O}%_@cF&b_SoY?VA`J1up4=SLJga$t@W1O7QO(>U{9M=Qm0PdY z)CwA&ElinlmC8FhE1bM@<$)O~+&{i01?2~wK9gBR=*bmS46b@s&Hi0`OiQrIC@H>r z^=$zof5CLCkS6EX+rL#QtoKG2gIoap?l$+vy&v!r1NL+Q}2Wy==GF%`6+JSOWcX=Lw28RA`~>FxHa6hVKnxuj`GCcP+Q%Lx6k@; zFzDLSr2B=L7SW6>&)bV%U7X}L&*Ig0ADZgt&m3@Ui;TX-{?+lP&DJqBHKK;hhay$Y z#KsdginAa4MS(=^fXBPOgLeg-ASjFnz*2bYSZN2qyVU?JssSKX2SA+?0Pp<(;HQll z8^nS8c2@*NsQ~zj@wHjan242iP9RN4Es>esF1L2JX7s8i9 zV1h=%gVg+l1dUQG5pZQ9jS5l{6*6&grj7vsQ!9yxR7diHSpvC~$QR0EA);2QfOP<1 zdutVZK|G|!#X@3<%nSeW=m|VdBJ{#fqw~l-g+CN02})5y;VB^zf|PgxQ;7HG*s`@O zSU?Kr#A&4oG8Iefg*WK3;Cp>D36C>$QOA4Xef0@(k-Sixzg!97=tMd}K&Db~o=hTz zPGeFiV{ue6#hpYUlc-Drg~FnFvM3%n(}m~Q!gp+?P{axg2sEXGEiZhWTCHG_NJ&Xa z#3Xm3Tq!0|m`o;#OeImN1h@x5l`K>9wFH^U)hN=c69B0MN{K=(k;`y;U4E=wqxQn% z^@-Xp)3~IHwnQ?Oi5*Olq~$9}6e5|_S&&fB7NgK86AX_g6p)|XSp@>fE9wOkn?mnU$HRo4Etg62{J*4P-q%b=C}4@?N-1B>kx2Pshy-r~Y*Krp zS3fDV0g^#Vi2xTi!LRij$6Uy)XQxU5a)Cy_ zHhg6QNCnTR%50|L`8KS6KfbtQYpWwc!hxrkD3l0U45}}k!WbXu@9RgUP{z}k{uF

p>qne!as1?N4DUCsTW?5TD@*c?cO40_5&NBY4nhWCGKZP9;!j9`x8) zD&$V42s;-uwsw42a};Pp)z>1A$KuLVYCcSY8(=!+z|<18AABpgcY*xFtshOJ(~SE?ZWM&^ZY-O1YC4aQ0^)q`O}Wbp<1mjp+k z-)A6r!aKCKKUP~L+t@+!Pbct;@UQ1cii2cmo0U<@(Ch0WD!E9V#8*PTVtDcWpDolV z*f9dBjJ6~?PEBjEemRwF{cC~+mjV1pd;@+8oAgCnduC(*Nd0ssXbk;5sbu(qzbD|! z6l(59hDM=>n!Ayq?U7St5;X^2f`$i0G@C`~-(|+#HXQ!!f;b*@cynTtkj==5P>B{w zhzyXxd!$NVkW{*dDG2H5G&1U|k!BuKq;U$(K9LOT$=C{ifWhB>q_&U0FP2){Lijgt z+K2RSsv@+oBnTkrCWZ^055kM#LI6QGFzw@M5?SK+sJL7djt= z7sG`Bf^K5C(D@*|7%l`5bQ8mc&IjSea3O%8n;0&1J_s*{3jqY(#BibWL3lA-2q5St zh6|k!!i(WT06{k~TkLg$0}M&`k^%Iv<1=!-W8XZeqC5`5?R) zE(8#C6T^kh2jRtVA%LKp7%p@^2rq^U0R-K|aG~=-crjcEAm}EB3!M+bi{U~5K{qj6 z=zI`f3>N|jx{2XJ=Y#NKxDY_lO;lXA?Z+u08GME^2|g_OJB_mpK4{rre`GVunj|JSFM7TD_|e57^MrhB*pIon+jB=3+6>zZc2!Ew ziwe^(h$ve_1P7=8Oc^;8T%SnAp$!@EAn}_TLy53eXmG;q=MJ~FEX<({Vj6LWD zeDqq@tv5E#AnCL3Nee~O5M!QAK9;Z_gwv> zhwpNW-MORRekdMbnF@R+j{(iI>)yP7BshNj_~uB9n32`h)iRH3rKJnIYr4az7G9z8 zXuO7pbv53k?_V~@TkC$9PTVBEd!AQ0mp$)&6R~BSwa#*?{kew~0o}mPJeOV|u+jTn zy)tti*Wt>b7Y#|ZLzvg<-dymu`S@Z^;{{P42M6h`!0VdTd4JsF0NJCKmOJ7mOP`#N zum3z_`ReuS^)1$#ndNhi(pM+u4Hk1UQ?ox^v(3t@+dCq1Y~O-AvQ>hNJ>>MS(iA%RntX@Uz?cXZP!#2fU9Yo=Q6^wrNZ{!E6WFp`>PU_<%#&UUWj=! zljsG{WjI`Tj%Swpls#!-+`e?W&ktE^GP*tJZJ1@e2fW-;*ys$tn353hYQe zcG=a=Ba&RUR1z&v2J8cZExLhFT(;%F?4}xpcSskJBE$BXQFo;5-6d%-9=|i~$Q_wj zx$Ux(Ps-f6w1GVWZyj>@>``!5!TMqAD1MOl(WR626)Ai3a7EVbh1X#K9c%KhyZ&h$ h>X1>KCRdjDljU~SxcBvuglho4xZ^_t^88{J{10q&nl1nU From 77d774e55fad0c432e5e8a99a05ff95f4ef285f5 Mon Sep 17 00:00:00 2001 From: Richard Freimer Date: Sat, 20 Apr 2019 10:45:13 -0400 Subject: [PATCH 7/8] Particle fixes (#5411) * Make transmitters return an actual particle instead of the default WHITE Make fluid tank particle/break particle be the glass wall Have hit particle for fluid tank and transmitters use the correct tier instead of being basic. Running and Falling particle still displays as the basic tier * Get actual state for transmitters (gets the proper tier data so that we don't have to manually replace it) * Fix dif of just imports * Fix dif of just imports * query the blockstate directly for the MachineType * remove incorrect copy-pasted use of FML logger * remove unnecessary list wrapping * tidy copied particle code a little and un-inline constants * use built in singleton rather than immulatble list --- .../client/render/MekanismRenderer.java | 7 +- .../client/render/obj/MekanismOBJLoader.java | 24 ++--- .../client/render/obj/OBJBakedModelBase.java | 14 +-- .../client/render/obj/TransmitterModel.java | 9 +- .../particle/MekanismParticleHelper.java | 87 +++++++++++++++++++ .../particle/TieredParticleDigging.java | 33 +++++++ .../transmitter/RenderTransmitterBase.java | 19 ++-- .../mekanism/common/base/ITieredTile.java | 8 ++ .../mekanism/common/block/BlockMachine.java | 21 ++++- .../common/block/BlockTransmitter.java | 15 +++- .../common/tile/TileEntityFluidTank.java | 13 ++- .../mekanism/models/block/fluid_tank.json | 3 + 12 files changed, 216 insertions(+), 37 deletions(-) create mode 100644 src/main/java/mekanism/client/render/particle/MekanismParticleHelper.java create mode 100644 src/main/java/mekanism/client/render/particle/TieredParticleDigging.java create mode 100644 src/main/java/mekanism/common/base/ITieredTile.java diff --git a/src/main/java/mekanism/client/render/MekanismRenderer.java b/src/main/java/mekanism/client/render/MekanismRenderer.java index da0d45c7d..5b048464c 100644 --- a/src/main/java/mekanism/client/render/MekanismRenderer.java +++ b/src/main/java/mekanism/client/render/MekanismRenderer.java @@ -117,8 +117,7 @@ public class MekanismRenderer { spriteLocation = fluid.getFlowing(); } - TextureAtlasSprite sprite = texMap.getTextureExtry(spriteLocation.toString()); - return sprite != null ? sprite : missingIcon; + return getTextureAtlasSprite(spriteLocation); } public static TextureAtlasSprite getFluidTexture(FluidStack fluidStack, FluidType type) { @@ -134,6 +133,10 @@ public class MekanismRenderer { } else { spriteLocation = fluid.getFlowing(fluidStack); } + return getTextureAtlasSprite(spriteLocation); + } + + public static TextureAtlasSprite getTextureAtlasSprite(ResourceLocation spriteLocation) { TextureAtlasSprite sprite = texMap.getTextureExtry(spriteLocation.toString()); return sprite != null ? sprite : missingIcon; } diff --git a/src/main/java/mekanism/client/render/obj/MekanismOBJLoader.java b/src/main/java/mekanism/client/render/obj/MekanismOBJLoader.java index 01bffe68a..7bac05e97 100644 --- a/src/main/java/mekanism/client/render/obj/MekanismOBJLoader.java +++ b/src/main/java/mekanism/client/render/obj/MekanismOBJLoader.java @@ -1,12 +1,13 @@ package mekanism.client.render.obj; -import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import java.util.HashMap; import java.util.Map; +import java.util.function.Function; import javax.annotation.Nonnull; import mekanism.client.render.obj.MekanismOBJModel.OBJModelType; +import mekanism.common.Mekanism; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ModelResourceLocation; @@ -15,6 +16,7 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.resources.IResourceManager; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.model.ICustomModelLoader; import net.minecraftforge.client.model.IModel; @@ -23,10 +25,10 @@ import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.obj.OBJLoader; import net.minecraftforge.client.model.obj.OBJModel; import net.minecraftforge.client.model.obj.OBJModel.OBJBakedModel; +import net.minecraftforge.client.model.obj.OBJModel.OBJState; import net.minecraftforge.common.model.IModelState; import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.apache.logging.log4j.Level; public class MekanismOBJLoader implements ICustomModelLoader { @@ -39,13 +41,12 @@ public class MekanismOBJLoader implements ICustomModelLoader { public void onModelBake(ModelBakeEvent event) { GlowPanelModel.forceRebake(); + IRegistry modelRegistry = event.getModelRegistry(); for (String s : OBJ_RENDERS) { ModelResourceLocation model = new ModelResourceLocation("mekanism:" + s, "inventory"); - IBakedModel bakedModel = event.getModelRegistry().getObject(model); - event.getModelRegistry().putObject(model, - createBakedObjItemModel(bakedModel, "mekanism:models/block/" + s + ".obj.mek", - new OBJModel.OBJState(Lists.newArrayList(OBJModel.Group.ALL), true), - DefaultVertexFormats.ITEM)); + IBakedModel bakedModel = modelRegistry.getObject(model); + modelRegistry.putObject(model, createBakedObjItemModel(bakedModel, "mekanism:models/block/" + s + + ".obj.mek", new OBJState(Lists.newArrayList(OBJModel.Group.ALL), true), DefaultVertexFormats.ITEM)); } } @@ -63,14 +64,13 @@ public class MekanismOBJLoader implements ICustomModelLoader { TextureAtlasSprite missing = textureGetter.apply(new ResourceLocation("missingno")); for (String s : objModel.getMatLib().getMaterialNames()) { - if (objModel.getMatLib().getMaterial(s).getTexture().getTextureLocation().getPath().startsWith("#")) { - FMLLog.log(Level.ERROR, "OBJLoader: Unresolved texture '%s' for obj model '%s'", - objModel.getMatLib().getMaterial(s).getTexture().getTextureLocation().getPath(), + ResourceLocation texture = objModel.getMatLib().getMaterial(s).getTexture().getTextureLocation(); + if (texture.getPath().startsWith("#")) { + Mekanism.logger.error("OBJLoader: Unresolved texture '{}' for obj model '{}'", texture.getPath(), modelLocation); builder.put(s, missing); } else { - builder.put(s, - textureGetter.apply(objModel.getMatLib().getMaterial(s).getTexture().getTextureLocation())); + builder.put(s, textureGetter.apply(texture)); } } diff --git a/src/main/java/mekanism/client/render/obj/OBJBakedModelBase.java b/src/main/java/mekanism/client/render/obj/OBJBakedModelBase.java index 614b08820..b96d56951 100644 --- a/src/main/java/mekanism/client/render/obj/OBJBakedModelBase.java +++ b/src/main/java/mekanism/client/render/obj/OBJBakedModelBase.java @@ -166,8 +166,9 @@ public abstract class OBJBakedModelBase extends OBJBakedModel { for (Face f : faces) { String groupName = groupNameMap.get(f); - if (getOverrideTexture(f, groupName) != null) { - tempSprite = getOverrideTexture(f, groupName); + TextureAtlasSprite overrideTexture = getOverrideTexture(f, groupName); + if (overrideTexture != null) { + tempSprite = overrideTexture; } else if (getModel().getMatLib().getMaterial(f.getMaterialName()).isWhite()) { for (Vertex v : f.getVertices()) { if (!v.getMaterial().equals(getModel().getMatLib().getMaterial(v.getMaterial().getName()))) { @@ -182,8 +183,9 @@ public abstract class OBJBakedModelBase extends OBJBakedModel { float[] color = new float[]{1, 1, 1, 1}; - if (getOverrideColor(f, groupName) != null) { - color = getOverrideColor(f, groupName); + float[] overrideColor = getOverrideColor(f, groupName); + if (overrideColor != null) { + color = overrideColor; } EnumFacing facing = EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z); @@ -214,9 +216,7 @@ public abstract class OBJBakedModelBase extends OBJBakedModel { bakedQuads.add(quad); } - List quadList = Collections.synchronizedList(Lists.newArrayList(bakedQuads)); - - return quadList; + return bakedQuads; } @SuppressWarnings("deprecation") diff --git a/src/main/java/mekanism/client/render/obj/TransmitterModel.java b/src/main/java/mekanism/client/render/obj/TransmitterModel.java index 5fd708e33..0ee7af6c0 100644 --- a/src/main/java/mekanism/client/render/obj/TransmitterModel.java +++ b/src/main/java/mekanism/client/render/obj/TransmitterModel.java @@ -68,12 +68,13 @@ public class TransmitterModel extends OBJBakedModelBase { private TransmitterModel itemCache; private IBlockState tempState; private ItemStack tempStack; + private TextureAtlasSprite particle; private TransmitterOverride override = new TransmitterOverride(); public TransmitterModel(IBakedModel base, OBJModel model, IModelState state, VertexFormat format, ImmutableMap textures, HashMap transform) { super(base, model, state, format, textures, transform); - + particle = textureMap.getOrDefault("None_Center", textureMap.getOrDefault("CentreMaterial", tempSprite)); modelInstances.add(this); } @@ -179,6 +180,12 @@ public class TransmitterModel extends OBJBakedModelBase { return null; } + @Nonnull + @Override + public TextureAtlasSprite getParticleTexture() { + return particle; + } + @Override public TextureAtlasSprite getOverrideTexture(Face f, String groupName) { if (tempState != null) { diff --git a/src/main/java/mekanism/client/render/particle/MekanismParticleHelper.java b/src/main/java/mekanism/client/render/particle/MekanismParticleHelper.java new file mode 100644 index 000000000..c60f75740 --- /dev/null +++ b/src/main/java/mekanism/client/render/particle/MekanismParticleHelper.java @@ -0,0 +1,87 @@ +package mekanism.client.render.particle; + +import mekanism.api.EnumColor; +import mekanism.common.base.ITieredTile; +import mekanism.common.util.MekanismUtils; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.particle.ParticleManager; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumBlockRenderType; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class MekanismParticleHelper { + + /** Centre offset? */ + private static final double OFFSET_1 = 0.20000000298023224D; + + /** Side offset? */ + private static final double OFFSET_2 = 0.10000000149011612D; + + /** + * Adds block hit particles for the specified block, accounting for tier colour + * @see ParticleManager#addBlockHitEffects(net.minecraft.util.math.BlockPos, net.minecraft.util.EnumFacing) for source of copy + * + * @param world relevant world + * @param pos position of block + * @param side which side was hit + * @param manager vanilla particle manager in use + * @return true if handled (always true) + */ + public static boolean addBlockHitEffects(World world, BlockPos pos, EnumFacing side, ParticleManager manager) { + TileEntity tile = MekanismUtils.getTileEntitySafe(world, pos); + EnumColor color = null; + IBlockState iblockstate = world.getBlockState(pos); + //Makes it so transmitters don't need to change their tier + iblockstate = iblockstate.getBlock().getActualState(iblockstate, world, pos); + if (tile instanceof ITieredTile) { + color = ((ITieredTile) tile).getTier().getColor(); + } + + if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE) { + int blockX = pos.getX(); + int blockY = pos.getY(); + int blockZ = pos.getZ(); + AxisAlignedBB axisalignedbb = iblockstate.getBoundingBox(world, pos); + double particleX = (double) blockX + world.rand.nextDouble() * (axisalignedbb.maxX - axisalignedbb.minX + - OFFSET_1) + OFFSET_2 + axisalignedbb.minX; + double particleY = (double) blockY + world.rand.nextDouble() * (axisalignedbb.maxY - axisalignedbb.minY + - OFFSET_1) + OFFSET_2 + axisalignedbb.minY; + double particleZ = (double) blockZ + world.rand.nextDouble() * (axisalignedbb.maxZ - axisalignedbb.minZ + - OFFSET_1) + OFFSET_2 + axisalignedbb.minZ; + + if (side == EnumFacing.DOWN) { + particleY = (double) blockY + axisalignedbb.minY - OFFSET_2; + } + + if (side == EnumFacing.UP) { + particleY = (double) blockY + axisalignedbb.maxY + OFFSET_2; + } + + if (side == EnumFacing.NORTH) { + particleZ = (double) blockZ + axisalignedbb.minZ - OFFSET_2; + } + + if (side == EnumFacing.SOUTH) { + particleZ = (double) blockZ + axisalignedbb.maxZ + OFFSET_2; + } + + if (side == EnumFacing.WEST) { + particleX = (double) blockX + axisalignedbb.minX - OFFSET_2; + } + + if (side == EnumFacing.EAST) { + particleX = (double) blockX + axisalignedbb.maxX + OFFSET_2; + } + + manager.addEffect(new TieredParticleDigging(world, particleX, particleY, particleZ, 0, 0, 0, iblockstate, color) + .setBlockPos(pos).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F)); + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/render/particle/TieredParticleDigging.java b/src/main/java/mekanism/client/render/particle/TieredParticleDigging.java new file mode 100644 index 000000000..e1ff4a73a --- /dev/null +++ b/src/main/java/mekanism/client/render/particle/TieredParticleDigging.java @@ -0,0 +1,33 @@ +package mekanism.client.render.particle; + +import javax.annotation.Nullable; +import mekanism.api.EnumColor; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.particle.ParticleDigging; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class TieredParticleDigging extends ParticleDigging { + + @Nullable + private final EnumColor color; + + public TieredParticleDigging(World world, double xCoord, double yCoord, double zCoord, double xSpeed, + double ySpeed, double zSpeed, IBlockState state, EnumColor color) { + super(world, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, state); + this.color = color; + } + + @Override + protected void multiplyColor(@Nullable BlockPos pos) { + if (color == null) { + return; + } + this.particleRed *= color.getColor(0); + this.particleGreen *= color.getColor(1); + this.particleBlue *= color.getColor(2); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/render/transmitter/RenderTransmitterBase.java b/src/main/java/mekanism/client/render/transmitter/RenderTransmitterBase.java index 5260794dd..a8766cc34 100644 --- a/src/main/java/mekanism/client/render/transmitter/RenderTransmitterBase.java +++ b/src/main/java/mekanism/client/render/transmitter/RenderTransmitterBase.java @@ -1,10 +1,11 @@ package mekanism.client.render.transmitter; -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Set; +import java.util.function.Function; import mekanism.client.render.MekanismRenderer; import mekanism.common.ColourRGBA; import mekanism.common.tile.transmitter.TileEntityTransmitter; @@ -22,6 +23,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.Attributes; import net.minecraftforge.client.model.obj.OBJLoader; import net.minecraftforge.client.model.obj.OBJModel; +import net.minecraftforge.client.model.obj.OBJModel.OBJState; import net.minecraftforge.client.model.pipeline.LightUtil; import org.lwjgl.opengl.GL11; @@ -47,15 +49,12 @@ public abstract class RenderTransmitterBase ext public static HashMap buildModelMap(OBJModel objModel) { HashMap modelParts = new HashMap<>(); - - if (!objModel.getMatLib().getGroups().keySet().isEmpty()) { - for (String key : objModel.getMatLib().getGroups().keySet()) { - String k = key; - + Set keys = objModel.getMatLib().getGroups().keySet(); + if (!keys.isEmpty()) { + for (String key : keys) { if (!modelParts.containsKey(key)) { - modelParts.put(k, objModel - .bake(new OBJModel.OBJState(ImmutableList.of(k), false), Attributes.DEFAULT_BAKED_FORMAT, - textureGetterFlipV)); + modelParts.put(key, objModel.bake(new OBJState(Collections.singletonList(key), false), + Attributes.DEFAULT_BAKED_FORMAT, textureGetterFlipV)); } } } diff --git a/src/main/java/mekanism/common/base/ITieredTile.java b/src/main/java/mekanism/common/base/ITieredTile.java new file mode 100644 index 000000000..bba6e128e --- /dev/null +++ b/src/main/java/mekanism/common/base/ITieredTile.java @@ -0,0 +1,8 @@ +package mekanism.common.base; + +import mekanism.common.tier.BaseTier; + +public interface ITieredTile { + + BaseTier getTier(); +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/block/BlockMachine.java b/src/main/java/mekanism/common/block/BlockMachine.java index 9de9c054c..70af891d8 100644 --- a/src/main/java/mekanism/common/block/BlockMachine.java +++ b/src/main/java/mekanism/common/block/BlockMachine.java @@ -7,8 +7,8 @@ import mekanism.api.Coord4D; import mekanism.api.IMekWrench; import mekanism.api.energy.IEnergizedItem; import mekanism.api.energy.IStrictEnergyStorage; +import mekanism.client.render.particle.MekanismParticleHelper; import mekanism.common.Mekanism; -import mekanism.common.tier.FluidTankTier; import mekanism.common.base.IActiveState; import mekanism.common.base.IBoundingBlock; import mekanism.common.base.IFactory; @@ -32,6 +32,7 @@ import mekanism.common.network.PacketLogisticalSorterGui.LogisticalSorterGuiMess import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket; import mekanism.common.security.ISecurityItem; import mekanism.common.security.ISecurityTile; +import mekanism.common.tier.FluidTankTier; import mekanism.common.tile.TileEntityFactory; import mekanism.common.tile.TileEntityFluidTank; import mekanism.common.tile.TileEntityLaser; @@ -56,6 +57,7 @@ import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.particle.ParticleManager; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -77,6 +79,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.RayTraceResult.Type; import net.minecraft.util.math.Vec3d; import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; @@ -806,6 +809,22 @@ public abstract class BlockMachine extends BlockContainer { return itemStack; } + @Override + @SideOnly(Side.CLIENT) + public boolean addHitEffects(IBlockState state, World world, RayTraceResult target, ParticleManager manager) { + if (!target.typeOfHit.equals(Type.BLOCK)) { + return super.addHitEffects(state, world, target, manager); + } + MachineType type = state.getValue(getTypeProperty()); + //If it is one of the types that block state won't have a color for + if (type == MachineType.FLUID_TANK) { + if (MekanismParticleHelper.addBlockHitEffects(world, target.getBlockPos(), target.sideHit, manager)) { + return true; + } + } + return super.addHitEffects(state, world, target, manager); + } + @Override public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { MachineType type = MachineType.get(getMachineBlock(), state.getBlock().getMetaFromState(state)); diff --git a/src/main/java/mekanism/common/block/BlockTransmitter.java b/src/main/java/mekanism/common/block/BlockTransmitter.java index 1fc6af8dd..09d96c8b3 100644 --- a/src/main/java/mekanism/common/block/BlockTransmitter.java +++ b/src/main/java/mekanism/common/block/BlockTransmitter.java @@ -6,9 +6,9 @@ import java.util.Random; import javax.annotation.Nonnull; import javax.annotation.Nullable; import mekanism.api.IMekWrench; +import mekanism.client.render.particle.MekanismParticleHelper; import mekanism.common.Mekanism; import mekanism.common.MekanismBlocks; -import mekanism.common.tier.BaseTier; import mekanism.common.base.ITierItem; import mekanism.common.block.property.PropertyConnection; import mekanism.common.block.states.BlockStateTransmitter; @@ -16,6 +16,7 @@ import mekanism.common.block.states.BlockStateTransmitter.TransmitterType; import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size; import mekanism.common.integration.multipart.MultipartMekanism; import mekanism.common.integration.wrenches.Wrenches; +import mekanism.common.tier.BaseTier; import mekanism.common.tile.transmitter.TileEntityDiversionTransporter; import mekanism.common.tile.transmitter.TileEntityLogisticalTransporter; import mekanism.common.tile.transmitter.TileEntityMechanicalPipe; @@ -33,6 +34,7 @@ import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.particle.ParticleManager; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -49,6 +51,7 @@ import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.RayTraceResult.Type; import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -286,6 +289,16 @@ public class BlockTransmitter extends Block implements ITileEntityProvider { return itemStack; } + @Override + @SideOnly(Side.CLIENT) + public boolean addHitEffects(IBlockState state, World world, RayTraceResult target, ParticleManager manager) { + if (!target.typeOfHit.equals(Type.BLOCK)) { + return super.addHitEffects(state, world, target, manager); + } + return MekanismParticleHelper.addBlockHitEffects(world, target.getBlockPos(), target.sideHit, manager) || + super.addHitEffects(state, world, target, manager); + } + public ItemStack dismantleBlock(IBlockState state, World world, BlockPos pos, boolean returnBlock) { ItemStack itemStack = getPickBlock(state, null, world, pos, null); diff --git a/src/main/java/mekanism/common/tile/TileEntityFluidTank.java b/src/main/java/mekanism/common/tile/TileEntityFluidTank.java index d92a6167e..dacd77d34 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFluidTank.java +++ b/src/main/java/mekanism/common/tile/TileEntityFluidTank.java @@ -8,8 +8,6 @@ import mekanism.api.IConfigurable; import mekanism.api.Range4D; import mekanism.api.TileNetworkList; import mekanism.common.Mekanism; -import mekanism.common.tier.BaseTier; -import mekanism.common.tier.FluidTankTier; import mekanism.common.base.FluidHandlerWrapper; import mekanism.common.base.IActiveState; import mekanism.common.base.IFluidContainerManager; @@ -17,10 +15,13 @@ import mekanism.common.base.IFluidHandlerWrapper; import mekanism.common.base.ISustainedTank; import mekanism.common.base.ITankManager; import mekanism.common.base.ITierUpgradeable; +import mekanism.common.base.ITieredTile; import mekanism.common.capabilities.Capabilities; import mekanism.common.config.MekanismConfig; import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.security.ISecurityTile; +import mekanism.common.tier.BaseTier; +import mekanism.common.tier.FluidTankTier; import mekanism.common.tile.component.TileComponentSecurity; import mekanism.common.tile.prefab.TileEntityContainerBlock; import mekanism.common.util.CapabilityUtils; @@ -51,7 +52,8 @@ import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.items.CapabilityItemHandler; public class TileEntityFluidTank extends TileEntityContainerBlock implements IActiveState, IConfigurable, - IFluidHandlerWrapper, ISustainedTank, IFluidContainerManager, ITankManager, ISecurityTile, ITierUpgradeable { + IFluidHandlerWrapper, ISustainedTank, IFluidContainerManager, ITankManager, ISecurityTile, ITierUpgradeable, + ITieredTile { public boolean isActive; @@ -574,4 +576,9 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc public TileComponentSecurity getSecurity() { return securityComponent; } + + @Override + public BaseTier getTier() { + return tier.getBaseTier(); + } } diff --git a/src/main/resources/assets/mekanism/models/block/fluid_tank.json b/src/main/resources/assets/mekanism/models/block/fluid_tank.json index 7d0a35d04..16ff68b33 100644 --- a/src/main/resources/assets/mekanism/models/block/fluid_tank.json +++ b/src/main/resources/assets/mekanism/models/block/fluid_tank.json @@ -1,4 +1,7 @@ { + "textures": { + "particle": "#glass" + }, "elements": [ { "name": "RightGlass", From 3316832070527bc111467252b1259e55990be6b0 Mon Sep 17 00:00:00 2001 From: Richard Freimer Date: Sat, 20 Apr 2019 10:52:21 -0400 Subject: [PATCH 8/8] bump version --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index a2cacf2fc..c3e9353cf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ mappings_version=stable_39 forge_version=14.23.5.2825 mcmp_version=2.5.3 jei_version=4.15.0.269 -mod_version=9.7.1 +mod_version=9.7.2 tesla_version=1.0.63 invtweak_version=1.64+dev.146 opencomputers_version=1.7.4.153 @@ -15,4 +15,4 @@ ic2_version=2.8.111-ex112 crafttweaker_version=4.1.15.527 computercraft_version=1.80pr1 top_version=1.12-1.4.23-16 -ae2_version=rv6-stable-6 \ No newline at end of file +ae2_version=rv6-stable-6