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
|
2019-01-01 01:10:18 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.shared.turtle.blocks;
|
|
|
|
|
2018-02-04 21:35:21 +00:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.ComputerCraft;
|
2019-03-27 18:59:02 +00:00
|
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
|
|
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
|
|
|
import dan200.computercraft.api.turtle.TurtleSide;
|
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
|
|
|
import dan200.computercraft.shared.common.TileGeneric;
|
2019-03-27 18:59:02 +00:00
|
|
|
import dan200.computercraft.shared.computer.blocks.ComputerPeripheral;
|
2017-09-15 17:58:13 +00:00
|
|
|
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
|
|
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
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
|
|
|
import dan200.computercraft.shared.computer.core.ComputerState;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
2019-03-27 18:59:02 +00:00
|
|
|
import dan200.computercraft.shared.network.Containers;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.turtle.apis.TurtleAPI;
|
|
|
|
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
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
|
|
|
import dan200.computercraft.shared.util.*;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Items;
|
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
|
|
|
import net.minecraft.item.EnumDyeColor;
|
|
|
|
import net.minecraft.item.ItemDye;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
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
|
|
|
import net.minecraft.tileentity.TileEntityType;
|
2018-12-23 17:46:58 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.NonNullList;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2017-05-07 00:42:32 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
2017-05-08 23:41:20 +00:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraftforge.common.util.Constants;
|
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
|
|
|
import net.minecraftforge.common.util.LazyOptional;
|
2017-05-08 23:41:20 +00:00
|
|
|
import net.minecraftforge.items.IItemHandlerModifiable;
|
|
|
|
import net.minecraftforge.items.wrapper.InvWrapper;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2017-05-08 23:41:20 +00:00
|
|
|
import javax.annotation.Nullable;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-08 23:41:20 +00:00
|
|
|
import static net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
|
|
|
|
2018-12-28 11:39:59 +00:00
|
|
|
public class TileTurtle extends TileComputerBase implements ITurtleTile, DefaultInventory
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Statics
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public static final int INVENTORY_SIZE = 16;
|
2017-05-01 13:32:39 +00:00
|
|
|
public static final int INVENTORY_WIDTH = 4;
|
|
|
|
public static final int INVENTORY_HEIGHT = 4;
|
|
|
|
|
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
|
|
|
public static final NamedBlockEntityType<TileTurtle> FACTORY_NORMAL = NamedBlockEntityType.create(
|
|
|
|
new ResourceLocation( ComputerCraft.MOD_ID, "turtle_normal" ),
|
|
|
|
type -> new TileTurtle( type, ComputerFamily.Normal )
|
|
|
|
);
|
|
|
|
|
|
|
|
public static final NamedBlockEntityType<TileTurtle> FACTORY_ADVANCED = NamedBlockEntityType.create(
|
|
|
|
new ResourceLocation( ComputerCraft.MOD_ID, "turtle_advanced" ),
|
|
|
|
type -> new TileTurtle( type, ComputerFamily.Advanced )
|
|
|
|
);
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
// Members
|
2017-05-03 14:03:47 +00:00
|
|
|
|
|
|
|
enum MoveState
|
|
|
|
{
|
|
|
|
NOT_MOVED,
|
|
|
|
IN_PROGRESS,
|
|
|
|
MOVED
|
|
|
|
}
|
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
private NonNullList<ItemStack> m_inventory;
|
|
|
|
private NonNullList<ItemStack> m_previousInventory;
|
2017-05-08 23:41:20 +00:00
|
|
|
private final IItemHandlerModifiable m_itemHandler = new InvWrapper( this );
|
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
|
|
|
private final LazyOptional<IItemHandlerModifiable> m_itemHandlerCap = LazyOptional.of( () -> m_itemHandler );
|
2017-05-01 13:32:39 +00:00
|
|
|
private boolean m_inventoryChanged;
|
|
|
|
private TurtleBrain m_brain;
|
2017-05-03 14:03:47 +00:00
|
|
|
private MoveState m_moveState;
|
2018-01-16 14:24:31 +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
|
|
|
public TileTurtle( TileEntityType<? extends TileGeneric> type, ComputerFamily family )
|
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
|
|
|
super( type, family );
|
2017-05-11 00:08:26 +00:00
|
|
|
m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
|
|
|
m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
2017-05-01 13:32:39 +00:00
|
|
|
m_inventoryChanged = false;
|
2019-02-18 23:28:51 +00:00
|
|
|
m_brain = new TurtleBrain( this );
|
2017-05-03 14:03:47 +00:00
|
|
|
m_moveState = MoveState.NOT_MOVED;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasMoved()
|
|
|
|
{
|
2017-05-03 14:03:47 +00:00
|
|
|
return m_moveState == MoveState.MOVED;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 23:28:51 +00:00
|
|
|
@Override
|
|
|
|
protected ServerComputer createComputer( int instanceID, int id )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
ServerComputer computer = new ServerComputer(
|
2019-02-18 23:28:51 +00:00
|
|
|
getWorld(), id, m_label, instanceID, getFamily(),
|
|
|
|
ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalHeight_turtle
|
2017-05-01 13:32:39 +00:00
|
|
|
);
|
|
|
|
computer.setPosition( getPos() );
|
|
|
|
computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) );
|
|
|
|
m_brain.setupComputer( computer );
|
|
|
|
return computer;
|
|
|
|
}
|
|
|
|
|
2017-09-15 17:58:13 +00:00
|
|
|
@Override
|
|
|
|
public ComputerProxy createProxy()
|
|
|
|
{
|
|
|
|
return m_brain.getProxy();
|
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public void destroy()
|
|
|
|
{
|
|
|
|
if( !hasMoved() )
|
|
|
|
{
|
|
|
|
// Stop computer
|
|
|
|
super.destroy();
|
|
|
|
|
|
|
|
// Drop contents
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !getWorld().isRemote )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
int size = getSizeInventory();
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int i = 0; i < size; i++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
ItemStack stack = getStackInSlot( i );
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !stack.isEmpty() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
WorldUtil.dropItemStack( stack, getWorld(), getPos() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just turn off any redstone we had on
|
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
|
|
|
for( EnumFacing dir : DirectionUtil.FACINGS )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-08-01 20:04:48 +00:00
|
|
|
RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void unload()
|
|
|
|
{
|
|
|
|
if( !hasMoved() )
|
|
|
|
{
|
|
|
|
super.unload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-27 11:32:29 +00:00
|
|
|
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Request description from server
|
2018-12-27 13:10:13 +00:00
|
|
|
// requestTileEntityUpdate();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Apply dye
|
2018-12-27 11:32:29 +00:00
|
|
|
ItemStack currentItem = player.getHeldItem( hand );
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !currentItem.isEmpty() )
|
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( currentItem.getItem() instanceof ItemDye )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Dye to change turtle colour
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !getWorld().isRemote )
|
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
|
|
|
EnumDyeColor dye = ((ItemDye) currentItem.getItem()).getDyeColor();
|
2017-05-01 13:32:39 +00:00
|
|
|
if( m_brain.getDyeColour() != dye )
|
|
|
|
{
|
|
|
|
m_brain.setDyeColour( dye );
|
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.isCreative() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
currentItem.shrink( 1 );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-11 17:44:02 +00:00
|
|
|
else if( currentItem.getItem() == Items.WATER_BUCKET && m_brain.getColour() != -1 )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Water to remove turtle colour
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !getWorld().isRemote )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 17:44:02 +00:00
|
|
|
if( m_brain.getColour() != -1 )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 17:44:02 +00:00
|
|
|
m_brain.setColour( -1 );
|
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.isCreative() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-27 11:32:29 +00:00
|
|
|
player.setHeldItem( hand, new ItemStack( Items.BUCKET ) );
|
2017-05-07 00:42:32 +00:00
|
|
|
player.inventory.markDirty();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open GUI or whatever
|
2018-12-27 11:32:29 +00:00
|
|
|
return super.onActivate( player, hand, side, hitX, hitY, hitZ );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean canNameWithTag( EntityPlayer player )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openGUI( EntityPlayer player )
|
|
|
|
{
|
2019-03-27 18:59:02 +00:00
|
|
|
Containers.openTurtleGUI( player, this );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected double getInteractRange( EntityPlayer player )
|
|
|
|
{
|
|
|
|
return 12.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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
|
|
|
public void tick()
|
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
|
|
|
super.tick();
|
2017-05-01 13:32:39 +00:00
|
|
|
m_brain.update();
|
|
|
|
synchronized( m_inventory )
|
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !getWorld().isRemote && m_inventoryChanged )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-29 12:38:19 +00:00
|
|
|
ServerComputer computer = getServerComputer();
|
|
|
|
if( computer != null ) computer.queueEvent( "turtle_inventory" );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
m_inventoryChanged = false;
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int n = 0; n < getSizeInventory(); n++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
m_previousInventory.set( n, InventoryUtil.copyItem( getStackInSlot( n ) ) );
|
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
|
|
|
@Override
|
|
|
|
protected void updateBlockState( ComputerState newState )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-03 14:03:47 +00:00
|
|
|
@Override
|
2019-01-25 22:03:44 +00:00
|
|
|
public void onNeighbourChange( @Nonnull BlockPos neighbour )
|
2017-05-03 14:03:47 +00:00
|
|
|
{
|
2019-01-25 22:03:44 +00:00
|
|
|
if( m_moveState == MoveState.NOT_MOVED ) super.onNeighbourChange( neighbour );
|
2017-05-03 14:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 17:46:58 +00:00
|
|
|
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
|
2017-05-03 14:03:47 +00:00
|
|
|
{
|
2019-01-25 22:03:44 +00:00
|
|
|
if( m_moveState == MoveState.NOT_MOVED ) super.onNeighbourTileEntityChange( neighbour );
|
2017-05-03 14:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void notifyMoveStart()
|
|
|
|
{
|
2019-01-25 22:03:44 +00:00
|
|
|
if( m_moveState == MoveState.NOT_MOVED ) m_moveState = MoveState.IN_PROGRESS;
|
2017-05-03 14:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void notifyMoveEnd()
|
|
|
|
{
|
|
|
|
// MoveState.MOVED is final
|
2019-01-25 22:03:44 +00:00
|
|
|
if( m_moveState == MoveState.IN_PROGRESS ) m_moveState = MoveState.NOT_MOVED;
|
2017-05-03 14:03:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
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
|
|
|
public void read( NBTTagCompound nbt )
|
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
|
|
|
super.read( nbt );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Read inventory
|
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
|
|
|
NBTTagList nbttaglist = nbt.getList( "Items", Constants.NBT.TAG_COMPOUND );
|
2017-05-11 00:08:26 +00:00
|
|
|
m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
|
|
|
m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
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
|
|
|
for( int i = 0; i < nbttaglist.size(); i++ )
|
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
|
|
|
NBTTagCompound tag = nbttaglist.getCompound( i );
|
2019-03-29 21:21:39 +00:00
|
|
|
int slot = tag.getByte( "Slot" ) & 0xff;
|
|
|
|
if( slot < getSizeInventory() )
|
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
|
|
|
m_inventory.set( slot, ItemStack.read( tag ) );
|
2017-05-11 00:08:26 +00:00
|
|
|
m_previousInventory.set( slot, InventoryUtil.copyItem( m_inventory.get( slot ) ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read state
|
2018-12-29 14:01:00 +00:00
|
|
|
m_brain.readFromNBT( nbt );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
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
|
|
|
public NBTTagCompound write( NBTTagCompound nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Write inventory
|
|
|
|
NBTTagList nbttaglist = new NBTTagList();
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int i = 0; i < INVENTORY_SIZE; i++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
if( !m_inventory.get( i ).isEmpty() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-03-29 21:21:39 +00:00
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
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
|
|
|
tag.putByte( "Slot", (byte) i );
|
|
|
|
m_inventory.get( i ).write( tag );
|
|
|
|
nbttaglist.add( tag );
|
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
|
|
|
nbt.put( "Items", nbttaglist );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Write brain
|
2018-12-29 14:01:00 +00:00
|
|
|
nbt = m_brain.writeToNBT( nbt );
|
2017-05-01 13:51:26 +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
|
|
|
return super.write( nbt );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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
|
|
|
protected boolean isPeripheralBlockedOnSide( EnumFacing localSide )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return hasPeripheralUpgradeOnSide( localSide );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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
|
|
|
protected boolean isRedstoneBlockedOnSide( EnumFacing localSide )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-04 21:01:32 +00:00
|
|
|
return false;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IDirectionalTile
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumFacing getDirection()
|
|
|
|
{
|
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
|
|
|
return getBlockState().get( BlockTurtle.FACING );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDirection( EnumFacing dir )
|
|
|
|
{
|
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( dir.getAxis() == EnumFacing.Axis.Y ) dir = EnumFacing.NORTH;
|
|
|
|
world.setBlockState( pos, getBlockState().with( BlockTurtle.FACING, dir ) );
|
|
|
|
updateOutput();
|
|
|
|
updateInput();
|
|
|
|
onTileEntityChange();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ITurtleTile
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ITurtleUpgrade getUpgrade( TurtleSide side )
|
|
|
|
{
|
|
|
|
return m_brain.getUpgrade( side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-11 17:44:02 +00:00
|
|
|
public int getColour()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 17:44:02 +00:00
|
|
|
return m_brain.getColour();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getOverlay()
|
|
|
|
{
|
|
|
|
return m_brain.getOverlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ITurtleAccess getAccess()
|
|
|
|
{
|
|
|
|
return m_brain;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-01 13:51:26 +00:00
|
|
|
public Vec3d getRenderOffset( float f )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return m_brain.getRenderOffset( f );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getRenderYaw( float f )
|
|
|
|
{
|
|
|
|
return m_brain.getVisualYaw( f );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getToolRenderAngle( TurtleSide side, float f )
|
|
|
|
{
|
|
|
|
return m_brain.getToolRenderAngle( side, f );
|
|
|
|
}
|
|
|
|
|
2018-02-04 21:35:21 +00:00
|
|
|
public void setOwningPlayer( GameProfile player )
|
|
|
|
{
|
|
|
|
m_brain.setOwningPlayer( player );
|
|
|
|
markDirty();
|
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
// IInventory
|
2017-05-03 14:03:47 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public int getSizeInventory()
|
|
|
|
{
|
|
|
|
return INVENTORY_SIZE;
|
|
|
|
}
|
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
@Override
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
|
|
|
for( ItemStack stack : m_inventory )
|
|
|
|
{
|
|
|
|
if( !stack.isEmpty() ) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot( int slot )
|
|
|
|
{
|
|
|
|
if( slot >= 0 && slot < INVENTORY_SIZE )
|
|
|
|
{
|
|
|
|
synchronized( m_inventory )
|
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
return m_inventory.get( slot );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-11 00:08:26 +00:00
|
|
|
return ItemStack.EMPTY;
|
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
|
|
|
@Override
|
|
|
|
public ItemStack removeStackFromSlot( int slot )
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
synchronized( m_inventory )
|
|
|
|
{
|
|
|
|
ItemStack result = getStackInSlot( slot );
|
2017-05-11 00:08:26 +00:00
|
|
|
setInventorySlotContents( slot, ItemStack.EMPTY );
|
2017-05-01 14:48:44 +00:00
|
|
|
return result;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-03 14:03:47 +00:00
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize( int slot, int count )
|
|
|
|
{
|
|
|
|
if( count == 0 )
|
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
return ItemStack.EMPTY;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
synchronized( m_inventory )
|
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
ItemStack stack = getStackInSlot( slot );
|
2017-05-11 00:08:26 +00:00
|
|
|
if( stack.isEmpty() )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
return ItemStack.EMPTY;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-03 14:03:47 +00:00
|
|
|
|
2017-05-11 00:08:26 +00:00
|
|
|
if( stack.getCount() <= count )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
setInventorySlotContents( slot, ItemStack.EMPTY );
|
2017-05-01 14:48:44 +00:00
|
|
|
return stack;
|
|
|
|
}
|
2017-05-03 14:03:47 +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
|
|
|
ItemStack part = stack.split( count );
|
2017-05-01 13:32:39 +00:00
|
|
|
onInventoryDefinitelyChanged();
|
2017-05-01 14:48:44 +00:00
|
|
|
return part;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-11 00:08:26 +00:00
|
|
|
public void setInventorySlotContents( int i, @Nonnull ItemStack stack )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
if( i >= 0 && i < INVENTORY_SIZE )
|
|
|
|
{
|
|
|
|
synchronized( m_inventory )
|
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !InventoryUtil.areItemsEqual( stack, m_inventory.get( i ) ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
m_inventory.set( i, stack );
|
2017-05-01 13:32:39 +00:00
|
|
|
onInventoryDefinitelyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear()
|
|
|
|
{
|
|
|
|
synchronized( m_inventory )
|
|
|
|
{
|
|
|
|
boolean changed = false;
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int i = 0; i < INVENTORY_SIZE; i++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !m_inventory.get( i ).isEmpty() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
m_inventory.set( i, ItemStack.EMPTY );
|
2017-05-01 13:32:39 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( changed )
|
|
|
|
{
|
|
|
|
onInventoryDefinitelyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-03 14:03:47 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
@Override
|
|
|
|
public void markDirty()
|
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
super.markDirty();
|
|
|
|
synchronized( m_inventory )
|
|
|
|
{
|
|
|
|
if( !m_inventoryChanged )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int n = 0; n < getSizeInventory(); n++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !ItemStack.areItemStacksEqual( getStackInSlot( n ), m_previousInventory.get( n ) ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
m_inventoryChanged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
@Override
|
2017-05-11 00:08:26 +00:00
|
|
|
public boolean isUsableByPlayer( @Nonnull EntityPlayer player )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return isUsable( player, false );
|
|
|
|
}
|
|
|
|
|
2019-03-27 18:59:02 +00:00
|
|
|
private void onInventoryDefinitelyChanged()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
super.markDirty();
|
|
|
|
m_inventoryChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onTileEntityChange()
|
|
|
|
{
|
|
|
|
super.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Networking stuff
|
|
|
|
|
|
|
|
@Override
|
2019-04-02 10:50:13 +00:00
|
|
|
protected void writeDescription( @Nonnull NBTTagCompound nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-29 14:01:00 +00:00
|
|
|
super.writeDescription( nbt );
|
|
|
|
m_brain.writeDescription( nbt );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-02 10:50:13 +00:00
|
|
|
protected void readDescription( @Nonnull NBTTagCompound nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-29 14:01:00 +00:00
|
|
|
super.readDescription( nbt );
|
|
|
|
m_brain.readDescription( nbt );
|
2017-05-01 13:32:39 +00:00
|
|
|
updateBlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Privates
|
|
|
|
|
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
|
|
|
private boolean hasPeripheralUpgradeOnSide( EnumFacing side )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
ITurtleUpgrade upgrade;
|
|
|
|
switch( side )
|
|
|
|
{
|
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
|
|
|
case WEST:
|
2018-12-23 17:46:58 +00:00
|
|
|
upgrade = getUpgrade( TurtleSide.Right );
|
|
|
|
break;
|
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
|
|
|
case EAST:
|
2018-12-23 17:46:58 +00:00
|
|
|
upgrade = getUpgrade( TurtleSide.Left );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-07 00:52:55 +00:00
|
|
|
return upgrade != null && upgrade.getType().isPeripheral();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void transferStateFrom( TileTurtle copy )
|
|
|
|
{
|
|
|
|
super.transferStateFrom( copy );
|
|
|
|
m_inventory = copy.m_inventory;
|
|
|
|
m_previousInventory = copy.m_previousInventory;
|
|
|
|
m_inventoryChanged = copy.m_inventoryChanged;
|
|
|
|
m_brain = copy.m_brain;
|
|
|
|
m_brain.setOwner( this );
|
2017-05-03 14:03:47 +00:00
|
|
|
copy.m_moveState = MoveState.MOVED;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-08 23:41:20 +00:00
|
|
|
|
2019-03-27 18:59:02 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public IPeripheral getPeripheral( @Nonnull EnumFacing side )
|
|
|
|
{
|
|
|
|
return hasMoved() ? null : new ComputerPeripheral( "turtle", createProxy() );
|
|
|
|
}
|
|
|
|
|
2017-05-08 23:41:20 +00:00
|
|
|
public IItemHandlerModifiable getItemHandler()
|
|
|
|
{
|
|
|
|
return m_itemHandler;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
@Nonnull
|
2017-05-08 23:41:20 +00:00
|
|
|
@Override
|
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
|
|
|
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> cap, @Nullable EnumFacing side )
|
2017-05-08 23:41:20 +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( cap == ITEM_HANDLER_CAPABILITY ) return m_itemHandlerCap.cast();
|
|
|
|
return super.getCapability( cap, side );
|
2017-05-08 23:41:20 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|