From 7c8bd28421040a783e2637df083a86c63bc326cd Mon Sep 17 00:00:00 2001 From: Paul Fulham Date: Sat, 21 Nov 2020 18:28:05 -0800 Subject: [PATCH] Restrict schematicannon configuration --- .../packet/ConfigureSchematicannonPacket.java | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/schematics/packet/ConfigureSchematicannonPacket.java b/src/main/java/com/simibubi/create/content/schematics/packet/ConfigureSchematicannonPacket.java index 4a5984e77..2e66fc255 100644 --- a/src/main/java/com/simibubi/create/content/schematics/packet/ConfigureSchematicannonPacket.java +++ b/src/main/java/com/simibubi/create/content/schematics/packet/ConfigureSchematicannonPacket.java @@ -2,15 +2,13 @@ package com.simibubi.create.content.schematics.packet; import java.util.function.Supplier; +import com.simibubi.create.content.schematics.block.SchematicannonContainer; import com.simibubi.create.content.schematics.block.SchematicannonTileEntity; import com.simibubi.create.content.schematics.block.SchematicannonTileEntity.State; import com.simibubi.create.foundation.networking.SimplePacketBase; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkEvent.Context; public class ConfigureSchematicannonPacket extends SimplePacketBase { @@ -21,45 +19,28 @@ public class ConfigureSchematicannonPacket extends SimplePacketBase { private Option option; private boolean set; - private BlockPos pos; - public static ConfigureSchematicannonPacket setOption(BlockPos pos, Option option, boolean set) { - ConfigureSchematicannonPacket packet = new ConfigureSchematicannonPacket(pos); - packet.option = option; - packet.set = set; - return packet; - } - - public ConfigureSchematicannonPacket(BlockPos pos) { - this.pos = pos; + public ConfigureSchematicannonPacket(Option option, boolean set) { + this.option = option; + this.set = set; } public ConfigureSchematicannonPacket(PacketBuffer buffer) { - pos = buffer.readBlockPos(); - option = Option.values()[buffer.readInt()]; - set = buffer.readBoolean(); + this(buffer.readEnumValue(Option.class), buffer.readBoolean()); } public void write(PacketBuffer buffer) { - buffer.writeBlockPos(pos); - buffer.writeInt(option.ordinal()); + buffer.writeEnumValue(option); buffer.writeBoolean(set); } public void handle(Supplier context) { context.get().enqueueWork(() -> { ServerPlayerEntity player = context.get().getSender(); - if (player == null) - return; - World world = player.world; - if (world == null || !world.isBlockPresent(pos)) + if (player == null || !(player.openContainer instanceof SchematicannonContainer)) return; - TileEntity tileEntity = world.getTileEntity(pos); - if (!(tileEntity instanceof SchematicannonTileEntity)) - return; - - SchematicannonTileEntity te = (SchematicannonTileEntity) tileEntity; + SchematicannonTileEntity te = ((SchematicannonContainer) player.openContainer).getTileEntity(); switch (option) { case DONT_REPLACE: case REPLACE_ANY: