Make some devices properly tell their container they changed.

Item devices for computer/robot, so not strictly necessary, but for clarity.
This commit is contained in:
Florian Nücke
2022-02-05 14:16:10 +01:00
parent 2b3858bd14
commit 5ecafeba16
4 changed files with 17 additions and 12 deletions

View File

@@ -2,17 +2,20 @@
package li.cil.oc2.common.bus.device.item;
import li.cil.oc2.api.bus.device.DeviceContainer;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.object.ObjectDevice;
import li.cil.oc2.api.bus.device.rpc.RPCDevice;
import li.cil.oc2.api.bus.device.rpc.RPCMethodGroup;
import li.cil.oc2.common.bus.device.util.IdentityProxy;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public abstract class AbstractItemRPCDevice extends IdentityProxy<ItemStack> implements RPCDevice, ItemDevice {
private final ObjectDevice device;
private DeviceContainer container;
///////////////////////////////////////////////////////////////////
@@ -23,6 +26,11 @@ public abstract class AbstractItemRPCDevice extends IdentityProxy<ItemStack> imp
///////////////////////////////////////////////////////////////////
@Override
public void setDeviceContainer(@Nullable final DeviceContainer container) {
this.container = container;
}
@Override
public List<String> getTypeNames() {
return device.getTypeNames();
@@ -33,18 +41,11 @@ public abstract class AbstractItemRPCDevice extends IdentityProxy<ItemStack> imp
return device.getMethodGroups();
}
@Override
public void mount() {
device.mount();
}
///////////////////////////////////////////////////////////////////
@Override
public void unmount() {
device.unmount();
}
@Override
public void dispose() {
device.dispose();
protected void setChanged() {
if (container != null) {
container.setChanged();
}
}
}

View File

@@ -213,6 +213,7 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
private void beginCooldown() {
lastOperation = entity.level.getGameTime();
setChanged();
}
private boolean isOnCooldown() {

View File

@@ -120,6 +120,7 @@ public final class RedstoneInterfaceCardItemDevice extends AbstractItemRPCDevice
}
output[index] = clampedValue;
setChanged();
final Direction direction = HorizontalBlockUtils.toGlobal(blockEntity.getBlockState(), side);
if (direction != null) {

View File

@@ -53,7 +53,9 @@ public final class SoundCardItemDevice extends AbstractItemRPCDevice {
if (gameTime < gameTimeCooldownExpiresAt) {
return;
}
gameTimeCooldownExpiresAt = gameTime + COOLDOWN_IN_TICKS;
setChanged();
final SoundEvent soundEvent = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(name));
if (soundEvent == null) throw new IllegalArgumentException("Sound not found.");