1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-12 11:24:34 +00:00

Add registry for pocket computer upgrades

This commit is contained in:
SquidDev
2017-05-02 01:46:17 +01:00
parent ff16868dd8
commit 5faceac7ba
11 changed files with 567 additions and 109 deletions

View File

@@ -0,0 +1,65 @@
package dan200.computercraft.api.pocket;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;
/**
* Wrapper class for pocket computers
*/
public interface IPocketAccess
{
/**
* Gets the holding entity of this item
*
* @return The holding entity, may be {@code null}.
*/
@Nullable
Entity getEntity();
/**
* Get if the modem light is turned on
*
* @return If the modem light is turned on
*/
boolean getModemLight();
/**
* Turn on/off the modem light
*
* @param value If the light should be on
*/
void setModemLight( boolean value );
/**
* Get the upgrade specific NBT
*
* @return The upgrade's NBT
*/
@Nonnull
NBTTagCompound getUpgradeNBTData();
/**
* Mark the upgrade specific NBT as dirty
*/
void updateUpgradeNBTData();
/**
* Remove the current peripheral and create a new one. You
* may wish to do this if the methods available change.
*/
void invalidatePeripheral();
/**
* Get a list of all upgrades for the pocket computer
*
* @return A collection of all upgrade names
*/
@Nonnull
Map<ResourceLocation, IPeripheral> getUpgrades();
}

View File

@@ -0,0 +1,86 @@
package dan200.computercraft.api.pocket;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Additional peripherals for pocket computers.
* <p>
* This is similar to {@link dan200.computercraft.api.turtle.ITurtleUpgrade}.
*/
public interface IPocketUpgrade
{
/**
* 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.
* The peripheral will fail registration if an already used ID is specified.
*
* @return The id
* @see IPocketUpgrade#getUpgradeID()
* @see ComputerCraftAPI#registerPocketUpgrade(IPocketUpgrade)
*/
@Nonnull
ResourceLocation getUpgradeID();
/**
* Return a String to describe this type of turtle in turtle item names.
* An example of built-in adjectives is "Wireless".
*
* @return The unlocalised adjective
* @see ITurtleUpgrade#getUnlocalisedAdjective()
*/
@Nonnull
String getUnlocalisedAdjective();
/**
* 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
* to determine the upgrade given by turtle.equip()
*
* @return The item stack used for crafting. This can be {@code null} if crafting is disabled.
* @see ITurtleUpgrade#getCraftingItem()
*/
@Nullable
ItemStack getCraftingItem();
/**
* Creates a peripheral for the pocket computer.
* <p>
* The peripheral created will be stored for the lifetime of the upgrade, will have update() called
* once-per-tick, and will be attached, detached and have methods called in the same manner as a Computer peripheral.
*
* @param access The access object for the pocket item stack
* @return The newly created peripheral.
* @see ITurtleUpgrade#createPeripheral(ITurtleAccess, TurtleSide)
*/
@Nullable
IPeripheral createPeripheral( @Nonnull IPocketAccess access );
/**
* Called when the pocket computer item stack updates
*
* @param access The access object for the pocket item stack
* @param peripheral The peripheral for this upgrade
*/
void update( @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral );
/**
* Called when the pocket computer is right clicked on something
*
* @param world The world the computer is in
* @param access The access object for the pocket item stack
* @param peripheral The peripheral for this upgrade
* @return {@code true} to stop the gui from opening, otherwise false.
*/
boolean onRightClick( @Nonnull World world, @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral );
}