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
|
|
|
|
*/
|
|
|
|
package dan200.computercraft.shared.turtle.core;
|
|
|
|
|
|
|
|
import com.google.common.base.Objects;
|
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;
|
Replace getMethodNames/callMethod with annotations (#447)
When creating a peripheral or custom Lua object, one must implement two
methods:
- getMethodNames(): String[] - Returns the name of the methods
- callMethod(int, ...): Object[] - Invokes the method using an index in
the above array.
This has a couple of problems:
- It's somewhat unwieldy to use - you need to keep track of array
indices, which leads to ugly code.
- Functions which yield (for instance, those which run on the main
thread) are blocking. This means we need to spawn new threads for
each CC-side yield.
We replace this system with a few changes:
- @LuaFunction annotation: One may annotate a public instance method
with this annotation. This then exposes a peripheral/lua object
method.
Furthermore, this method can accept and return a variety of types,
which often makes functions cleaner (e.g. can return an int rather
than an Object[], and specify and int argument rather than
Object[]).
- MethodResult: Instead of returning an Object[] and having blocking
yields, functions return a MethodResult. This either contains an
immediate return, or an instruction to yield with some continuation
to resume with.
MethodResult is then interpreted by the Lua runtime (i.e. Cobalt),
rather than our weird bodgey hacks before. This means we no longer
spawn new threads when yielding within CC.
- Methods accept IArguments instead of a raw Object array. This has a
few benefits:
- Consistent argument handling - people no longer need to use
ArgumentHelper (as it doesn't exist!), or even be aware of its
existence - you're rather forced into using it.
- More efficient code in some cases. We provide a Cobalt-specific
implementation of IArguments, which avoids the boxing/unboxing when
handling numbers and binary strings.
2020-05-15 12:21:16 +00:00
|
|
|
import dan200.computercraft.api.lua.ILuaCallback;
|
|
|
|
import dan200.computercraft.api.lua.MethodResult;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
|
|
|
import dan200.computercraft.api.turtle.*;
|
2019-04-09 09:02:54 +00:00
|
|
|
import dan200.computercraft.core.computer.ComputerSide;
|
2019-03-29 21:21:39 +00:00
|
|
|
import dan200.computercraft.shared.TurtleUpgrades;
|
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.core.ComputerFamily;
|
|
|
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
|
|
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
2018-12-27 11:32:29 +00:00
|
|
|
import dan200.computercraft.shared.util.Colour;
|
|
|
|
import dan200.computercraft.shared.util.Holiday;
|
|
|
|
import dan200.computercraft.shared.util.HolidayUtil;
|
2019-10-04 18:44:34 +00:00
|
|
|
import dan200.computercraft.shared.util.InventoryDelegate;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.block.Block;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.block.BlockState;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
2017-05-11 00:08:26 +00:00
|
|
|
import net.minecraft.entity.MoverType;
|
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.fluid.IFluidState;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.item.DyeColor;
|
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
|
|
|
import net.minecraft.particles.ParticleTypes;
|
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.tags.FluidTags;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.util.Direction;
|
|
|
|
import net.minecraft.util.EntityPredicates;
|
2017-05-07 00:16:08 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.Constants;
|
2017-05-08 23:41:20 +00:00
|
|
|
import net.minecraftforge.items.IItemHandlerModifiable;
|
2019-10-04 15:53:48 +00:00
|
|
|
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;
|
2020-10-31 10:59:24 +00:00
|
|
|
import javax.annotation.Nullable;
|
2017-05-01 13:32:39 +00:00
|
|
|
import java.util.*;
|
2019-03-20 21:26:56 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
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
|
|
|
import static dan200.computercraft.shared.common.IColouredItem.NBT_COLOUR;
|
2019-06-08 12:36:31 +00:00
|
|
|
import static dan200.computercraft.shared.util.WaterloggableHelpers.WATERLOGGED;
|
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
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public class TurtleBrain implements ITurtleAccess
|
|
|
|
{
|
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 String NBT_RIGHT_UPGRADE = "RightUpgrade";
|
|
|
|
public static final String NBT_RIGHT_UPGRADE_DATA = "RightUpgradeNbt";
|
|
|
|
public static final String NBT_LEFT_UPGRADE = "LeftUpgrade";
|
|
|
|
public static final String NBT_LEFT_UPGRADE_DATA = "LeftUpgradeNbt";
|
|
|
|
public static final String NBT_FUEL = "Fuel";
|
|
|
|
public static final String NBT_OVERLAY = "Overlay";
|
|
|
|
|
|
|
|
private static final String NBT_SLOT = "Slot";
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
private static final int ANIM_DURATION = 8;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private TileTurtle owner;
|
|
|
|
private ComputerProxy proxy;
|
|
|
|
private GameProfile owningPlayer;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private final IInventory inventory = (InventoryDelegate) () -> owner;
|
|
|
|
private final IItemHandlerModifiable inventoryWrapper = new InvWrapper( inventory );
|
2019-10-04 15:53:48 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private final Queue<TurtleCommandQueueEntry> commandQueue = new ArrayDeque<>();
|
|
|
|
private int commandsIssued = 0;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private final Map<TurtleSide, ITurtleUpgrade> upgrades = new EnumMap<>( TurtleSide.class );
|
2020-05-15 16:09:12 +00:00
|
|
|
private final Map<TurtleSide, IPeripheral> peripherals = new EnumMap<>( TurtleSide.class );
|
2021-01-15 16:35:49 +00:00
|
|
|
private final Map<TurtleSide, CompoundNBT> upgradeNBTData = new EnumMap<>( TurtleSide.class );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private int selectedSlot = 0;
|
|
|
|
private int fuelLevel = 0;
|
|
|
|
private int colourHex = -1;
|
|
|
|
private ResourceLocation overlay = null;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private TurtleAnimation animation = TurtleAnimation.NONE;
|
|
|
|
private int animationProgress = 0;
|
|
|
|
private int lastAnimationProgress = 0;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
TurtlePlayer cachedPlayer;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
public TurtleBrain( TileTurtle turtle )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
owner = turtle;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setOwner( TileTurtle owner )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
this.owner = owner;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public TileTurtle getOwner()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return owner;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 17:58:13 +00:00
|
|
|
public ComputerProxy getProxy()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( proxy == null ) proxy = new ComputerProxy( () -> owner );
|
|
|
|
return proxy;
|
2017-09-15 17:58:13 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public ComputerFamily getFamily()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return owner.getFamily();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setupComputer( ServerComputer computer )
|
|
|
|
{
|
|
|
|
updatePeripherals( computer );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void update()
|
|
|
|
{
|
|
|
|
World world = getWorld();
|
2021-01-09 19:22:58 +00:00
|
|
|
if( !world.isClientSide )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Advance movement
|
|
|
|
updateCommands();
|
2020-11-28 13:13:35 +00:00
|
|
|
|
|
|
|
// The block may have been broken while the command was executing (for instance, if a block explodes
|
|
|
|
// when being mined). If so, abort.
|
2021-01-15 16:35:49 +00:00
|
|
|
if( owner.isRemoved() ) return;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Advance animation
|
|
|
|
updateAnimation();
|
|
|
|
|
|
|
|
// Advance upgrades
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !upgrades.isEmpty() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
for( Map.Entry<TurtleSide, ITurtleUpgrade> entry : upgrades.entrySet() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
entry.getValue().update( this, entry.getKey() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
2019-11-25 09:15:20 +00:00
|
|
|
* Read common data for saving and client synchronisation.
|
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
|
|
|
*
|
|
|
|
* @param nbt The tag to read from
|
|
|
|
*/
|
2019-06-08 12:36:31 +00:00
|
|
|
private void readCommon( CompoundNBT 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
|
|
|
// Read fields
|
2021-01-15 16:35:49 +00:00
|
|
|
colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1;
|
|
|
|
fuelLevel = nbt.contains( NBT_FUEL ) ? nbt.getInt( NBT_FUEL ) : 0;
|
|
|
|
overlay = nbt.contains( NBT_OVERLAY ) ? new ResourceLocation( nbt.getString( NBT_OVERLAY ) ) : null;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Read upgrades
|
2021-06-01 17:55:12 +00:00
|
|
|
setUpgradeDirect( TurtleSide.LEFT, nbt.contains( NBT_LEFT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_LEFT_UPGRADE ) ) : null );
|
|
|
|
setUpgradeDirect( TurtleSide.RIGHT, nbt.contains( NBT_RIGHT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_RIGHT_UPGRADE ) ) : null );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// NBT
|
2021-01-15 16:35:49 +00:00
|
|
|
upgradeNBTData.clear();
|
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( nbt.contains( NBT_LEFT_UPGRADE_DATA ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
upgradeNBTData.put( TurtleSide.LEFT, nbt.getCompound( NBT_LEFT_UPGRADE_DATA ).copy() );
|
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( nbt.contains( NBT_RIGHT_UPGRADE_DATA ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
upgradeNBTData.put( TurtleSide.RIGHT, nbt.getCompound( NBT_RIGHT_UPGRADE_DATA ).copy() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
private void writeCommon( CompoundNBT nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
nbt.putInt( NBT_FUEL, fuelLevel );
|
|
|
|
if( colourHex != -1 ) nbt.putInt( NBT_COLOUR, colourHex );
|
|
|
|
if( overlay != null ) nbt.putString( NBT_OVERLAY, overlay.toString() );
|
2018-02-04 21:35:21 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
// Write upgrades
|
2020-01-28 22:28:48 +00:00
|
|
|
String leftUpgradeId = getUpgradeId( getUpgrade( TurtleSide.LEFT ) );
|
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( leftUpgradeId != null ) nbt.putString( NBT_LEFT_UPGRADE, leftUpgradeId );
|
2020-01-28 22:28:48 +00:00
|
|
|
String rightUpgradeId = getUpgradeId( getUpgrade( TurtleSide.RIGHT ) );
|
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( rightUpgradeId != null ) nbt.putString( NBT_RIGHT_UPGRADE, rightUpgradeId );
|
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
|
|
|
// Write upgrade NBT
|
2021-01-15 16:35:49 +00:00
|
|
|
if( upgradeNBTData.containsKey( TurtleSide.LEFT ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-01-28 22:28:48 +00:00
|
|
|
nbt.put( NBT_LEFT_UPGRADE_DATA, getUpgradeNBTData( TurtleSide.LEFT ).copy() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2021-01-15 16:35:49 +00:00
|
|
|
if( upgradeNBTData.containsKey( TurtleSide.RIGHT ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-01-28 22:28:48 +00:00
|
|
|
nbt.put( NBT_RIGHT_UPGRADE_DATA, getUpgradeNBTData( TurtleSide.RIGHT ).copy() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public void readFromNBT( CompoundNBT 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
|
|
|
readCommon( 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
|
|
|
// Read state
|
2021-01-15 16:35:49 +00:00
|
|
|
selectedSlot = nbt.getInt( NBT_SLOT );
|
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
|
|
|
// Read owner
|
|
|
|
if( nbt.contains( "Owner", Constants.NBT.TAG_COMPOUND ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
CompoundNBT owner = nbt.getCompound( "Owner" );
|
2021-01-15 16:35:49 +00:00
|
|
|
owningPlayer = new GameProfile(
|
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
|
|
|
new UUID( owner.getLong( "UpperId" ), owner.getLong( "LowerId" ) ),
|
|
|
|
owner.getString( "Name" )
|
|
|
|
);
|
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
|
|
|
else
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
owningPlayer = null;
|
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
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public CompoundNBT writeToNBT( CompoundNBT nbt )
|
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
|
|
|
{
|
|
|
|
writeCommon( nbt );
|
|
|
|
|
|
|
|
// Write state
|
2021-01-15 16:35:49 +00:00
|
|
|
nbt.putInt( NBT_SLOT, selectedSlot );
|
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
|
|
|
// Write owner
|
2021-01-15 16:35:49 +00:00
|
|
|
if( owningPlayer != null )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
CompoundNBT owner = new CompoundNBT();
|
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( "Owner", owner );
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
owner.putLong( "UpperId", owningPlayer.getId().getMostSignificantBits() );
|
|
|
|
owner.putLong( "LowerId", owningPlayer.getId().getLeastSignificantBits() );
|
|
|
|
owner.putString( "Name", owningPlayer.getName() );
|
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
|
|
|
return 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
|
|
|
private static String getUpgradeId( ITurtleUpgrade upgrade )
|
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
|
|
|
return upgrade != null ? upgrade.getUpgradeID().toString() : null;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public void readDescription( CompoundNBT nbt )
|
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
|
|
|
{
|
|
|
|
readCommon( nbt );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Animation
|
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
|
|
|
TurtleAnimation anim = TurtleAnimation.values()[nbt.getInt( "Animation" )];
|
2021-01-15 16:35:49 +00:00
|
|
|
if( anim != animation &&
|
2020-01-28 22:28:48 +00:00
|
|
|
anim != TurtleAnimation.WAIT &&
|
|
|
|
anim != TurtleAnimation.SHORT_WAIT &&
|
|
|
|
anim != TurtleAnimation.NONE )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
animation = anim;
|
|
|
|
animationProgress = 0;
|
|
|
|
lastAnimationProgress = 0;
|
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
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public void writeDescription( CompoundNBT nbt )
|
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
|
|
|
{
|
|
|
|
writeCommon( nbt );
|
2021-01-15 16:35:49 +00:00
|
|
|
nbt.putInt( "Animation", animation.ordinal() );
|
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
|
|
|
|
public World getWorld()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return owner.getLevel();
|
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
|
|
|
|
public BlockPos getPosition()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return owner.getBlockPos();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-06 23:07:42 +00:00
|
|
|
public boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( world.isClientSide || getWorld().isClientSide )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-03-29 21:21:39 +00:00
|
|
|
throw new UnsupportedOperationException( "Cannot teleport on the client" );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cache info about the old turtle (so we don't access this after we delete ourselves)
|
|
|
|
World oldWorld = getWorld();
|
2021-01-15 16:35:49 +00:00
|
|
|
TileTurtle oldOwner = owner;
|
|
|
|
BlockPos oldPos = owner.getBlockPos();
|
|
|
|
BlockState oldBlock = owner.getBlockState();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
if( oldWorld == world && oldPos.equals( pos ) )
|
|
|
|
{
|
|
|
|
// Teleporting to the current position is a no-op
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-12 17:50:46 +00:00
|
|
|
// Ensure the chunk is loaded
|
2019-06-09 08:07:31 +00:00
|
|
|
if( !world.isAreaLoaded( pos, 0 ) ) return false;
|
2018-02-12 17:50:46 +00:00
|
|
|
|
|
|
|
// Ensure we're inside the world border
|
2021-01-09 19:22:58 +00:00
|
|
|
if( !world.getWorldBorder().isWithinBounds( pos ) ) return false;
|
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
|
|
|
IFluidState existingFluid = world.getBlockState( pos ).getFluidState();
|
2019-06-08 12:36:31 +00:00
|
|
|
BlockState newState = oldBlock
|
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
|
|
|
// We only mark this as waterlogged when travelling into a source block. This prevents us from spreading
|
|
|
|
// fluid by creating a new source when moving into a block, causing the next block to be almost full and
|
|
|
|
// then moving into that.
|
2021-01-09 19:22:58 +00:00
|
|
|
.setValue( WATERLOGGED, existingFluid.is( FluidTags.WATER ) && existingFluid.isSource() );
|
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
|
|
|
|
2017-05-03 14:03:47 +00:00
|
|
|
oldOwner.notifyMoveStart();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Create a new turtle
|
2021-01-09 19:22:58 +00:00
|
|
|
if( world.setBlock( pos, newState, 0 ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-03 14:03:47 +00:00
|
|
|
Block block = world.getBlockState( pos ).getBlock();
|
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( block == oldBlock.getBlock() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
TileEntity newTile = world.getBlockEntity( pos );
|
2018-12-29 14:01:00 +00:00
|
|
|
if( newTile instanceof TileTurtle )
|
2017-05-03 14:03:47 +00:00
|
|
|
{
|
|
|
|
// Copy the old turtle state into the new turtle
|
2018-12-23 17:46:58 +00:00
|
|
|
TileTurtle newTurtle = (TileTurtle) newTile;
|
2021-01-09 19:22:58 +00:00
|
|
|
newTurtle.setLevelAndPosition( world, pos );
|
2017-05-03 14:03:47 +00:00
|
|
|
newTurtle.transferStateFrom( oldOwner );
|
|
|
|
newTurtle.createServerComputer().setWorld( world );
|
|
|
|
newTurtle.createServerComputer().setPosition( pos );
|
|
|
|
|
|
|
|
// Remove the old turtle
|
2019-06-08 12:36:31 +00:00
|
|
|
oldWorld.removeBlock( oldPos, false );
|
2017-05-03 14:03:47 +00:00
|
|
|
|
|
|
|
// Make sure everybody knows about it
|
|
|
|
newTurtle.updateBlock();
|
|
|
|
newTurtle.updateInput();
|
|
|
|
newTurtle.updateOutput();
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 14:03:47 +00:00
|
|
|
// Something went wrong, remove the newly created turtle
|
2019-06-08 12:36:31 +00:00
|
|
|
world.removeBlock( pos, false );
|
2017-05-03 14:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
// whatever happens, unblock old turtle in case it's still in world
|
|
|
|
oldOwner.notifyMoveEnd();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2017-05-01 13:51:26 +00:00
|
|
|
public Vec3d getVisualPosition( float f )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 13:51:26 +00:00
|
|
|
Vec3d offset = getRenderOffset( f );
|
2021-01-15 16:35:49 +00:00
|
|
|
BlockPos pos = owner.getBlockPos();
|
2017-05-01 13:51:26 +00:00
|
|
|
return new Vec3d(
|
2017-06-12 08:14:57 +00:00
|
|
|
pos.getX() + 0.5 + offset.x,
|
|
|
|
pos.getY() + 0.5 + offset.y,
|
|
|
|
pos.getZ() + 0.5 + offset.z
|
2017-05-01 13:32:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getVisualYaw( float f )
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
float yaw = getDirection().toYRot();
|
2021-01-15 16:35:49 +00:00
|
|
|
switch( animation )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-01-28 22:28:48 +00:00
|
|
|
case TURN_LEFT:
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
yaw += 90.0f * (1.0f - getAnimationFraction( f ));
|
|
|
|
if( yaw >= 360.0f )
|
|
|
|
{
|
|
|
|
yaw -= 360.0f;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-01-28 22:28:48 +00:00
|
|
|
case TURN_RIGHT:
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
yaw += -90.0f * (1.0f - getAnimationFraction( f ));
|
|
|
|
if( yaw < 0.0f )
|
|
|
|
{
|
|
|
|
yaw += 360.0f;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return yaw;
|
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2019-06-08 12:36:31 +00:00
|
|
|
public Direction getDirection()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return owner.getDirection();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-08 12:36:31 +00:00
|
|
|
public void setDirection( @Nonnull Direction dir )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
owner.setDirection( dir );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedSlot()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return selectedSlot;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSelectedSlot( int slot )
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot set the slot on the client" );
|
2019-03-29 21:21:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
if( slot >= 0 && slot < owner.getContainerSize() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
selectedSlot = slot;
|
|
|
|
owner.onTileEntityChange();
|
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
|
|
|
|
public IInventory getInventory()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return inventory;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 23:41:20 +00:00
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public IItemHandlerModifiable getItemHandler()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return inventoryWrapper;
|
2017-05-08 23:41:20 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
|
|
|
public boolean isFuelNeeded()
|
|
|
|
{
|
|
|
|
return ComputerCraft.turtlesNeedFuel;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFuelLevel()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return Math.min( fuelLevel, getFuelLimit() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFuelLevel( int level )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
fuelLevel = Math.min( level, getFuelLimit() );
|
|
|
|
owner.onTileEntityChange();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFuelLimit()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( owner.getFamily() == ComputerFamily.ADVANCED )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return ComputerCraft.advancedTurtleFuelLimit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ComputerCraft.turtleFuelLimit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean consumeFuel( int fuel )
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot consume fuel on the client" );
|
2019-03-29 21:21:39 +00:00
|
|
|
|
|
|
|
if( !isFuelNeeded() ) return true;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
int consumption = Math.max( fuel, 0 );
|
|
|
|
if( getFuelLevel() >= consumption )
|
|
|
|
{
|
|
|
|
setFuelLevel( getFuelLevel() - consumption );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addFuel( int fuel )
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot add fuel on the client" );
|
2019-03-29 21:21:39 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
int addition = Math.max( fuel, 0 );
|
|
|
|
setFuelLevel( getFuelLevel() + addition );
|
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
Replace getMethodNames/callMethod with annotations (#447)
When creating a peripheral or custom Lua object, one must implement two
methods:
- getMethodNames(): String[] - Returns the name of the methods
- callMethod(int, ...): Object[] - Invokes the method using an index in
the above array.
This has a couple of problems:
- It's somewhat unwieldy to use - you need to keep track of array
indices, which leads to ugly code.
- Functions which yield (for instance, those which run on the main
thread) are blocking. This means we need to spawn new threads for
each CC-side yield.
We replace this system with a few changes:
- @LuaFunction annotation: One may annotate a public instance method
with this annotation. This then exposes a peripheral/lua object
method.
Furthermore, this method can accept and return a variety of types,
which often makes functions cleaner (e.g. can return an int rather
than an Object[], and specify and int argument rather than
Object[]).
- MethodResult: Instead of returning an Object[] and having blocking
yields, functions return a MethodResult. This either contains an
immediate return, or an instruction to yield with some continuation
to resume with.
MethodResult is then interpreted by the Lua runtime (i.e. Cobalt),
rather than our weird bodgey hacks before. This means we no longer
spawn new threads when yielding within CC.
- Methods accept IArguments instead of a raw Object array. This has a
few benefits:
- Consistent argument handling - people no longer need to use
ArgumentHelper (as it doesn't exist!), or even be aware of its
existence - you're rather forced into using it.
- More efficient code in some cases. We provide a Cobalt-specific
implementation of IArguments, which avoids the boxing/unboxing when
handling numbers and binary strings.
2020-05-15 12:21:16 +00:00
|
|
|
public MethodResult executeCommand( @Nonnull ITurtleCommand command )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot run commands on the client" );
|
2021-06-06 18:26:20 +00:00
|
|
|
if( commandQueue.size() > 16 ) return MethodResult.of( false, "Too many ongoing turtle commands" );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-06-06 18:26:20 +00:00
|
|
|
commandQueue.offer( new TurtleCommandQueueEntry( ++commandsIssued, command ) );
|
|
|
|
int commandID = commandsIssued;
|
Replace getMethodNames/callMethod with annotations (#447)
When creating a peripheral or custom Lua object, one must implement two
methods:
- getMethodNames(): String[] - Returns the name of the methods
- callMethod(int, ...): Object[] - Invokes the method using an index in
the above array.
This has a couple of problems:
- It's somewhat unwieldy to use - you need to keep track of array
indices, which leads to ugly code.
- Functions which yield (for instance, those which run on the main
thread) are blocking. This means we need to spawn new threads for
each CC-side yield.
We replace this system with a few changes:
- @LuaFunction annotation: One may annotate a public instance method
with this annotation. This then exposes a peripheral/lua object
method.
Furthermore, this method can accept and return a variety of types,
which often makes functions cleaner (e.g. can return an int rather
than an Object[], and specify and int argument rather than
Object[]).
- MethodResult: Instead of returning an Object[] and having blocking
yields, functions return a MethodResult. This either contains an
immediate return, or an instruction to yield with some continuation
to resume with.
MethodResult is then interpreted by the Lua runtime (i.e. Cobalt),
rather than our weird bodgey hacks before. This means we no longer
spawn new threads when yielding within CC.
- Methods accept IArguments instead of a raw Object array. This has a
few benefits:
- Consistent argument handling - people no longer need to use
ArgumentHelper (as it doesn't exist!), or even be aware of its
existence - you're rather forced into using it.
- More efficient code in some cases. We provide a Cobalt-specific
implementation of IArguments, which avoids the boxing/unboxing when
handling numbers and binary strings.
2020-05-15 12:21:16 +00:00
|
|
|
return new CommandCallback( commandID ).pull;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-06 23:07:42 +00:00
|
|
|
public void playAnimation( @Nonnull TurtleAnimation animation )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot play animations on the client" );
|
2019-03-29 21:21:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
this.animation = animation;
|
|
|
|
if( this.animation == TurtleAnimation.SHORT_WAIT )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
animationProgress = ANIM_DURATION / 2;
|
|
|
|
lastAnimationProgress = ANIM_DURATION / 2;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
animationProgress = 0;
|
|
|
|
lastAnimationProgress = 0;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2021-01-15 16:35:49 +00:00
|
|
|
owner.updateBlock();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public ResourceLocation getOverlay()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return overlay;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setOverlay( ResourceLocation overlay )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( !Objects.equal( this.overlay, overlay ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
this.overlay = overlay;
|
|
|
|
owner.updateBlock();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public DyeColor getDyeColour()
|
2017-05-13 21:42:31 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( colourHex == -1 ) return null;
|
|
|
|
Colour colour = Colour.fromHex( colourHex );
|
2019-06-08 12:36:31 +00:00
|
|
|
return colour == null ? null : DyeColor.byId( 15 - colour.ordinal() );
|
2017-05-13 21:42:31 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public void setDyeColour( DyeColor dyeColour )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-13 21:42:31 +00:00
|
|
|
int newColour = -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( dyeColour != null )
|
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
|
|
|
newColour = Colour.values()[15 - dyeColour.getId()].getHex();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2021-01-15 16:35:49 +00:00
|
|
|
if( colourHex != newColour )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
colourHex = newColour;
|
|
|
|
owner.updateBlock();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 17:44:02 +00:00
|
|
|
@Override
|
|
|
|
public void setColour( int colour )
|
|
|
|
{
|
|
|
|
if( colour >= 0 && colour <= 0xFFFFFF )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( colourHex != colour )
|
2017-05-11 17:44:02 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
colourHex = colour;
|
|
|
|
owner.updateBlock();
|
2017-05-11 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-15 16:35:49 +00:00
|
|
|
else if( colourHex != -1 )
|
2017-05-11 17:44:02 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
colourHex = -1;
|
|
|
|
owner.updateBlock();
|
2017-05-11 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getColour()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return colourHex;
|
2017-05-11 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2018-02-04 21:35:21 +00:00
|
|
|
public void setOwningPlayer( GameProfile profile )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
owningPlayer = profile;
|
2018-02-04 21:35:21 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 10:59:24 +00:00
|
|
|
@Nullable
|
2018-02-04 21:35:21 +00:00
|
|
|
@Override
|
|
|
|
public GameProfile getOwningPlayer()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return owningPlayer;
|
2018-02-04 21:35:21 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2017-05-06 23:07:42 +00:00
|
|
|
public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return upgrades.get( side );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-06 23:07:42 +00:00
|
|
|
public void setUpgrade( @Nonnull TurtleSide side, ITurtleUpgrade upgrade )
|
2021-06-01 17:55:12 +00:00
|
|
|
{
|
|
|
|
if( !setUpgradeDirect( side, upgrade ) ) return;
|
|
|
|
|
|
|
|
// This is a separate function to avoid updating the block when reading the NBT. We don't need to do this as
|
|
|
|
// either the block is newly placed (and so won't have changed) or is being updated with /data, which calls
|
|
|
|
// updateBlock for us.
|
2021-06-01 18:12:35 +00:00
|
|
|
if( owner.getLevel() != null )
|
|
|
|
{
|
|
|
|
owner.updateBlock();
|
|
|
|
owner.updateInput();
|
|
|
|
}
|
2021-06-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean setUpgradeDirect( @Nonnull TurtleSide side, ITurtleUpgrade upgrade )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Remove old upgrade
|
2021-01-15 16:35:49 +00:00
|
|
|
if( upgrades.containsKey( side ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-06-01 17:55:12 +00:00
|
|
|
if( upgrades.get( side ) == upgrade ) return false;
|
2021-01-15 16:35:49 +00:00
|
|
|
upgrades.remove( side );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-01 17:55:12 +00:00
|
|
|
if( upgrade == null ) return false;
|
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
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
upgradeNBTData.remove( side );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Set new upgrade
|
2021-01-15 16:35:49 +00:00
|
|
|
if( upgrade != null ) upgrades.put( side, upgrade );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Notify clients and create peripherals
|
2021-01-15 16:35:49 +00:00
|
|
|
if( owner.getLevel() != null )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
updatePeripherals( owner.createServerComputer() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2021-06-01 17:55:12 +00:00
|
|
|
|
|
|
|
return true;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-06 23:07:42 +00:00
|
|
|
public IPeripheral getPeripheral( @Nonnull TurtleSide side )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-03-29 21:21:39 +00:00
|
|
|
return peripherals.get( side );
|
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
|
2019-06-08 12:36:31 +00:00
|
|
|
public CompoundNBT getUpgradeNBTData( TurtleSide side )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
CompoundNBT nbt = upgradeNBTData.get( side );
|
|
|
|
if( nbt == null ) upgradeNBTData.put( side, nbt = new CompoundNBT() );
|
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 nbt;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-06 23:07:42 +00:00
|
|
|
public void updateUpgradeNBTData( @Nonnull TurtleSide side )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
owner.updateBlock();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:51:26 +00:00
|
|
|
public Vec3d getRenderOffset( float f )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
switch( animation )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_FORWARD:
|
|
|
|
case MOVE_BACK:
|
|
|
|
case MOVE_UP:
|
|
|
|
case MOVE_DOWN:
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Get direction
|
2019-06-08 12:36:31 +00:00
|
|
|
Direction dir;
|
2021-01-15 16:35:49 +00:00
|
|
|
switch( animation )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_FORWARD:
|
2017-05-01 13:32:39 +00:00
|
|
|
default:
|
|
|
|
dir = getDirection();
|
|
|
|
break;
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_BACK:
|
2017-05-01 13:32:39 +00:00
|
|
|
dir = getDirection().getOpposite();
|
|
|
|
break;
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_UP:
|
2019-06-08 12:36:31 +00:00
|
|
|
dir = Direction.UP;
|
2017-05-01 13:32:39 +00:00
|
|
|
break;
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_DOWN:
|
2019-06-08 12:36:31 +00:00
|
|
|
dir = Direction.DOWN;
|
2017-05-01 13:32:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-24 05:18:20 +00:00
|
|
|
double distance = -1.0 + getAnimationFraction( f );
|
2017-05-01 13:51:26 +00:00
|
|
|
return new Vec3d(
|
2021-01-09 19:22:58 +00:00
|
|
|
distance * dir.getStepX(),
|
|
|
|
distance * dir.getStepY(),
|
|
|
|
distance * dir.getStepZ()
|
2017-05-01 13:32:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2018-12-27 11:32:29 +00:00
|
|
|
return Vec3d.ZERO;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getToolRenderAngle( TurtleSide side, float f )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return (side == TurtleSide.LEFT && animation == TurtleAnimation.SWING_LEFT_TOOL) ||
|
|
|
|
(side == TurtleSide.RIGHT && animation == TurtleAnimation.SWING_RIGHT_TOOL)
|
2019-03-29 21:21:39 +00:00
|
|
|
? 45.0f * (float) Math.sin( getAnimationFraction( f ) * Math.PI )
|
|
|
|
: 0.0f;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 09:02:54 +00:00
|
|
|
private static ComputerSide toDirection( TurtleSide side )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
switch( side )
|
|
|
|
{
|
2020-01-28 22:28:48 +00:00
|
|
|
case LEFT:
|
2019-04-09 09:02:54 +00:00
|
|
|
return ComputerSide.LEFT;
|
2020-01-28 22:28:48 +00:00
|
|
|
case RIGHT:
|
2017-05-01 13:32:39 +00:00
|
|
|
default:
|
2019-04-09 09:02:54 +00:00
|
|
|
return ComputerSide.RIGHT;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 23:28:51 +00:00
|
|
|
private void updatePeripherals( ServerComputer serverComputer )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-02-18 23:28:51 +00:00
|
|
|
if( serverComputer == null ) return;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Update peripherals
|
|
|
|
for( TurtleSide side : TurtleSide.values() )
|
|
|
|
{
|
|
|
|
ITurtleUpgrade upgrade = getUpgrade( side );
|
|
|
|
IPeripheral peripheral = null;
|
2017-05-03 16:28:54 +00:00
|
|
|
if( upgrade != null && upgrade.getType().isPeripheral() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
peripheral = upgrade.createPeripheral( this, side );
|
|
|
|
}
|
|
|
|
|
2019-02-18 23:28:51 +00:00
|
|
|
IPeripheral existing = peripherals.get( side );
|
|
|
|
if( existing == peripheral || (existing != null && peripheral != null && existing.equals( peripheral )) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-02-18 23:28:51 +00:00
|
|
|
// If the peripheral is the same, just use that.
|
|
|
|
peripheral = existing;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2019-02-18 23:28:51 +00:00
|
|
|
else
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-02-18 23:28:51 +00:00
|
|
|
// Otherwise update our map
|
|
|
|
peripherals.put( side, peripheral );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2019-02-18 23:28:51 +00:00
|
|
|
|
|
|
|
// Always update the computer: it may not be the same computer as before!
|
|
|
|
serverComputer.setPeripheral( toDirection( side ), peripheral );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCommands()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( animation != TurtleAnimation.NONE || commandQueue.isEmpty() ) return;
|
2019-01-30 20:43:08 +00:00
|
|
|
|
2019-03-19 12:24:36 +00:00
|
|
|
// If we've got a computer, ensure that we're allowed to perform work.
|
2021-01-15 16:35:49 +00:00
|
|
|
ServerComputer computer = owner.getServerComputer();
|
2019-03-20 21:26:56 +00:00
|
|
|
if( computer != null && !computer.getComputer().getMainThreadMonitor().canWork() ) return;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-03-19 12:24:36 +00:00
|
|
|
// Pull a new command
|
2021-01-15 16:35:49 +00:00
|
|
|
TurtleCommandQueueEntry nextCommand = commandQueue.poll();
|
2019-03-19 12:24:36 +00:00
|
|
|
if( nextCommand == null ) return;
|
|
|
|
|
|
|
|
// Execute the command
|
|
|
|
long start = System.nanoTime();
|
|
|
|
TurtleCommandResult result = nextCommand.command.execute( this );
|
|
|
|
long end = System.nanoTime();
|
|
|
|
|
|
|
|
// Dispatch the callback
|
|
|
|
if( computer == null ) return;
|
2019-03-20 21:26:56 +00:00
|
|
|
computer.getComputer().getMainThreadMonitor().trackWork( end - start, TimeUnit.NANOSECONDS );
|
2019-03-19 12:24:36 +00:00
|
|
|
int callbackID = nextCommand.callbackID;
|
|
|
|
if( callbackID < 0 ) return;
|
|
|
|
|
|
|
|
if( result != null && result.isSuccess() )
|
|
|
|
{
|
|
|
|
Object[] results = result.getResults();
|
|
|
|
if( results != null )
|
|
|
|
{
|
|
|
|
Object[] arguments = new Object[results.length + 2];
|
|
|
|
arguments[0] = callbackID;
|
|
|
|
arguments[1] = true;
|
|
|
|
System.arraycopy( results, 0, arguments, 2, results.length );
|
|
|
|
computer.queueEvent( "turtle_response", arguments );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
computer.queueEvent( "turtle_response", new Object[] {
|
2019-06-07 23:28:03 +00:00
|
|
|
callbackID, true,
|
2019-03-19 12:24:36 +00:00
|
|
|
} );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-19 12:24:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
computer.queueEvent( "turtle_response", new Object[] {
|
2019-06-07 23:28:03 +00:00
|
|
|
callbackID, false, result != null ? result.getErrorMessage() : null,
|
2019-03-19 12:24:36 +00:00
|
|
|
} );
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAnimation()
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
if( animation != TurtleAnimation.NONE )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-03-29 21:21:39 +00:00
|
|
|
World world = getWorld();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
if( ComputerCraft.turtlesCanPush )
|
|
|
|
{
|
|
|
|
// Advance entity pushing
|
2021-01-15 16:35:49 +00:00
|
|
|
if( animation == TurtleAnimation.MOVE_FORWARD ||
|
|
|
|
animation == TurtleAnimation.MOVE_BACK ||
|
|
|
|
animation == TurtleAnimation.MOVE_UP ||
|
|
|
|
animation == TurtleAnimation.MOVE_DOWN )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
BlockPos pos = getPosition();
|
2019-06-08 12:36:31 +00:00
|
|
|
Direction moveDir;
|
2021-01-15 16:35:49 +00:00
|
|
|
switch( animation )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_FORWARD:
|
2017-05-01 13:32:39 +00:00
|
|
|
default:
|
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
|
|
|
moveDir = getDirection();
|
2017-05-01 13:32:39 +00:00
|
|
|
break;
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_BACK:
|
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
|
|
|
moveDir = getDirection().getOpposite();
|
2017-05-01 13:32:39 +00:00
|
|
|
break;
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_UP:
|
2019-06-08 12:36:31 +00:00
|
|
|
moveDir = Direction.UP;
|
2017-05-01 13:32:39 +00:00
|
|
|
break;
|
2020-01-28 22:28:48 +00:00
|
|
|
case MOVE_DOWN:
|
2019-06-08 12:36:31 +00:00
|
|
|
moveDir = Direction.DOWN;
|
2017-05-01 13:32:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
double minX = pos.getX();
|
|
|
|
double minY = pos.getY();
|
|
|
|
double minZ = pos.getZ();
|
|
|
|
double maxX = minX + 1.0;
|
|
|
|
double maxY = minY + 1.0;
|
|
|
|
double maxZ = minZ + 1.0;
|
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
float pushFrac = 1.0f - (float) (animationProgress + 1) / ANIM_DURATION;
|
2017-05-01 13:32:39 +00:00
|
|
|
float push = Math.max( pushFrac + 0.0125f, 0.0f );
|
2021-01-09 19:22:58 +00:00
|
|
|
if( moveDir.getStepX() < 0 )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
minX += moveDir.getStepX() * push;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
maxX -= moveDir.getStepX() * push;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
if( moveDir.getStepY() < 0 )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
minY += moveDir.getStepY() * push;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
maxY -= moveDir.getStepY() * push;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
if( moveDir.getStepZ() < 0 )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
minZ += moveDir.getStepZ() * push;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
maxZ -= moveDir.getStepZ() * push;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AxisAlignedBB aabb = new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ );
|
2021-01-09 19:22:58 +00:00
|
|
|
List<Entity> list = world.getEntitiesOfClass( Entity.class, aabb, EntityPredicates.NO_SPECTATORS );
|
2017-05-01 13:32:39 +00:00
|
|
|
if( !list.isEmpty() )
|
|
|
|
{
|
2017-09-24 05:18:20 +00:00
|
|
|
double pushStep = 1.0f / ANIM_DURATION;
|
2021-01-09 19:22:58 +00:00
|
|
|
double pushStepX = moveDir.getStepX() * pushStep;
|
|
|
|
double pushStepY = moveDir.getStepY() * pushStep;
|
|
|
|
double pushStepZ = moveDir.getStepZ() * pushStep;
|
2018-12-23 17:46:58 +00:00
|
|
|
for( Entity entity : list )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
entity.move( MoverType.PISTON, new Vec3d( pushStepX, pushStepY, pushStepZ ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Advance valentines day easter egg
|
2021-01-15 16:35:49 +00:00
|
|
|
if( world.isClientSide && animation == TurtleAnimation.MOVE_FORWARD && animationProgress == 4 )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Spawn love pfx if valentines day
|
|
|
|
Holiday currentHoliday = HolidayUtil.getCurrentHoliday();
|
2020-01-28 22:28:48 +00:00
|
|
|
if( currentHoliday == Holiday.VALENTINES )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 13:51:26 +00:00
|
|
|
Vec3d position = getVisualPosition( 1.0f );
|
2017-05-01 13:32:39 +00:00
|
|
|
if( position != null )
|
|
|
|
{
|
2021-01-09 19:22:58 +00:00
|
|
|
double x = position.x + world.random.nextGaussian() * 0.1;
|
|
|
|
double y = position.y + 0.5 + world.random.nextGaussian() * 0.1;
|
|
|
|
double z = position.z + world.random.nextGaussian() * 0.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
|
|
|
world.addParticle(
|
2019-06-08 12:36:31 +00:00
|
|
|
ParticleTypes.HEART, x, y, z,
|
2021-01-09 19:22:58 +00:00
|
|
|
world.random.nextGaussian() * 0.02,
|
|
|
|
world.random.nextGaussian() * 0.02,
|
|
|
|
world.random.nextGaussian() * 0.02
|
2017-05-01 13:32:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for anim completion
|
2021-01-15 16:35:49 +00:00
|
|
|
lastAnimationProgress = animationProgress;
|
|
|
|
if( ++animationProgress >= ANIM_DURATION )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
animation = TurtleAnimation.NONE;
|
|
|
|
animationProgress = 0;
|
|
|
|
lastAnimationProgress = 0;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private float getAnimationFraction( float f )
|
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
float next = (float) animationProgress / ANIM_DURATION;
|
|
|
|
float previous = (float) lastAnimationProgress / ANIM_DURATION;
|
2017-05-01 13:32:39 +00:00
|
|
|
return previous + (next - previous) * f;
|
|
|
|
}
|
Replace getMethodNames/callMethod with annotations (#447)
When creating a peripheral or custom Lua object, one must implement two
methods:
- getMethodNames(): String[] - Returns the name of the methods
- callMethod(int, ...): Object[] - Invokes the method using an index in
the above array.
This has a couple of problems:
- It's somewhat unwieldy to use - you need to keep track of array
indices, which leads to ugly code.
- Functions which yield (for instance, those which run on the main
thread) are blocking. This means we need to spawn new threads for
each CC-side yield.
We replace this system with a few changes:
- @LuaFunction annotation: One may annotate a public instance method
with this annotation. This then exposes a peripheral/lua object
method.
Furthermore, this method can accept and return a variety of types,
which often makes functions cleaner (e.g. can return an int rather
than an Object[], and specify and int argument rather than
Object[]).
- MethodResult: Instead of returning an Object[] and having blocking
yields, functions return a MethodResult. This either contains an
immediate return, or an instruction to yield with some continuation
to resume with.
MethodResult is then interpreted by the Lua runtime (i.e. Cobalt),
rather than our weird bodgey hacks before. This means we no longer
spawn new threads when yielding within CC.
- Methods accept IArguments instead of a raw Object array. This has a
few benefits:
- Consistent argument handling - people no longer need to use
ArgumentHelper (as it doesn't exist!), or even be aware of its
existence - you're rather forced into using it.
- More efficient code in some cases. We provide a Cobalt-specific
implementation of IArguments, which avoids the boxing/unboxing when
handling numbers and binary strings.
2020-05-15 12:21:16 +00:00
|
|
|
|
|
|
|
private static final class CommandCallback implements ILuaCallback
|
|
|
|
{
|
|
|
|
final MethodResult pull = MethodResult.pullEvent( "turtle_response", this );
|
|
|
|
private final int command;
|
|
|
|
|
|
|
|
CommandCallback( int command )
|
|
|
|
{
|
|
|
|
this.command = command;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public MethodResult resume( Object[] response )
|
|
|
|
{
|
|
|
|
if( response.length < 3 || !(response[1] instanceof Number) || !(response[2] instanceof Boolean) )
|
|
|
|
{
|
|
|
|
return pull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ((Number) response[1]).intValue() != command ) return pull;
|
|
|
|
|
|
|
|
return MethodResult.of( Arrays.copyOfRange( response, 2, response.length ) );
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|