diff --git a/patchwork.md b/patchwork.md index 46f21aa62..5d333f606 100644 --- a/patchwork.md +++ b/patchwork.md @@ -461,4 +461,43 @@ and Not sure what irritates me more ``` -both skipped because the changes where already ported. \ No newline at end of file +both skipped because the changes where already ported. + +``` +4ae370b9dbaf1de0ed32a5f32340b1448136c9cc + +Merge pull request #606 from TheWireLord/numpadenter-support +``` +Just lua changes. + +``` +f5eb6ce03e0d9bbbf77130452afd4b49e758f7bd + +Fix copy-paste error in inventory docs +``` +Skipped because it was already ported. + +``` +663859d2e5a97edefebf9ac36206903d7dd33a3e +Fix double URL decode +``` + +``` +abf425dfb5553483cdc51c50a6b7d8b5e44814f4 + +Fix overflow in os.epoch +``` + +``` +e3a672099c1b5d2c06f9fe4d8ccd024fef0873a2 + +Fix JEI integration with turtle/pocket upgrades +``` +Skipped because there seems to be no REI integration. + +``` +2f0cae0bc1b038ac092bafa7f65a317537203cd8 + +Make upgrade recipe requirements a little more lax +``` +Crafting is still messed up, but this port didn't change the behavior. diff --git a/src/main/java/dan200/computercraft/api/IUpgradeBase.java b/src/main/java/dan200/computercraft/api/IUpgradeBase.java new file mode 100644 index 000000000..c659ea5f5 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/IUpgradeBase.java @@ -0,0 +1,81 @@ +package dan200.computercraft.api; + +import dan200.computercraft.api.pocket.IPocketUpgrade; +import dan200.computercraft.api.turtle.ITurtleUpgrade; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Identifier; + +import javax.annotation.Nonnull; + +/** + * Common functionality between {@link ITurtleUpgrade} and {@link IPocketUpgrade}. + */ +public interface IUpgradeBase +{ + /** + * 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 upgrade will fail registration if an already used ID is specified. + * + * @return The unique ID for this upgrade. + */ + @Nonnull + Identifier getUpgradeID(); + + /** + * Return an unlocalised string to describe this type of computer in item names. + * + * Examples of built-in adjectives are "Wireless", "Mining" and "Crafty". + * + * @return The localisation key for this upgrade's adjective. + */ + @Nonnull + String getUnlocalisedAdjective(); + + /** + * Return an item stack representing the type of item that a computer must be crafted + * with to create a version which holds this upgrade. This item stack is also used + * to determine the upgrade given by {@code turtle.equipLeft()} or {@code pocket.equipBack()} + * + * This should be constant over a session (or at least a datapack reload). It is recommended + * that you cache the stack too, in order to prevent constructing it every time the method + * is called. + * + * @return The item stack to craft with, or {@link ItemStack#EMPTY} if it cannot be crafted. + */ + @Nonnull + ItemStack getCraftingItem(); + + /** + * Determine if an item is suitable for being used for this upgrade. + * + * When un-equipping an upgrade, we return {@link #getCraftingItem()} rather than + * the original stack. In order to prevent people losing items with enchantments (or + * repairing items with non-0 damage), we impose additional checks on the item. + * + * The default check requires that any non-capability NBT is exactly the same as the + * crafting item, but this may be relaxed for your upgrade. + * + * @param stack The stack to check. This is guaranteed to be non-empty and have the same item as + * {@link #getCraftingItem()}. + * @return If this stack may be used to equip this upgrade. + * @see net.minecraftforge.common.crafting.NBTIngredient#test(ItemStack) For the implementation of the default + * check. + */ + default boolean isItemSuitable( @Nonnull ItemStack stack ) + { + ItemStack crafting = getCraftingItem(); + + // A more expanded form of ItemStack.areShareTagsEqual, but allowing an empty tag to be equal to a + // null one. + CompoundTag shareTag = stack.getTag(); + CompoundTag craftingShareTag = crafting.getTag(); + if( shareTag == craftingShareTag ) return true; + if( shareTag == null ) return craftingShareTag.isEmpty(); + if( craftingShareTag == null ) return shareTag.isEmpty(); + return shareTag.equals( craftingShareTag ); + } +} diff --git a/src/main/java/dan200/computercraft/api/pocket/IPocketUpgrade.java b/src/main/java/dan200/computercraft/api/pocket/IPocketUpgrade.java index 150c0feb4..37fb9687a 100644 --- a/src/main/java/dan200/computercraft/api/pocket/IPocketUpgrade.java +++ b/src/main/java/dan200/computercraft/api/pocket/IPocketUpgrade.java @@ -10,56 +10,18 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import dan200.computercraft.api.ComputerCraftAPI; +import dan200.computercraft.api.IUpgradeBase; import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.api.turtle.ITurtleUpgrade; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; import net.minecraft.world.World; /** * Additional peripherals for pocket computers. * - * This is similar to {@link ITurtleUpgrade}. + * @see ComputerCraftAPI#registerPocketUpgrade(IPocketUpgrade) */ -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 upgrade will fail registration if an already used ID is - * specified. - * - * @return The upgrade's id. - * @see IPocketUpgrade#getUpgradeID() - * @see ComputerCraftAPI#registerPocketUpgrade(IPocketUpgrade) - */ - @Nonnull - Identifier getUpgradeID(); - - /** - * Return an unlocalised string to describe the type of pocket computer this upgrade provides. - * - * An example of a built-in adjectives is "Wireless" - this is converted to "Wireless Pocket Computer". - * - * @return The unlocalised adjective. - * @see ITurtleUpgrade#getUnlocalisedAdjective() - */ - @Nonnull - String getUnlocalisedAdjective(); - - /** - * Return an item stack representing the type of item that a pocket computer must be crafted with to create a pocket computer which holds this upgrade. - * This item stack is also used to determine the upgrade given by {@code pocket.equip()}/{@code pocket.unequip()}. - * - * 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. - * - * @return The item stack used for crafting. This can be {@link ItemStack#EMPTY} if crafting is disabled. - */ - @Nonnull - ItemStack getCraftingItem(); - +public interface IPocketUpgrade extends IUpgradeBase +{ /** * Creates a peripheral for the pocket computer. * diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java index 479b626e5..7048031b4 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -10,11 +10,10 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import dan200.computercraft.api.ComputerCraftAPI; +import dan200.computercraft.api.IUpgradeBase; import dan200.computercraft.api.client.TransformedModel; import dan200.computercraft.api.peripheral.IPeripheral; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; import net.minecraft.util.math.Direction; import net.fabricmc.api.EnvType; @@ -25,27 +24,8 @@ import net.fabricmc.api.Environment; * * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) */ -public interface ITurtleUpgrade { - /** - * 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 turtle will fail registration if an already used ID is specified. - * - * @return The unique ID for this upgrade. - * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) - */ - @Nonnull - Identifier getUpgradeID(); - - /** - * Return an unlocalised string to describe this type of turtle in turtle item names. - * - * Examples of built-in adjectives are "Wireless", "Mining" and "Crafty". - * - * @return The localisation key for this upgrade's adjective. - */ - @Nonnull - String getUnlocalisedAdjective(); - +public interface ITurtleUpgrade extends IUpgradeBase +{ /** * Return whether this turtle adds a tool or a peripheral to the turtle. * @@ -55,18 +35,6 @@ public interface ITurtleUpgrade { @Nonnull TurtleUpgradeType getType(); - /** - * 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 {@code turtle.equip()} - * - * 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. - * - * @return The item stack to craft with, or {@link ItemStack#EMPTY} if it cannot be crafted. - */ - @Nonnull - ItemStack getCraftingItem(); - /** * Will only be called for peripheral upgrades. Creates a peripheral for a turtle being placed using this upgrade. * diff --git a/src/main/java/dan200/computercraft/core/apis/OSAPI.java b/src/main/java/dan200/computercraft/core/apis/OSAPI.java index 5e26e9431..ae9ca3497 100644 --- a/src/main/java/dan200/computercraft/core/apis/OSAPI.java +++ b/src/main/java/dan200/computercraft/core/apis/OSAPI.java @@ -353,7 +353,7 @@ public class OSAPI implements ILuaAPI { case "ingame": // Get in-game epoch synchronized (this.m_alarms) { - return this.m_day * 86400000 + (int) (this.m_time * 3600000.0f); + return this.m_day * 86400000L + (long) (this.m_time * 3600000.0); } default: throw new LuaException("Unsupported operation"); diff --git a/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequestHandler.java b/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequestHandler.java index cbe577271..37e540c87 100644 --- a/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequestHandler.java +++ b/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequestHandler.java @@ -9,10 +9,8 @@ package dan200.computercraft.core.apis.http.request; import static dan200.computercraft.core.apis.http.request.HttpRequest.getHeaderSize; import java.io.Closeable; -import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URLDecoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.HashMap; @@ -228,8 +226,8 @@ public final class HttpRequestHandler extends SimpleChannelInboundHandler