2017-05-07 00:18:59 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2021-01-06 17:13:40 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
package dan200.computercraft.shared.common;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-06-27 09:23:45 +00:00
|
|
|
import dan200.computercraft.shared.Registry;
|
2019-06-12 07:40:20 +00:00
|
|
|
import dan200.computercraft.shared.network.container.HeldItemContainerData;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2019-06-12 07:40:20 +00:00
|
|
|
import net.minecraft.entity.player.PlayerInventory;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.inventory.container.Container;
|
|
|
|
import net.minecraft.inventory.container.ContainerType;
|
2019-06-12 07:40:20 +00:00
|
|
|
import net.minecraft.inventory.container.INamedContainerProvider;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.util.Hand;
|
2019-06-12 07:40:20 +00:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2019-06-12 07:40:20 +00:00
|
|
|
import javax.annotation.Nullable;
|
2017-05-06 23:07:42 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public class ContainerHeldItem extends Container
|
|
|
|
{
|
2019-06-12 07:40:20 +00:00
|
|
|
private final ItemStack stack;
|
|
|
|
private final Hand hand;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public ContainerHeldItem( ContainerType<? extends ContainerHeldItem> type, int id, PlayerEntity player, Hand hand )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
super( type, id );
|
|
|
|
|
2019-06-12 07:40:20 +00:00
|
|
|
this.hand = hand;
|
2021-01-09 19:22:58 +00:00
|
|
|
stack = player.getItemInHand( hand ).copy();
|
2019-06-12 07:40:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-27 09:23:45 +00:00
|
|
|
public static ContainerHeldItem createPrintout( int id, PlayerInventory inventory, HeldItemContainerData data )
|
2019-06-12 07:40:20 +00:00
|
|
|
{
|
2020-06-27 09:23:45 +00:00
|
|
|
return new ContainerHeldItem( Registry.ModContainers.PRINTOUT.get(), id, inventory.player, data.getHand() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
public ItemStack getStack()
|
|
|
|
{
|
2019-06-12 07:40:20 +00:00
|
|
|
return stack;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
public boolean stillValid( @Nonnull PlayerEntity player )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
if( !player.isAlive() ) return false;
|
2018-12-29 16:42:02 +00:00
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
ItemStack stack = player.getItemInHand( hand );
|
2019-06-12 07:40:20 +00:00
|
|
|
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;
|
2021-06-12 21:18:35 +00:00
|
|
|
name = stack.getHoverName();
|
2019-06-12 07:40:20 +00:00
|
|
|
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 );
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|