mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
As we disable capabilities when a side config has them disabled we need to notify the neighbor of an update when a side's config changes. (#5426)
This commit is contained in:
1 parent
14bd97e435
commit
03cc33f501
2 files changed
+31
-21
No files matched your search
@@ -3,15 +3,16 @@ package mekanism.common.network;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.Range4D;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.base.ISideConfiguration;
|
||||
import mekanism.common.base.ITileNetwork;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.network.PacketConfigurationUpdate.ConfigurationUpdateMessage;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.tile.component.TileComponentEjector;
|
||||
import mekanism.common.tile.prefab.TileEntityBasicBlock;
|
||||
import mekanism.common.util.CapabilityUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
@@ -30,12 +31,10 @@ public class PacketConfigurationUpdate implements IMessageHandler<ConfigurationU
|
||||
public IMessage onMessage(ConfigurationUpdateMessage message, MessageContext context) {
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
|
||||
PacketHandler.handlePacket(() ->
|
||||
{
|
||||
PacketHandler.handlePacket(() -> {
|
||||
TileEntity tile = message.coord4D.getTileEntity(player.world);
|
||||
ITileNetwork network = CapabilityUtils.getCapability(tile, Capabilities.TILE_NETWORK_CAPABILITY, null);
|
||||
|
||||
if (tile instanceof ISideConfiguration) {
|
||||
ITileNetwork network = CapabilityUtils.getCapability(tile, Capabilities.TILE_NETWORK_CAPABILITY, null);
|
||||
ISideConfiguration config = (ISideConfiguration) tile;
|
||||
|
||||
if (message.packetType == ConfigurationPacket.EJECT) {
|
||||
@@ -43,41 +42,38 @@ public class PacketConfigurationUpdate implements IMessageHandler<ConfigurationU
|
||||
.setEjecting(message.transmission, !config.getConfig().isEjecting(message.transmission));
|
||||
} else if (message.packetType == ConfigurationPacket.SIDE_DATA) {
|
||||
if (message.clickType == 0) {
|
||||
MekanismUtils
|
||||
.incrementOutput((ISideConfiguration) tile, message.transmission, message.configIndex);
|
||||
MekanismUtils.incrementOutput(config, message.transmission, message.configIndex);
|
||||
} else if (message.clickType == 1) {
|
||||
MekanismUtils
|
||||
.decrementOutput((ISideConfiguration) tile, message.transmission, message.configIndex);
|
||||
MekanismUtils.decrementOutput(config, message.transmission, message.configIndex);
|
||||
} else if (message.clickType == 2) {
|
||||
((ISideConfiguration) tile).getConfig().getConfig(message.transmission)
|
||||
.set(message.configIndex, (byte) 0);
|
||||
config.getConfig().getConfig(message.transmission).set(message.configIndex, (byte) 0);
|
||||
}
|
||||
|
||||
tile.markDirty();
|
||||
Mekanism.packetHandler.sendToReceivers(
|
||||
new TileEntityMessage(message.coord4D, network.getNetworkedData(new TileNetworkList())),
|
||||
new Range4D(message.coord4D));
|
||||
//Notify the neighbor on that side our state changed
|
||||
MekanismUtils.notifyNeighborOfChange(tile.getWorld(), message.configIndex, tile.getPos());
|
||||
} else if (message.packetType == ConfigurationPacket.EJECT_COLOR) {
|
||||
TileComponentEjector ejector = config.getEjector();
|
||||
if (message.clickType == 0) {
|
||||
config.getEjector()
|
||||
.setOutputColor(TransporterUtils.increment(config.getEjector().getOutputColor()));
|
||||
ejector.setOutputColor(TransporterUtils.increment(ejector.getOutputColor()));
|
||||
} else if (message.clickType == 1) {
|
||||
config.getEjector()
|
||||
.setOutputColor(TransporterUtils.decrement(config.getEjector().getOutputColor()));
|
||||
ejector.setOutputColor(TransporterUtils.decrement(ejector.getOutputColor()));
|
||||
} else if (message.clickType == 2) {
|
||||
config.getEjector().setOutputColor(null);
|
||||
ejector.setOutputColor(null);
|
||||
}
|
||||
} else if (message.packetType == ConfigurationPacket.INPUT_COLOR) {
|
||||
EnumFacing side = EnumFacing.byIndex(message.inputSide);
|
||||
|
||||
TileComponentEjector ejector = config.getEjector();
|
||||
if (message.clickType == 0) {
|
||||
config.getEjector()
|
||||
.setInputColor(side, TransporterUtils.increment(config.getEjector().getInputColor(side)));
|
||||
ejector.setInputColor(side, TransporterUtils.increment(ejector.getInputColor(side)));
|
||||
} else if (message.clickType == 1) {
|
||||
config.getEjector()
|
||||
.setInputColor(side, TransporterUtils.decrement(config.getEjector().getInputColor(side)));
|
||||
ejector.setInputColor(side, TransporterUtils.decrement(ejector.getInputColor(side)));
|
||||
} else if (message.clickType == 2) {
|
||||
config.getEjector().setInputColor(side, null);
|
||||
ejector.setInputColor(side, null);
|
||||
}
|
||||
} else if (message.packetType == ConfigurationPacket.STRICT_INPUT) {
|
||||
config.getEjector().setStrictInput(!config.getEjector().hasStrictInput());
|
||||
|
||||
@@ -479,6 +479,20 @@ public final class MekanismUtils {
|
||||
state.neighborChanged(world, coord.getPos(), world.getBlockState(fromPos).getBlock(), fromPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls BOTH neighbour changed functions because nobody can decide on which one to implement.
|
||||
*
|
||||
* @param world world the change exists in
|
||||
* @param neighborSide The side the neighbor to notify is on
|
||||
* @param fromPos pos of our block that updated
|
||||
*/
|
||||
public static void notifyNeighborOfChange(World world, EnumFacing neighborSide, BlockPos fromPos) {
|
||||
BlockPos neighbor = fromPos.offset(neighborSide);
|
||||
IBlockState state = world.getBlockState(neighbor);
|
||||
state.getBlock().onNeighborChange(world, neighbor, fromPos);
|
||||
state.neighborChanged(world, neighbor, world.getBlockState(fromPos).getBlock(), fromPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Places a fake bounding block at the defined location.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user