2017-05-05 15:16:09 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
2019-01-01 01:10:18 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
|
2017-05-01 13:32:39 +00:00
|
|
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.api.turtle;
|
|
|
|
|
2017-05-05 13:56:15 +00:00
|
|
|
import dan200.computercraft.api.ComputerCraftAPI;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
2018-02-16 10:33:32 +00:00
|
|
|
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
|
|
|
|
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
|
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.client.renderer.model.IBakedModel;
|
|
|
|
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-02-16 10:33:32 +00:00
|
|
|
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
|
|
|
import net.minecraftforge.event.world.BlockEvent;
|
2017-05-01 13:32:39 +00:00
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
2017-05-01 13:32:39 +00:00
|
|
|
import javax.vecmath.Matrix4f;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The primary interface for defining an update for Turtles. A turtle update
|
|
|
|
* can either be a new tool, or a new peripheral.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
|
|
|
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
|
2017-05-01 13:32:39 +00:00
|
|
|
*/
|
|
|
|
public interface ITurtleUpgrade
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Gets a unique identifier representing this type of turtle upgrade. eg: "computercraft:wireless_modem" or "my_mod:my_upgrade".
|
|
|
|
* You should use a unique resource domain to ensure this upgrade is uniquely identified.
|
2017-05-01 13:32:39 +00:00
|
|
|
* The turtle will fail registration if an already used ID is specified.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
2017-05-05 15:07:18 +00:00
|
|
|
* @return The unique ID for this upgrade.
|
2017-05-05 13:56:15 +00:00
|
|
|
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
|
|
|
ResourceLocation getUpgradeID();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
/**
|
2017-05-05 13:56:15 +00:00
|
|
|
* Return an unlocalised string to describe this type of turtle in turtle item names.
|
|
|
|
*
|
2017-05-01 14:48:44 +00:00
|
|
|
* Examples of built-in adjectives are "Wireless", "Mining" and "Crafty".
|
2017-05-05 15:07:18 +00:00
|
|
|
*
|
|
|
|
* @return The localisation key for this upgrade's adjective.
|
2017-05-05 13:56:15 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
|
|
|
String getUnlocalisedAdjective();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Return whether this turtle adds a tool or a peripheral to the turtle.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
2017-05-05 15:07:18 +00:00
|
|
|
* @return The type of upgrade this is.
|
|
|
|
* @see TurtleUpgradeType for the differences between them.
|
2017-05-05 13:56:15 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
|
|
|
TurtleUpgradeType getType();
|
2017-05-05 13:56:15 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Return an item stack representing the type of item that a turtle must be crafted
|
|
|
|
* with to create a turtle which holds this upgrade. This item stack is also used
|
2017-05-05 13:56:15 +00:00
|
|
|
* to determine the upgrade given by {@code turtle.equip()}
|
2017-05-05 15:07:18 +00:00
|
|
|
*
|
2019-03-16 01:49:02 +00:00
|
|
|
* Ideally this should be constant over a session. It is recommended that you cache
|
|
|
|
* the item too, in order to prevent constructing it every time the method is called.
|
|
|
|
*
|
2017-05-11 00:08:26 +00:00
|
|
|
* @return The item stack to craft with, or {@link ItemStack#EMPTY} if it cannot be crafted.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
2017-05-11 00:08:26 +00:00
|
|
|
@Nonnull
|
2017-05-06 23:07:42 +00:00
|
|
|
ItemStack getCraftingItem();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
/**
|
2017-05-05 13:56:15 +00:00
|
|
|
* Will only be called for peripheral upgrades. Creates a peripheral for a turtle being placed using this upgrade.
|
|
|
|
*
|
|
|
|
* The peripheral created will be stored for the lifetime of the upgrade and will be passed as an argument to
|
|
|
|
* {@link #update(ITurtleAccess, TurtleSide)}. It will be attached, detached and have methods called in the same
|
|
|
|
* manner as a Computer peripheral.
|
2017-05-01 14:48:44 +00:00
|
|
|
*
|
2017-05-01 13:32:39 +00:00
|
|
|
* @param turtle Access to the turtle that the peripheral is being created for.
|
2017-05-05 13:56:15 +00:00
|
|
|
* @param side Which side of the turtle (left or right) that the upgrade resides on.
|
|
|
|
* @return The newly created peripheral. You may return {@code null} if this upgrade is a Tool
|
2017-05-01 14:48:44 +00:00
|
|
|
* and this method is not expected to be called.
|
2017-05-05 13:56:15 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nullable
|
2018-12-17 21:33:49 +00:00
|
|
|
default IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
|
|
|
|
* by the turtle, and the tool is required to do some work.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
2018-02-16 10:33:32 +00:00
|
|
|
* Conforming implementations should fire {@link BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig}for digging,
|
|
|
|
* {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking.
|
|
|
|
*
|
2017-05-05 13:56:15 +00:00
|
|
|
* @param turtle Access to the turtle that the tool resides on.
|
|
|
|
* @param side Which side of the turtle (left or right) the tool resides on.
|
|
|
|
* @param verb Which action (dig or attack) the turtle is being called on to perform.
|
2017-05-01 14:48:44 +00:00
|
|
|
* @param direction Which world direction the action should be performed in, relative to the turtles
|
2017-05-05 13:56:15 +00:00
|
|
|
* position. This will either be up, down, or the direction the turtle is facing, depending on
|
|
|
|
* whether dig, digUp or digDown was called.
|
|
|
|
* @return Whether the turtle was able to perform the action, and hence whether the {@code turtle.dig()}
|
|
|
|
* or {@code turtle.attack()} lua method should return true. If true is returned, the tool will perform
|
|
|
|
* a swinging animation. You may return {@code null} if this turtle is a Peripheral and this method is not expected
|
|
|
|
* to be called.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2018-12-17 21:33:49 +00:00
|
|
|
default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction )
|
|
|
|
{
|
|
|
|
return TurtleCommandResult.failure();
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to obtain the model to be used when rendering a turtle peripheral.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
|
|
|
* This can be obtained from {@link net.minecraft.client.renderer.ItemModelMesher#getItemModel(ItemStack)},
|
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
|
|
|
* {@link net.minecraft.client.renderer.model.ModelManager#getModel(ModelResourceLocation)} or any other
|
2017-05-05 13:56:15 +00:00
|
|
|
* source.
|
|
|
|
*
|
2017-05-01 13:32:39 +00:00
|
|
|
* @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models!
|
2017-05-05 13:56:15 +00:00
|
|
|
* @param side Which side of the turtle (left or right) the upgrade resides on.
|
|
|
|
* @return The model that you wish to be used to render your upgrade, and a transformation to apply to it. Returning
|
|
|
|
* a transformation of {@code null} has the same effect as the identify matrix.
|
2017-05-01 13:32:39 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
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
|
|
|
@OnlyIn( Dist.CLIENT )
|
2017-05-06 23:07:42 +00:00
|
|
|
Pair<IBakedModel, Matrix4f> getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called once per tick for each turtle which has the upgrade equipped.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
2017-05-01 13:32:39 +00:00
|
|
|
* @param turtle Access to the turtle that the upgrade resides on.
|
2017-05-05 13:56:15 +00:00
|
|
|
* @param side Which side of the turtle (left or right) the upgrade resides on.
|
2017-05-01 13:32:39 +00:00
|
|
|
*/
|
2017-06-12 20:08:35 +00:00
|
|
|
default void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
|
|
|
|
{
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|