mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-15 02:20:05 +00:00
Finish off containers, somewhat fix block drops
- Add Forge's "name" field to the loot tables. This doesn't resolve all our missing loot providers, but it's a start. - Add back GUIs for pocket computers, printouts, view computer, etc...
This commit is contained in:
parent
d10b657a54
commit
8dd1c2a6cc
@ -12,19 +12,16 @@ import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public final class GuiComputer<T extends Container & IContainerComputer> extends ContainerScreen<T>
|
||||
public final class GuiComputer<T extends ContainerComputerBase> extends ContainerScreen<T>
|
||||
{
|
||||
public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" );
|
||||
public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" );
|
||||
@ -40,13 +37,12 @@ public final class GuiComputer<T extends Container & IContainerComputer> extends
|
||||
private WidgetWrapper terminalWrapper;
|
||||
|
||||
private GuiComputer(
|
||||
T container, PlayerInventory player, ITextComponent title,
|
||||
ComputerFamily family, ClientComputer computer, int termWidth, int termHeight
|
||||
T container, PlayerInventory player, ITextComponent title, int termWidth, int termHeight
|
||||
)
|
||||
{
|
||||
super( container, player, title );
|
||||
m_family = family;
|
||||
m_computer = computer;
|
||||
m_family = container.getFamily();
|
||||
m_computer = (ClientComputer) container.getComputer();
|
||||
m_termWidth = termWidth;
|
||||
m_termHeight = termHeight;
|
||||
terminal = null;
|
||||
@ -56,20 +52,15 @@ public final class GuiComputer<T extends Container & IContainerComputer> extends
|
||||
{
|
||||
return new GuiComputer<>(
|
||||
container, inventory, component,
|
||||
container.getFamily(),
|
||||
(ClientComputer) container.getComputer(),
|
||||
ComputerCraft.terminalWidth_computer, ComputerCraft.terminalHeight_computer
|
||||
);
|
||||
}
|
||||
|
||||
public static GuiComputer<ContainerPocketComputer> createPocket( ContainerPocketComputer container, PlayerInventory inventory, ITextComponent component )
|
||||
{
|
||||
Item item = container.getStack().getItem();
|
||||
return new GuiComputer<>(
|
||||
container, inventory, component,
|
||||
item instanceof ItemPocketComputer ? ((ItemPocketComputer) item).getFamily() : ComputerFamily.Normal,
|
||||
(ClientComputer) container.getComputer(),
|
||||
ComputerCraft.terminalWidth_computer, ComputerCraft.terminalHeight_computer
|
||||
ComputerCraft.terminalWidth_pocketComputer, ComputerCraft.terminalHeight_pocketComputer
|
||||
);
|
||||
}
|
||||
|
||||
@ -77,8 +68,6 @@ public final class GuiComputer<T extends Container & IContainerComputer> extends
|
||||
{
|
||||
return new GuiComputer<>(
|
||||
container, inventory, component,
|
||||
container.getFamily(),
|
||||
(ClientComputer) container.getComputer(),
|
||||
container.getWidth(), container.getHeight()
|
||||
);
|
||||
}
|
||||
|
@ -20,14 +20,20 @@ import dan200.computercraft.core.tracking.TrackingField;
|
||||
import dan200.computercraft.shared.command.text.TableBuilder;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.network.container.ViewComputerContainerData;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
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.play.server.SPlayerPositionLookPacket;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.ServerWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -216,7 +222,22 @@ public final class CommandComputerCraft
|
||||
.executes( context -> {
|
||||
ServerPlayerEntity player = context.getSource().asPlayer();
|
||||
ServerComputer computer = getComputerArgument( context, "computer" );
|
||||
// TODO: new ViewComputerContainerData( computer ).open( player );
|
||||
new ViewComputerContainerData( computer ).open( player, new INamedContainerProvider()
|
||||
{
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return new TranslationTextComponent( "gui.computercraft.view_computer" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Container createMenu( int id, @Nonnull PlayerInventory player, @Nonnull PlayerEntity entity )
|
||||
{
|
||||
return new ContainerViewComputer( id, computer );
|
||||
}
|
||||
} );
|
||||
return 1;
|
||||
} ) )
|
||||
|
||||
|
@ -7,35 +7,44 @@
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.shared.network.container.ContainerData;
|
||||
import dan200.computercraft.shared.network.container.PrintoutContainerData;
|
||||
import dan200.computercraft.shared.network.container.HeldItemContainerData;
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ContainerHeldItem extends Container
|
||||
{
|
||||
public static final ContainerType<ContainerHeldItem> PRINTOUT_TYPE = ContainerData.toType( PrintoutContainerData::new, null /* TODO */ );
|
||||
public static final ContainerType<ContainerHeldItem> PRINTOUT_TYPE = ContainerData.toType( HeldItemContainerData::new, ContainerHeldItem::createPrintout );
|
||||
|
||||
private final ItemStack m_stack;
|
||||
private final Hand m_hand;
|
||||
private final ItemStack stack;
|
||||
private final Hand hand;
|
||||
|
||||
public ContainerHeldItem( ContainerType<? extends ContainerHeldItem> type, int id, PlayerEntity player, Hand hand )
|
||||
{
|
||||
super( type, id );
|
||||
|
||||
m_hand = hand;
|
||||
m_stack = InventoryUtil.copyItem( player.getHeldItem( hand ) );
|
||||
this.hand = hand;
|
||||
stack = InventoryUtil.copyItem( player.getHeldItem( hand ) );
|
||||
}
|
||||
|
||||
private static ContainerHeldItem createPrintout( int id, PlayerInventory inventory, HeldItemContainerData data )
|
||||
{
|
||||
return new ContainerHeldItem( PRINTOUT_TYPE, id, inventory.player, data.getHand() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public ItemStack getStack()
|
||||
{
|
||||
return m_stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,7 +52,35 @@ public class ContainerHeldItem extends Container
|
||||
{
|
||||
if( !player.isAlive() ) return false;
|
||||
|
||||
ItemStack stack = player.getHeldItem( m_hand );
|
||||
return stack == m_stack || !stack.isEmpty() && !m_stack.isEmpty() && stack.getItem() == m_stack.getItem();
|
||||
ItemStack stack = player.getHeldItem( hand );
|
||||
return stack == this.stack || !stack.isEmpty() && !this.stack.isEmpty() && stack.getItem() == this.stack.getItem();
|
||||
}
|
||||
|
||||
public static class Factory implements INamedContainerProvider
|
||||
{
|
||||
private final ContainerType<ContainerHeldItem> type;
|
||||
private final ITextComponent name;
|
||||
private final Hand hand;
|
||||
|
||||
public Factory( ContainerType<ContainerHeldItem> type, ItemStack stack, Hand hand )
|
||||
{
|
||||
this.type = type;
|
||||
this.name = stack.getDisplayName();
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
|
||||
{
|
||||
return new ContainerHeldItem( type, id, player, hand );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import dan200.computercraft.core.computer.ComputerSide;
|
||||
import dan200.computercraft.shared.BundledRedstone;
|
||||
import dan200.computercraft.shared.Peripherals;
|
||||
import dan200.computercraft.shared.common.TileGeneric;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ComputerState;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
@ -49,7 +48,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
{
|
||||
private static final String NBT_ID = "ComputerId";
|
||||
private static final String NBT_LABEL = "Label";
|
||||
private static final String NBT_INSTANCE = "InstanceId";
|
||||
private static final String NBT_ON = "On";
|
||||
|
||||
private int m_instanceID = -1;
|
||||
@ -173,11 +171,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
|
||||
if( computer.hasOutputChanged() ) updateOutput();
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientComputer computer = createClientComputer();
|
||||
if( computer != null && computer.hasOutputChanged() ) updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void updateBlockState( ComputerState newState );
|
||||
@ -376,23 +369,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
return getWorld().isRemote ? null : ComputerCraft.serverComputerRegistry.get( m_instanceID );
|
||||
}
|
||||
|
||||
public ClientComputer createClientComputer()
|
||||
{
|
||||
if( !getWorld().isRemote || m_instanceID < 0 ) return null;
|
||||
|
||||
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( m_instanceID );
|
||||
if( computer == null )
|
||||
{
|
||||
ComputerCraft.clientComputerRegistry.add( m_instanceID, computer = new ClientComputer( m_instanceID ) );
|
||||
}
|
||||
return computer;
|
||||
}
|
||||
|
||||
public ClientComputer getClientComputer()
|
||||
{
|
||||
return getWorld().isRemote ? ComputerCraft.clientComputerRegistry.get( m_instanceID ) : null;
|
||||
}
|
||||
|
||||
// Networking stuff
|
||||
|
||||
@Override
|
||||
@ -402,14 +378,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
|
||||
if( m_computerID >= 0 ) nbt.putInt( NBT_ID, m_computerID );
|
||||
if( m_label != null ) nbt.putString( NBT_LABEL, m_label );
|
||||
nbt.putInt( NBT_INSTANCE, createServerComputer().getInstanceID() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readDescription( @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.readDescription( nbt );
|
||||
m_instanceID = nbt.contains( NBT_INSTANCE ) ? nbt.getInt( NBT_INSTANCE ) : -1;
|
||||
m_label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
|
||||
m_computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
package dan200.computercraft.shared.computer.core;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import dan200.computercraft.shared.common.ClientTerminal;
|
||||
import dan200.computercraft.shared.network.NetworkHandler;
|
||||
import dan200.computercraft.shared.network.server.*;
|
||||
@ -18,10 +17,8 @@ public class ClientComputer extends ClientTerminal implements IComputer
|
||||
|
||||
private boolean m_on = false;
|
||||
private boolean m_blinking = false;
|
||||
private boolean m_changed = true;
|
||||
private CompoundNBT m_userData = null;
|
||||
|
||||
private boolean m_changedLastFrame = false;
|
||||
|
||||
public ClientComputer( int instanceID )
|
||||
{
|
||||
@ -29,17 +26,6 @@ public class ClientComputer extends ClientTerminal implements IComputer
|
||||
m_instanceID = instanceID;
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
m_changedLastFrame = m_changed;
|
||||
m_changed = false;
|
||||
}
|
||||
|
||||
public boolean hasOutputChanged()
|
||||
{
|
||||
return m_changedLastFrame;
|
||||
}
|
||||
|
||||
public CompoundNBT getUserData()
|
||||
{
|
||||
return m_userData;
|
||||
@ -137,14 +123,8 @@ public class ClientComputer extends ClientTerminal implements IComputer
|
||||
|
||||
public void setState( ComputerState state, CompoundNBT userData )
|
||||
{
|
||||
boolean oldOn = m_on;
|
||||
boolean oldBlinking = m_blinking;
|
||||
CompoundNBT oldUserData = m_userData;
|
||||
|
||||
m_on = state != ComputerState.OFF;
|
||||
m_blinking = state == ComputerState.BLINKING;
|
||||
m_userData = userData;
|
||||
|
||||
m_changed |= m_on != oldOn || m_blinking != oldBlinking || !Objects.equal( m_userData, oldUserData );
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,6 @@ package dan200.computercraft.shared.computer.core;
|
||||
|
||||
public class ClientComputerRegistry extends ComputerRegistry<ClientComputer>
|
||||
{
|
||||
public void update()
|
||||
{
|
||||
for( ClientComputer computer : getComputers() )
|
||||
{
|
||||
computer.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( int instanceID, ClientComputer computer )
|
||||
{
|
||||
|
@ -7,10 +7,7 @@
|
||||
package dan200.computercraft.shared.computer.inventory;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.InputState;
|
||||
import dan200.computercraft.shared.computer.core.*;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@ -38,11 +35,17 @@ public class ContainerComputerBase extends Container implements IContainerComput
|
||||
|
||||
protected ContainerComputerBase( ContainerType<? extends ContainerComputerBase> type, int id, PlayerInventory player, ComputerContainerData data )
|
||||
{
|
||||
this( type, id, x -> true,
|
||||
(player.player.world.isRemote
|
||||
? ComputerCraft.clientComputerRegistry
|
||||
: ComputerCraft.serverComputerRegistry).get( data.getInstanceId() ),
|
||||
data.getFamily() );
|
||||
this( type, id, x -> true, getComputer( player, data ), data.getFamily() );
|
||||
}
|
||||
|
||||
protected static IComputer getComputer( PlayerInventory player, ComputerContainerData data )
|
||||
{
|
||||
int id = data.getInstanceId();
|
||||
if( !player.player.world.isRemote ) return ComputerCraft.serverComputerRegistry.get( id );
|
||||
|
||||
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( id );
|
||||
if( computer == null ) ComputerCraft.clientComputerRegistry.add( id, computer = new ClientComputer( id ) );
|
||||
return computer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,6 +7,8 @@
|
||||
package dan200.computercraft.shared.media.items;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.network.container.HeldItemContainerData;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
@ -59,7 +61,11 @@ public class ItemPrintout extends Item
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick( World world, PlayerEntity player, @Nonnull Hand hand )
|
||||
{
|
||||
// TODO: if( !world.isRemote ) new PrintoutContainerData( hand ).open( player );
|
||||
if( !world.isRemote )
|
||||
{
|
||||
new HeldItemContainerData( hand )
|
||||
.open( player, new ContainerHeldItem.Factory( ContainerHeldItem.PRINTOUT_TYPE, player.getHeldItem( hand ), hand ) );
|
||||
}
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) );
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
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;
|
||||
|
||||
@ -17,18 +15,19 @@ import javax.annotation.Nonnull;
|
||||
/**
|
||||
* Opens a printout GUI based on the currently held item
|
||||
*
|
||||
* @see ContainerHeldItem
|
||||
* @see dan200.computercraft.shared.media.items.ItemPrintout
|
||||
*/
|
||||
public class PrintoutContainerData implements ContainerData
|
||||
public class HeldItemContainerData implements ContainerData
|
||||
{
|
||||
private final Hand hand;
|
||||
|
||||
public PrintoutContainerData( Hand hand )
|
||||
public HeldItemContainerData( Hand hand )
|
||||
{
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public PrintoutContainerData( PacketBuffer buffer )
|
||||
public HeldItemContainerData( PacketBuffer buffer )
|
||||
{
|
||||
hand = buffer.readEnumValue( Hand.class );
|
||||
}
|
||||
@ -40,8 +39,8 @@ public class PrintoutContainerData implements ContainerData
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public ContainerHeldItem createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
|
||||
public Hand getHand()
|
||||
{
|
||||
return new ContainerHeldItem( ContainerHeldItem.PRINTOUT_TYPE, id, player, hand );
|
||||
return hand;
|
||||
}
|
||||
}
|
@ -1,47 +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.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 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
|
||||
{
|
||||
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
|
||||
public ContainerPocketComputer createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
|
||||
{
|
||||
return new ContainerPocketComputer( id, player, hand );
|
||||
}
|
||||
}
|
@ -6,52 +6,69 @@
|
||||
|
||||
package dan200.computercraft.shared.pocket.inventory;
|
||||
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.InputState;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import dan200.computercraft.shared.network.container.ContainerData;
|
||||
import dan200.computercraft.shared.network.container.PocketComputerContainerData;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ContainerPocketComputer extends ContainerHeldItem implements IContainerComputer
|
||||
public final class ContainerPocketComputer extends ContainerComputerBase
|
||||
{
|
||||
public static final ContainerType<ContainerPocketComputer> TYPE = ContainerData.toType( PocketComputerContainerData::new, null /* TODO */ );
|
||||
public static final ContainerType<ContainerPocketComputer> TYPE = ContainerData.toType( ComputerContainerData::new, ContainerPocketComputer::new );
|
||||
|
||||
private final InputState input = new InputState( this );
|
||||
|
||||
public ContainerPocketComputer( int id, @Nonnull PlayerEntity player, Hand hand )
|
||||
private ContainerPocketComputer( int id, ServerComputer computer, ItemPocketComputer item, Hand hand )
|
||||
{
|
||||
super( TYPE, id, player, hand );
|
||||
super( TYPE, id, p -> {
|
||||
ItemStack stack = p.getHeldItem( hand );
|
||||
return stack.getItem() == item && ItemPocketComputer.getServerComputer( stack ) == computer;
|
||||
}, computer, item.getFamily() );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IComputer getComputer()
|
||||
private ContainerPocketComputer( int id, PlayerInventory player, ComputerContainerData data )
|
||||
{
|
||||
ItemStack stack = getStack();
|
||||
return !stack.isEmpty() && stack.getItem() instanceof ItemPocketComputer
|
||||
? ItemPocketComputer.getServerComputer( stack ) : null;
|
||||
super( TYPE, id, player, data );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public InputState getInput()
|
||||
public static class Factory implements INamedContainerProvider
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed( PlayerEntity player )
|
||||
{
|
||||
super.onContainerClosed( player );
|
||||
input.close();
|
||||
private final ServerComputer computer;
|
||||
private final ITextComponent name;
|
||||
private final ItemPocketComputer item;
|
||||
private final Hand hand;
|
||||
|
||||
public Factory( ServerComputer computer, ItemStack stack, ItemPocketComputer item, Hand hand )
|
||||
{
|
||||
this.computer = computer;
|
||||
this.name = stack.getDisplayName();
|
||||
this.item = item;
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity entity )
|
||||
{
|
||||
return new ContainerPocketComputer( id, computer, item, hand );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,10 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ComputerState;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.items.IComputerItem;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import dan200.computercraft.shared.pocket.apis.PocketAPI;
|
||||
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@ -153,7 +155,10 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: if( !stop ) new PocketComputerContainerData( hand ).open( player );
|
||||
if( !stop && computer != null )
|
||||
{
|
||||
new ComputerContainerData( computer ).open( player, new ContainerPocketComputer.Factory( computer, stack, this, hand ) );
|
||||
}
|
||||
}
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, stack );
|
||||
}
|
||||
@ -207,7 +212,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
return super.getCreatorModId( stack );
|
||||
}
|
||||
|
||||
private PocketServerComputer createServerComputer( final World world, IInventory inventory, Entity entity, @Nonnull ItemStack stack )
|
||||
public PocketServerComputer createServerComputer( final World world, IInventory inventory, Entity entity, @Nonnull ItemStack stack )
|
||||
{
|
||||
if( world.isRemote ) return null;
|
||||
|
||||
|
@ -103,15 +103,6 @@ public final class ComputerCraftProxyCommon
|
||||
}
|
||||
*/
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClientTick( TickEvent.ClientTickEvent event )
|
||||
{
|
||||
if( event.phase == TickEvent.Phase.START )
|
||||
{
|
||||
ComputerCraft.clientComputerRegistry.update();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerTick( TickEvent.ServerTickEvent event )
|
||||
{
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
package dan200.computercraft.shared.turtle.inventory;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
||||
@ -82,12 +81,10 @@ public class ContainerTurtle extends ContainerComputerBase
|
||||
|
||||
private ContainerTurtle( int id, PlayerInventory player, ComputerContainerData data )
|
||||
{
|
||||
this( id, x -> true,
|
||||
(player.player.world.isRemote
|
||||
? ComputerCraft.clientComputerRegistry
|
||||
: ComputerCraft.serverComputerRegistry).get( data.getInstanceId() ),
|
||||
data.getFamily(),
|
||||
player, new Inventory( TileTurtle.INVENTORY_SIZE ), new IntArray( 1 ) );
|
||||
this(
|
||||
id, x -> true, getComputer( player, data ), data.getFamily(),
|
||||
player, new Inventory( TileTurtle.INVENTORY_SIZE ), new IntArray( 1 )
|
||||
);
|
||||
}
|
||||
|
||||
public int getSelectedSlot()
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "cable",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:item", "name": "computercraft:cable" }
|
||||
@ -16,6 +17,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "wired_modem",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:item", "name": "computercraft:wired_modem" }
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:dynamic", "name": "computercraft:computer" }
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:dynamic", "name": "computercraft:computer" }
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [ { "type": "minecraft:dynamic", "name": "computercraft:computer" } ]
|
||||
}
|
||||
|
@ -2,11 +2,13 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [ { "type": "minecraft:item", "name": "computercraft:disk_drive" } ],
|
||||
"conditions": [ { "condition": "minecraft:survives_explosion" } ]
|
||||
},
|
||||
{
|
||||
"name": "contents",
|
||||
"rolls": 1,
|
||||
"entries": [ { "type": "minecraft:dynamic", "name": "computercraft:contents" } ],
|
||||
"conditions": [ { "condition": "minecraft:survives_explosion" } ]
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:item", "name": "computercraft:monitor_advanced" }
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:item", "name": "computercraft:monitor_normal" }
|
||||
|
@ -2,11 +2,13 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [ { "type": "minecraft:item", "name": "computercraft:printer" } ],
|
||||
"conditions": [ { "condition": "minecraft:survives_explosion" } ]
|
||||
},
|
||||
{
|
||||
"name": "contents",
|
||||
"rolls": 1,
|
||||
"entries": [ { "type": "minecraft:dynamic", "name": "computercraft:contents" } ],
|
||||
"conditions": [ { "condition": "minecraft:survives_explosion" } ]
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:item", "name": "computercraft:speaker" }
|
||||
|
@ -2,12 +2,14 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:dynamic", "name": "computercraft:computer" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "contents",
|
||||
"rolls": 1,
|
||||
"entries": [ { "type": "minecraft:dynamic", "name": "computercraft:contents" } ],
|
||||
"conditions": [ { "condition": "minecraft:survives_explosion" } ]
|
||||
|
@ -2,10 +2,12 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [ { "type": "minecraft:dynamic", "name": "computercraft:computer" } ]
|
||||
},
|
||||
{
|
||||
"name": "contents",
|
||||
"rolls": 1,
|
||||
"entries": [ { "type": "minecraft:dynamic", "name": "computercraft:contents" } ],
|
||||
"conditions": [ { "condition": "minecraft:survives_explosion" } ]
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:item", "name": "computercraft:wired_modem_full" }
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:item", "name": "computercraft:wireless_modem_advanced" }
|
||||
|
@ -2,6 +2,7 @@
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"name": "main",
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{ "type": "minecraft:item", "name": "computercraft:wireless_modem_normal" }
|
||||
|
Loading…
x
Reference in New Issue
Block a user