mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-16 18:33:52 +01:00
Restrict schematicannon configuration
This commit is contained in:
parent
e1d1b062f8
commit
7c8bd28421
1 changed files with 8 additions and 27 deletions
|
@ -2,15 +2,13 @@ package com.simibubi.create.content.schematics.packet;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
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;
|
||||||
import com.simibubi.create.content.schematics.block.SchematicannonTileEntity.State;
|
import com.simibubi.create.content.schematics.block.SchematicannonTileEntity.State;
|
||||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||||
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.network.PacketBuffer;
|
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;
|
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
||||||
|
|
||||||
public class ConfigureSchematicannonPacket extends SimplePacketBase {
|
public class ConfigureSchematicannonPacket extends SimplePacketBase {
|
||||||
|
@ -21,45 +19,28 @@ public class ConfigureSchematicannonPacket extends SimplePacketBase {
|
||||||
|
|
||||||
private Option option;
|
private Option option;
|
||||||
private boolean set;
|
private boolean set;
|
||||||
private BlockPos pos;
|
|
||||||
|
|
||||||
public static ConfigureSchematicannonPacket setOption(BlockPos pos, Option option, boolean set) {
|
public ConfigureSchematicannonPacket(Option option, boolean set) {
|
||||||
ConfigureSchematicannonPacket packet = new ConfigureSchematicannonPacket(pos);
|
this.option = option;
|
||||||
packet.option = option;
|
this.set = set;
|
||||||
packet.set = set;
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigureSchematicannonPacket(BlockPos pos) {
|
|
||||||
this.pos = pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigureSchematicannonPacket(PacketBuffer buffer) {
|
public ConfigureSchematicannonPacket(PacketBuffer buffer) {
|
||||||
pos = buffer.readBlockPos();
|
this(buffer.readEnumValue(Option.class), buffer.readBoolean());
|
||||||
option = Option.values()[buffer.readInt()];
|
|
||||||
set = buffer.readBoolean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(PacketBuffer buffer) {
|
public void write(PacketBuffer buffer) {
|
||||||
buffer.writeBlockPos(pos);
|
buffer.writeEnumValue(option);
|
||||||
buffer.writeInt(option.ordinal());
|
|
||||||
buffer.writeBoolean(set);
|
buffer.writeBoolean(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handle(Supplier<Context> context) {
|
public void handle(Supplier<Context> context) {
|
||||||
context.get().enqueueWork(() -> {
|
context.get().enqueueWork(() -> {
|
||||||
ServerPlayerEntity player = context.get().getSender();
|
ServerPlayerEntity player = context.get().getSender();
|
||||||
if (player == null)
|
if (player == null || !(player.openContainer instanceof SchematicannonContainer))
|
||||||
return;
|
|
||||||
World world = player.world;
|
|
||||||
if (world == null || !world.isBlockPresent(pos))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
SchematicannonTileEntity te = ((SchematicannonContainer) player.openContainer).getTileEntity();
|
||||||
if (!(tileEntity instanceof SchematicannonTileEntity))
|
|
||||||
return;
|
|
||||||
|
|
||||||
SchematicannonTileEntity te = (SchematicannonTileEntity) tileEntity;
|
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case DONT_REPLACE:
|
case DONT_REPLACE:
|
||||||
case REPLACE_ANY:
|
case REPLACE_ANY:
|
||||||
|
|
Loading…
Reference in a new issue