StorageUnitBlock: Implement locking mechanism (#2124). Thanks to Sturmlilie

This commit is contained in:
drcrazy 2020-06-09 16:30:40 +03:00 committed by GitHub
parent f5cd992686
commit c3d405e4f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 4 deletions

View file

@ -43,6 +43,7 @@ import techreborn.blockentity.machine.tier1.AutoCraftingTableBlockEntity;
import techreborn.blockentity.machine.tier1.RollingMachineBlockEntity;
import techreborn.blockentity.machine.tier3.ChunkLoaderBlockEntity;
import techreborn.blockentity.storage.energy.AdjustableSUBlockEntity;
import techreborn.blockentity.storage.item.StorageUnitBaseBlockEntity;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
@ -53,6 +54,7 @@ public class ServerboundPackets {
public static final Identifier AESU = new Identifier(TechReborn.MOD_ID, "aesu");
public static final Identifier AUTO_CRAFTING_LOCK = new Identifier(TechReborn.MOD_ID, "auto_crafting_lock");
public static final Identifier ROLLING_MACHINE_LOCK = new Identifier(TechReborn.MOD_ID, "rolling_machine_lock");
public static final Identifier STORAGE_UNIT_LOCK = new Identifier(TechReborn.MOD_ID, "storage_unit_lock");
public static final Identifier FUSION_CONTROL_SIZE = new Identifier(TechReborn.MOD_ID, "fusion_control_size");
public static final Identifier REFUND = new Identifier(TechReborn.MOD_ID, "refund");
public static final Identifier CHUNKLOADER = new Identifier(TechReborn.MOD_ID, "chunkloader");
@ -109,6 +111,18 @@ public class ServerboundPackets {
});
});
registerPacketHandler(STORAGE_UNIT_LOCK, (extendedPacketBuffer, context) -> {
BlockPos machinePos = extendedPacketBuffer.readBlockPos();
boolean locked = extendedPacketBuffer.readBoolean();
context.getTaskQueue().execute(() -> {
BlockEntity BlockEntity = context.getPlayer().world.getBlockEntity(machinePos);
if (BlockEntity instanceof StorageUnitBaseBlockEntity) {
((StorageUnitBaseBlockEntity) BlockEntity).setLocked(locked);
}
});
});
registerPacketHandler(REFUND, (extendedPacketBuffer, context) -> {
if(!TechRebornConfig.allowManualRefund){
return;
@ -188,6 +202,13 @@ public class ServerboundPackets {
});
}
public static Packet<ServerPlayPacketListener> createPacketStorageUnitLock(StorageUnitBaseBlockEntity machine, boolean locked) {
return NetworkManager.createServerBoundPacket(STORAGE_UNIT_LOCK, extendedPacketBuffer -> {
extendedPacketBuffer.writeBlockPos(machine.getPos());
extendedPacketBuffer.writeBoolean(locked);
});
}
public static Packet<ServerPlayPacketListener> createRefundPacket(){
return NetworkManager.createServerBoundPacket(REFUND, extendedPacketBuffer -> {