mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-24 09:04:49 +00:00
Initial update to 1.14
So very little works, but it compiles and runs. Things to resolve over the next few days: - Horrible mappings (should largely be resolved by tomorrow). - Cannot send extra data over containers - we'll have to see what Forge does here. - Turtle models are broken - No block drops yet - this will largely be cherry-picking whatever I did on Fabric. - Weird inventory desyncs (items don't show up initially when interacting with a CC inventory). - Probably lots of other things.
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import dan200.computercraft.shared.network.container.*;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
||||
public final class Containers
|
||||
{
|
||||
private Containers()
|
||||
{
|
||||
}
|
||||
|
||||
public static void openDiskDriveGUI( EntityPlayer player, TileDiskDrive drive )
|
||||
{
|
||||
TileEntityContainerType.diskDrive( drive.getPos() ).open( player );
|
||||
}
|
||||
|
||||
public static void openComputerGUI( EntityPlayer player, TileComputer computer )
|
||||
{
|
||||
TileEntityContainerType.computer( computer.getPos() ).open( player );
|
||||
}
|
||||
|
||||
public static void openPrinterGUI( EntityPlayer player, TilePrinter printer )
|
||||
{
|
||||
TileEntityContainerType.printer( printer.getPos() ).open( player );
|
||||
}
|
||||
|
||||
public static void openTurtleGUI( EntityPlayer player, TileTurtle turtle )
|
||||
{
|
||||
TileEntityContainerType.turtle( turtle.getPos() ).open( player );
|
||||
}
|
||||
|
||||
public static void openPrintoutGUI( EntityPlayer player, EnumHand hand )
|
||||
{
|
||||
ItemStack stack = player.getHeldItem( hand );
|
||||
Item item = stack.getItem();
|
||||
if( !(item instanceof ItemPrintout) ) return;
|
||||
|
||||
new PrintoutContainerType( hand ).open( player );
|
||||
}
|
||||
|
||||
public static void openPocketComputerGUI( EntityPlayer player, EnumHand hand )
|
||||
{
|
||||
ItemStack stack = player.getHeldItem( hand );
|
||||
Item item = stack.getItem();
|
||||
if( !(item instanceof ItemPocketComputer) ) return;
|
||||
|
||||
new PocketComputerContainerType( hand ).open( player );
|
||||
}
|
||||
|
||||
public static void openComputerGUI( EntityPlayer player, ServerComputer computer )
|
||||
{
|
||||
new ViewComputerContainerType( computer ).open( player );
|
||||
}
|
||||
|
||||
public static void setup()
|
||||
{
|
||||
ContainerType.register( TileEntityContainerType::computer, ( packet, player ) ->
|
||||
new ContainerComputer( (TileComputer) packet.getTileEntity( player ) ) );
|
||||
ContainerType.register( TileEntityContainerType::turtle, ( packet, player ) -> {
|
||||
TileTurtle turtle = (TileTurtle) packet.getTileEntity( player );
|
||||
return new ContainerTurtle( player.inventory, turtle.getAccess(), turtle.getServerComputer() );
|
||||
} );
|
||||
ContainerType.register( TileEntityContainerType::diskDrive, ( packet, player ) ->
|
||||
new ContainerDiskDrive( player.inventory, (TileDiskDrive) packet.getTileEntity( player ) ) );
|
||||
ContainerType.register( TileEntityContainerType::printer, ( packet, player ) ->
|
||||
new ContainerPrinter( player.inventory, (TilePrinter) packet.getTileEntity( player ) ) );
|
||||
|
||||
ContainerType.register( PocketComputerContainerType::new, ( packet, player ) -> new ContainerPocketComputer( player, packet.hand ) );
|
||||
ContainerType.register( PrintoutContainerType::new, ( packet, player ) -> new ContainerHeldItem( player, packet.hand ) );
|
||||
ContainerType.register( ViewComputerContainerType::new, ( packet, player ) -> new ContainerViewComputer( ComputerCraft.serverComputerRegistry.get( packet.instanceId ) ) );
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@ package dan200.computercraft.shared.network;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.network.client.*;
|
||||
import dan200.computercraft.shared.network.server.*;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
@@ -55,14 +55,14 @@ public final class NetworkHandler
|
||||
registerMainThread( 14, PlayRecordClientMessage.class, PlayRecordClientMessage::new );
|
||||
}
|
||||
|
||||
public static void sendToPlayer( EntityPlayer player, NetworkMessage packet )
|
||||
public static void sendToPlayer( PlayerEntity player, NetworkMessage packet )
|
||||
{
|
||||
network.sendTo( packet, ((EntityPlayerMP) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT );
|
||||
network.sendTo( packet, ((ServerPlayerEntity) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT );
|
||||
}
|
||||
|
||||
public static void sendToAllPlayers( NetworkMessage packet )
|
||||
{
|
||||
for( EntityPlayerMP player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() )
|
||||
for( ServerPlayerEntity player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() )
|
||||
{
|
||||
sendToPlayer( player, packet );
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public final class NetworkHandler
|
||||
|
||||
public static void sendToAllAround( NetworkMessage packet, World world, Vec3d pos, double range )
|
||||
{
|
||||
for( EntityPlayerMP player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() )
|
||||
for( ServerPlayerEntity player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() )
|
||||
{
|
||||
if( player.getEntityWorld() != world ) continue;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ package dan200.computercraft.shared.network.client;
|
||||
|
||||
import dan200.computercraft.shared.computer.core.ComputerState;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
@@ -20,7 +20,7 @@ import javax.annotation.Nonnull;
|
||||
public class ComputerDataClientMessage extends ComputerClientMessage
|
||||
{
|
||||
private ComputerState state;
|
||||
private NBTTagCompound userData;
|
||||
private CompoundNBT userData;
|
||||
|
||||
public ComputerDataClientMessage( ServerComputer computer )
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
package dan200.computercraft.shared.network.client;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
@@ -14,9 +14,9 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class ComputerTerminalClientMessage extends ComputerClientMessage
|
||||
{
|
||||
private NBTTagCompound tag;
|
||||
private CompoundNBT tag;
|
||||
|
||||
public ComputerTerminalClientMessage( int instanceId, NBTTagCompound tag )
|
||||
public ComputerTerminalClientMessage( int instanceId, CompoundNBT tag )
|
||||
{
|
||||
super( instanceId );
|
||||
this.tag = tag;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class PlayRecordClientMessage implements NetworkMessage
|
||||
public void handle( NetworkEvent.Context context )
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
mc.world.playRecord( pos, soundEvent );
|
||||
if( name != null ) mc.ingameGUI.setRecordPlayingMessage( name );
|
||||
mc.worldRenderer.playRecord( soundEvent, pos );
|
||||
if( name != null ) mc.field_71456_v.setRecordPlayingMessage( name );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network.container;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A horrible hack to allow opening GUIs until Forge adds a built-in system.
|
||||
*/
|
||||
public interface ContainerData<T extends Container> extends INamedContainerProvider
|
||||
{
|
||||
void toBytes( PacketBuffer buf );
|
||||
|
||||
default void open( PlayerEntity player )
|
||||
{
|
||||
NetworkHooks.openGui( (ServerPlayerEntity) player, this, this::toBytes );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
T createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player );
|
||||
|
||||
static <C extends Container, T extends ContainerData<C>> net.minecraft.inventory.container.ContainerType<C> create( Function<PacketBuffer, T> reader )
|
||||
{
|
||||
return new net.minecraft.inventory.container.ContainerType<>(
|
||||
( id, player ) -> reader.apply( null ).createMenu( id, player, player.player )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network.container;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.world.IInteractionObject;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A horrible hack to allow opening GUIs until Forge adds a built-in system.
|
||||
*/
|
||||
public interface ContainerType<T extends Container> extends IInteractionObject
|
||||
{
|
||||
@Nonnull
|
||||
ResourceLocation getId();
|
||||
|
||||
void toBytes( PacketBuffer buf );
|
||||
|
||||
void fromBytes( PacketBuffer buf );
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@SuppressWarnings( "unchecked" )
|
||||
default T createContainer( @Nonnull InventoryPlayer inventoryPlayer, @Nonnull EntityPlayer entityPlayer )
|
||||
{
|
||||
return ((BiFunction<ContainerType<T>, EntityPlayer, T>) containerFactories.get( getId() )).apply( this, entityPlayer );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
default String getGuiID()
|
||||
{
|
||||
return getId().toString();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
default ITextComponent getName()
|
||||
{
|
||||
return new TextComponentString( "" );
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
default ITextComponent getCustomName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
default void open( EntityPlayer player )
|
||||
{
|
||||
NetworkHooks.openGui( (EntityPlayerMP) player, this, this::toBytes );
|
||||
}
|
||||
|
||||
static <C extends Container, T extends ContainerType<C>> void register( Supplier<T> containerType, BiFunction<T, EntityPlayer, C> factory )
|
||||
{
|
||||
factories.put( containerType.get().getId(), containerType );
|
||||
containerFactories.put( containerType.get().getId(), factory );
|
||||
}
|
||||
|
||||
static <C extends Container, T extends ContainerType<C>> void registerGui( Supplier<T> containerType, BiFunction<T, EntityPlayer, GuiContainer> factory )
|
||||
{
|
||||
guiFactories.put( containerType.get().getId(), factory );
|
||||
}
|
||||
|
||||
static <C extends Container, T extends ContainerType<C>> void registerGui( Supplier<T> containerType, Function<C, GuiContainer> factory )
|
||||
{
|
||||
registerGui( containerType, ( type, player ) -> {
|
||||
@SuppressWarnings( "unchecked" )
|
||||
C container = ((BiFunction<T, EntityPlayer, C>) containerFactories.get( type.getId() )).apply( type, player );
|
||||
return container == null ? null : factory.apply( container );
|
||||
} );
|
||||
}
|
||||
|
||||
Map<ResourceLocation, Supplier<? extends ContainerType<?>>> factories = new HashMap<>();
|
||||
Map<ResourceLocation, BiFunction<? extends ContainerType<?>, EntityPlayer, GuiContainer>> guiFactories = new HashMap<>();
|
||||
Map<ResourceLocation, BiFunction<? extends ContainerType<?>, EntityPlayer, ? extends Container>> containerFactories = new HashMap<>();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network.container;
|
||||
|
||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Opens a pocket computer GUI based on the held item
|
||||
*
|
||||
* @see dan200.computercraft.shared.pocket.items.ItemPocketComputer
|
||||
*/
|
||||
public class PocketComputerContainerData implements ContainerData<ContainerPocketComputer>
|
||||
{
|
||||
private final Hand hand;
|
||||
|
||||
public PocketComputerContainerData( Hand hand )
|
||||
{
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public PocketComputerContainerData( PacketBuffer buffer )
|
||||
{
|
||||
hand = buffer.readEnumValue( Hand.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
buf.writeEnumValue( hand );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return new TranslationTextComponent( "gui.computercraft.pocket" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ContainerPocketComputer createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
|
||||
{
|
||||
return new ContainerPocketComputer( id, player, hand );
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network.container;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Opens a pocket computer GUI based on the held item
|
||||
*
|
||||
* @see dan200.computercraft.shared.pocket.items.ItemPocketComputer
|
||||
*/
|
||||
public class PocketComputerContainerType implements ContainerType<ContainerPocketComputer>
|
||||
{
|
||||
public static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "pocket_computer_gui" );
|
||||
|
||||
public EnumHand hand;
|
||||
|
||||
public PocketComputerContainerType( EnumHand hand )
|
||||
{
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public PocketComputerContainerType()
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
buf.writeEnumValue( hand );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
hand = buf.readEnumValue( EnumHand.class );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network.container;
|
||||
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Opens a printout GUI based on the currently held item
|
||||
*
|
||||
* @see dan200.computercraft.shared.media.items.ItemPrintout
|
||||
*/
|
||||
public class PrintoutContainerData implements ContainerData<ContainerHeldItem>
|
||||
{
|
||||
private final Hand hand;
|
||||
|
||||
public PrintoutContainerData( Hand hand )
|
||||
{
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public PrintoutContainerData( PacketBuffer buffer )
|
||||
{
|
||||
hand = buffer.readEnumValue( Hand.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( PacketBuffer buf )
|
||||
{
|
||||
buf.writeEnumValue( hand );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return new TranslationTextComponent( "gui.computercraft.printout" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ContainerHeldItem createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
|
||||
{
|
||||
return new ContainerHeldItem( ContainerHeldItem.PRINTOUT_TYPE, id, player, hand );
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network.container;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Opens a printout GUI based on the currently held item
|
||||
*
|
||||
* @see dan200.computercraft.shared.media.items.ItemPrintout
|
||||
*/
|
||||
public class PrintoutContainerType implements ContainerType<ContainerHeldItem>
|
||||
{
|
||||
public static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "printout_gui" );
|
||||
|
||||
public EnumHand hand;
|
||||
|
||||
public PrintoutContainerType( EnumHand hand )
|
||||
{
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public PrintoutContainerType()
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
buf.writeEnumValue( hand );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
hand = buf.readEnumValue( EnumHand.class );
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network.container;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Opens a GUI on a specific ComputerCraft TileEntity
|
||||
*
|
||||
* @see dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive
|
||||
* @see dan200.computercraft.shared.peripheral.printer.TilePrinter
|
||||
* @see dan200.computercraft.shared.computer.blocks.TileComputer
|
||||
*/
|
||||
public final class TileEntityContainerType<T extends Container> implements ContainerType<T>
|
||||
{
|
||||
private static final ResourceLocation DISK_DRIVE = new ResourceLocation( ComputerCraft.MOD_ID, "disk_drive" );
|
||||
private static final ResourceLocation PRINTER = new ResourceLocation( ComputerCraft.MOD_ID, "printer" );
|
||||
private static final ResourceLocation COMPUTER = new ResourceLocation( ComputerCraft.MOD_ID, "computer" );
|
||||
private static final ResourceLocation TURTLE = new ResourceLocation( ComputerCraft.MOD_ID, "turtle" );
|
||||
|
||||
public BlockPos pos;
|
||||
private final ResourceLocation id;
|
||||
|
||||
private TileEntityContainerType( ResourceLocation id, BlockPos pos )
|
||||
{
|
||||
this.id = id;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
private TileEntityContainerType( ResourceLocation id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( PacketBuffer buf )
|
||||
{
|
||||
buf.writeBlockPos( pos );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes( PacketBuffer buf )
|
||||
{
|
||||
pos = buf.readBlockPos();
|
||||
}
|
||||
|
||||
public TileEntity getTileEntity( EntityPlayer entity )
|
||||
{
|
||||
return entity.world.getTileEntity( pos );
|
||||
}
|
||||
|
||||
public static TileEntityContainerType<ContainerDiskDrive> diskDrive()
|
||||
{
|
||||
return new TileEntityContainerType<>( DISK_DRIVE );
|
||||
}
|
||||
|
||||
public static TileEntityContainerType<ContainerDiskDrive> diskDrive( BlockPos pos )
|
||||
{
|
||||
return new TileEntityContainerType<>( DISK_DRIVE, pos );
|
||||
}
|
||||
|
||||
public static TileEntityContainerType<ContainerPrinter> printer()
|
||||
{
|
||||
return new TileEntityContainerType<>( PRINTER );
|
||||
}
|
||||
|
||||
public static TileEntityContainerType<ContainerPrinter> printer( BlockPos pos )
|
||||
{
|
||||
return new TileEntityContainerType<>( PRINTER, pos );
|
||||
}
|
||||
|
||||
public static TileEntityContainerType<ContainerComputer> computer()
|
||||
{
|
||||
return new TileEntityContainerType<>( COMPUTER );
|
||||
}
|
||||
|
||||
public static TileEntityContainerType<ContainerComputer> computer( BlockPos pos )
|
||||
{
|
||||
return new TileEntityContainerType<>( COMPUTER, pos );
|
||||
}
|
||||
|
||||
public static TileEntityContainerType<ContainerTurtle> turtle()
|
||||
{
|
||||
return new TileEntityContainerType<>( TURTLE );
|
||||
}
|
||||
|
||||
public static TileEntityContainerType<ContainerTurtle> turtle( BlockPos pos )
|
||||
{
|
||||
return new TileEntityContainerType<>( TURTLE, pos );
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,15 @@ package dan200.computercraft.shared.network.container;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -21,16 +26,16 @@ import javax.annotation.Nonnull;
|
||||
*
|
||||
* @see dan200.computercraft.shared.command.CommandComputerCraft
|
||||
*/
|
||||
public class ViewComputerContainerType implements ContainerType<ContainerViewComputer>
|
||||
public class ViewComputerContainerData implements ContainerData<ContainerViewComputer>
|
||||
{
|
||||
public static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "view_computer_gui" );
|
||||
|
||||
public int instanceId;
|
||||
public int width;
|
||||
public int height;
|
||||
public ComputerFamily family;
|
||||
private final int instanceId;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final ComputerFamily family;
|
||||
|
||||
public ViewComputerContainerType( ServerComputer computer )
|
||||
public ViewComputerContainerData( ServerComputer computer )
|
||||
{
|
||||
instanceId = computer.getInstanceID();
|
||||
Terminal terminal = computer.getTerminal();
|
||||
@@ -39,18 +44,19 @@ public class ViewComputerContainerType implements ContainerType<ContainerViewCom
|
||||
width = terminal.getWidth();
|
||||
height = terminal.getHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
width = height = 0;
|
||||
}
|
||||
family = computer.getFamily();
|
||||
}
|
||||
|
||||
public ViewComputerContainerType()
|
||||
public ViewComputerContainerData( PacketBuffer buffer )
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId()
|
||||
{
|
||||
return ID;
|
||||
instanceId = buffer.readVarInt();
|
||||
width = buffer.readVarInt();
|
||||
height = buffer.readVarInt();
|
||||
family = buffer.readEnumValue( ComputerFamily.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,12 +68,18 @@ public class ViewComputerContainerType implements ContainerType<ContainerViewCom
|
||||
buf.writeEnumValue( family );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void fromBytes( @Nonnull PacketBuffer buf )
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
instanceId = buf.readVarInt();
|
||||
width = buf.readVarInt();
|
||||
height = buf.readVarInt();
|
||||
family = buf.readEnumValue( ComputerFamily.class );
|
||||
return new TranslationTextComponent( "gui.computercraft.view_computer" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ContainerViewComputer createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
|
||||
{
|
||||
IComputer computer = (player.world.isRemote ? ComputerCraft.clientComputerRegistry : ComputerCraft.serverComputerRegistry).get( id );
|
||||
return new ContainerViewComputer( id, computer );
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ package dan200.computercraft.shared.network.server;
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.util.NBTUtil;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -51,7 +51,7 @@ public class QueueEventServerMessage extends ComputerServerMessage
|
||||
super.fromBytes( buf );
|
||||
event = buf.readString( Short.MAX_VALUE );
|
||||
|
||||
NBTTagCompound args = buf.readCompoundTag();
|
||||
CompoundNBT args = buf.readCompoundTag();
|
||||
this.args = args == null ? null : NBTUtil.decodeObjects( args );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user