diff --git a/projects/common/src/client/java/dan200/computercraft/client/render/TurtleBlockEntityRenderer.java b/projects/common/src/client/java/dan200/computercraft/client/render/TurtleBlockEntityRenderer.java index 92fce737f..c52c5a485 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/render/TurtleBlockEntityRenderer.java +++ b/projects/common/src/client/java/dan200/computercraft/client/render/TurtleBlockEntityRenderer.java @@ -11,7 +11,6 @@ import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.client.platform.ClientPlatformHelper; import dan200.computercraft.client.turtle.TurtleUpgradeModellers; -import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity; import dan200.computercraft.shared.util.Holiday; import net.minecraft.client.Minecraft; @@ -21,7 +20,6 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; @@ -29,8 +27,6 @@ import net.minecraft.world.phys.HitResult; import javax.annotation.Nullable; public class TurtleBlockEntityRenderer implements BlockEntityRenderer { - private static final ModelResourceLocation NORMAL_TURTLE_MODEL = new ModelResourceLocation(ComputerCraftAPI.MOD_ID, "turtle_normal", "inventory"); - private static final ModelResourceLocation ADVANCED_TURTLE_MODEL = new ModelResourceLocation(ComputerCraftAPI.MOD_ID, "turtle_advanced", "inventory"); private static final ResourceLocation COLOUR_TURTLE_MODEL = new ResourceLocation(ComputerCraftAPI.MOD_ID, "block/turtle_colour"); private static final ResourceLocation ELF_OVERLAY_MODEL = new ResourceLocation(ComputerCraftAPI.MOD_ID, "block/turtle_elf_overlay"); @@ -42,13 +38,6 @@ public class TurtleBlockEntityRenderer implements BlockEntityRenderer coloured ? COLOUR_TURTLE_MODEL : NORMAL_TURTLE_MODEL; - case ADVANCED -> coloured ? COLOUR_TURTLE_MODEL : ADVANCED_TURTLE_MODEL; - }; - } - public static @Nullable ResourceLocation getTurtleOverlayModel(@Nullable ResourceLocation overlay, boolean christmas) { if (overlay != null) return overlay; if (christmas) return ELF_OVERLAY_MODEL; @@ -78,7 +67,6 @@ public class TurtleBlockEntityRenderer implements BlockEntityRenderer add) { for (var turtleItem : turtleItems()) { var base = turtleItem.create(-1, null, -1, null, null, 0, null); - - var nameId = turtleItem.getFamily().name().toLowerCase(Locale.ROOT); + var name = RegistryWrappers.ITEMS.getKey(turtleItem); for (var upgrade : turtleUpgrades.getGeneratedUpgrades()) { var result = turtleItem.create(-1, null, -1, null, UpgradeData.ofDefault(upgrade), -1, null); ShapedRecipeBuilder .shaped(RecipeCategory.REDSTONE, result.getItem()) - .group(String.format("%s:turtle_%s", ComputerCraftAPI.MOD_ID, nameId)) + .group(name.toString()) .pattern("#T") .define('T', base.getItem()) .define('#', upgrade.getCraftingItem().getItem()) @@ -121,9 +118,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { inventoryChange(base.getItem(), upgrade.getCraftingItem().getItem())) .save( RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPED.get(), add).withResultTag(result.getTag()), - new ResourceLocation(ComputerCraftAPI.MOD_ID, String.format("turtle_%s/%s/%s", - nameId, upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath() - )) + name.withSuffix(String.format("/%s/%s", upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath())) ); } } @@ -141,15 +136,13 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { private void pocketUpgrades(Consumer add) { for (var pocket : pocketComputerItems()) { var base = pocket.create(-1, null, -1, null); - if (base.isEmpty()) continue; - - var nameId = pocket.getFamily().name().toLowerCase(Locale.ROOT); + var name = RegistryWrappers.ITEMS.getKey(pocket).withPath(x -> x.replace("pocket_computer_", "pocket_")); for (var upgrade : pocketUpgrades.getGeneratedUpgrades()) { var result = pocket.create(-1, null, -1, UpgradeData.ofDefault(upgrade)); ShapedRecipeBuilder .shaped(RecipeCategory.REDSTONE, result.getItem()) - .group(String.format("%s:pocket_%s", ComputerCraftAPI.MOD_ID, nameId)) + .group(name.toString()) .pattern("#") .pattern("P") .define('P', base.getItem()) @@ -158,9 +151,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { inventoryChange(base.getItem(), upgrade.getCraftingItem().getItem())) .save( RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPED.get(), add).withResultTag(result.getTag()), - new ResourceLocation(ComputerCraftAPI.MOD_ID, String.format("pocket_%s/%s/%s", - nameId, upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath() - )) + name.withSuffix(String.format("/%s/%s", upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath())) ); } } @@ -190,12 +181,10 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { private void turtleOverlay(Consumer add, String overlay, Consumer build) { for (var turtleItem : turtleItems()) { var base = turtleItem.create(-1, null, -1, null, null, 0, null); - - var nameId = turtleItem.getFamily().name().toLowerCase(Locale.ROOT); - var group = "%s:turtle_%s_overlay".formatted(ComputerCraftAPI.MOD_ID, nameId); + var name = RegistryWrappers.ITEMS.getKey(turtleItem); var builder = ShapelessRecipeBuilder.shapeless(RecipeCategory.REDSTONE, base.getItem()) - .group(group) + .group(name.withSuffix("_overlay").toString()) .unlockedBy("has_turtle", inventoryChange(base.getItem())); build.accept(builder); builder @@ -204,7 +193,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { RecipeWrapper .wrap(ModRegistry.RecipeSerializers.TURTLE_OVERLAY.get(), add) .withExtraData(x -> x.addProperty("overlay", new ResourceLocation(ComputerCraftAPI.MOD_ID, "block/" + overlay).toString())), - new ResourceLocation(ComputerCraftAPI.MOD_ID, "turtle_%s_overlays/%s".formatted(nameId, overlay)) + name.withSuffix("_overlays/" + overlay) ); } } @@ -253,7 +242,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { .define('C', ModRegistry.Items.COMPUTER_NORMAL.get()) .unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.COMPUTER_NORMAL.get()), itemPredicate(ingredients.goldIngot()))) .save( - RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)), + RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add), new ResourceLocation(ComputerCraftAPI.MOD_ID, "computer_advanced_upgrade") ); @@ -277,7 +266,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { .define('C', ModRegistry.Items.COMPUTER_NORMAL.get()) .define('I', ingredients.woodenChest()) .unlockedBy("has_computer", inventoryChange(ModRegistry.Items.COMPUTER_NORMAL.get())) - .save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.TURTLE.get(), add).withExtraData(family(ComputerFamily.NORMAL))); + .save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.TURTLE.get(), add)); ShapedRecipeBuilder .shaped(RecipeCategory.REDSTONE, ModRegistry.Blocks.TURTLE_ADVANCED.get()) @@ -288,7 +277,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { .define('C', ModRegistry.Items.COMPUTER_ADVANCED.get()) .define('I', ingredients.woodenChest()) .unlockedBy("has_computer", inventoryChange(ModRegistry.Items.COMPUTER_NORMAL.get())) - .save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.TURTLE.get(), add).withExtraData(family(ComputerFamily.ADVANCED))); + .save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.TURTLE.get(), add)); ShapedRecipeBuilder .shaped(RecipeCategory.REDSTONE, ModRegistry.Blocks.TURTLE_ADVANCED.get()) @@ -300,7 +289,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { .define('B', ingredients.goldBlock()) .unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.TURTLE_NORMAL.get()), itemPredicate(ingredients.goldIngot()))) .save( - RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)), + RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add), new ResourceLocation(ComputerCraftAPI.MOD_ID, "turtle_advanced_upgrade") ); @@ -367,7 +356,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { .define('C', ModRegistry.Items.POCKET_COMPUTER_NORMAL.get()) .unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.POCKET_COMPUTER_NORMAL.get()), itemPredicate(ingredients.goldIngot()))) .save( - RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)), + RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add), new ResourceLocation(ComputerCraftAPI.MOD_ID, "pocket_computer_advanced_upgrade") ); @@ -519,10 +508,6 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider { return tag; } - private static Consumer family(ComputerFamily family) { - return json -> json.addProperty("family", family.getSerializedName()); - } - private static void addSpecial(Consumer add, SimpleCraftingRecipeSerializer special) { SpecialRecipeBuilder.special(special).save(add, RegistryWrappers.RECIPE_SERIALIZERS.getKey(special).toString()); } diff --git a/projects/common/src/main/java/dan200/computercraft/data/TagProvider.java b/projects/common/src/main/java/dan200/computercraft/data/TagProvider.java index 798e605d7..9b207e09d 100644 --- a/projects/common/src/main/java/dan200/computercraft/data/TagProvider.java +++ b/projects/common/src/main/java/dan200/computercraft/data/TagProvider.java @@ -79,6 +79,8 @@ class TagProvider { ModRegistry.Blocks.WIRED_MODEM_FULL.get(), ModRegistry.Blocks.CABLE.get() ); + + tags.tag(BlockTags.WITHER_IMMUNE).add(ModRegistry.Blocks.COMPUTER_COMMAND.get()); } public static void itemTags(ItemTagConsumer tags) { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/ModRegistry.java b/projects/common/src/main/java/dan200/computercraft/shared/ModRegistry.java index 1af983037..fab124915 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/ModRegistry.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/ModRegistry.java @@ -34,6 +34,7 @@ import dan200.computercraft.shared.computer.inventory.ViewComputerMenu; import dan200.computercraft.shared.computer.items.CommandComputerItem; import dan200.computercraft.shared.computer.items.ComputerItem; import dan200.computercraft.shared.computer.recipe.ComputerUpgradeRecipe; +import dan200.computercraft.shared.config.Config; import dan200.computercraft.shared.data.BlockNamedEntityLootCondition; import dan200.computercraft.shared.data.ConstantLootConditionSerializer; import dan200.computercraft.shared.data.HasComputerIdLootCondition; @@ -139,19 +140,17 @@ public final class ModRegistry { } public static final RegistryEntry> COMPUTER_NORMAL = REGISTRY.register("computer_normal", - () -> new ComputerBlock<>(computerProperties().mapColor(MapColor.STONE), ComputerFamily.NORMAL, BlockEntities.COMPUTER_NORMAL)); + () -> new ComputerBlock<>(computerProperties().mapColor(MapColor.STONE), BlockEntities.COMPUTER_NORMAL)); public static final RegistryEntry> COMPUTER_ADVANCED = REGISTRY.register("computer_advanced", - () -> new ComputerBlock<>(computerProperties().mapColor(MapColor.GOLD), ComputerFamily.ADVANCED, BlockEntities.COMPUTER_ADVANCED)); + () -> new ComputerBlock<>(computerProperties().mapColor(MapColor.GOLD), BlockEntities.COMPUTER_ADVANCED)); - public static final RegistryEntry> COMPUTER_COMMAND = REGISTRY.register("computer_command", () -> new CommandComputerBlock<>( - computerProperties().strength(-1, 6000000.0F), - ComputerFamily.COMMAND, BlockEntities.COMPUTER_COMMAND - )); + public static final RegistryEntry> COMPUTER_COMMAND = REGISTRY.register("computer_command", + () -> new CommandComputerBlock<>(computerProperties().strength(-1, 6000000.0F), BlockEntities.COMPUTER_COMMAND)); public static final RegistryEntry TURTLE_NORMAL = REGISTRY.register("turtle_normal", - () -> new TurtleBlock(turtleProperties().mapColor(MapColor.STONE), ComputerFamily.NORMAL, BlockEntities.TURTLE_NORMAL)); + () -> new TurtleBlock(turtleProperties().mapColor(MapColor.STONE), BlockEntities.TURTLE_NORMAL)); public static final RegistryEntry TURTLE_ADVANCED = REGISTRY.register("turtle_advanced", - () -> new TurtleBlock(turtleProperties().mapColor(MapColor.GOLD), ComputerFamily.ADVANCED, BlockEntities.TURTLE_ADVANCED)); + () -> new TurtleBlock(turtleProperties().mapColor(MapColor.GOLD).explosionResistance(TurtleBlock.IMMUNE_EXPLOSION_RESISTANCE), BlockEntities.TURTLE_ADVANCED)); public static final RegistryEntry SPEAKER = REGISTRY.register("speaker", () -> new SpeakerBlock(properties().mapColor(MapColor.STONE))); public static final RegistryEntry DISK_DRIVE = REGISTRY.register("disk_drive", () -> new DiskDriveBlock(properties().mapColor(MapColor.STONE))); @@ -192,9 +191,9 @@ public final class ModRegistry { ofBlock(Blocks.COMPUTER_COMMAND, (p, s) -> new CommandComputerBlockEntity(BlockEntities.COMPUTER_COMMAND.get(), p, s)); public static final RegistryEntry> TURTLE_NORMAL = - ofBlock(Blocks.TURTLE_NORMAL, (p, s) -> new TurtleBlockEntity(BlockEntities.TURTLE_NORMAL.get(), p, s, ComputerFamily.NORMAL)); + ofBlock(Blocks.TURTLE_NORMAL, (p, s) -> new TurtleBlockEntity(BlockEntities.TURTLE_NORMAL.get(), p, s, () -> Config.turtleFuelLimit, ComputerFamily.NORMAL)); public static final RegistryEntry> TURTLE_ADVANCED = - ofBlock(Blocks.TURTLE_ADVANCED, (p, s) -> new TurtleBlockEntity(BlockEntities.TURTLE_ADVANCED.get(), p, s, ComputerFamily.ADVANCED)); + ofBlock(Blocks.TURTLE_ADVANCED, (p, s) -> new TurtleBlockEntity(BlockEntities.TURTLE_ADVANCED.get(), p, s, () -> Config.advancedTurtleFuelLimit, ComputerFamily.ADVANCED)); public static final RegistryEntry> SPEAKER = ofBlock(Blocks.SPEAKER, (p, s) -> new SpeakerBlockEntity(BlockEntities.SPEAKER.get(), p, s)); @@ -311,7 +310,10 @@ public final class ModRegistry { () -> new MenuType<>(PrinterMenu::new, FeatureFlags.VANILLA_SET)); public static final RegistryEntry> PRINTOUT = REGISTRY.register("printout", - () -> ContainerData.toType(HeldItemContainerData::new, HeldItemMenu::createPrintout)); + () -> ContainerData.toType( + HeldItemContainerData::new, + (id, inventory, data) -> new HeldItemMenu(Menus.PRINTOUT.get(), id, inventory.player, data.getHand()) + )); public static final RegistryEntry> VIEW_COMPUTER = REGISTRY.register("view_computer", () -> ContainerData.toType(ComputerContainerData::new, ViewComputerMenu::new)); @@ -371,11 +373,11 @@ public final class ModRegistry { public static final RegistryEntry> DYEABLE_ITEM_CLEAR = simple("clear_colour", ClearColourRecipe::new); public static final RegistryEntry> TURTLE = REGISTRY.register("turtle", () -> TurtleRecipe.validatingSerialiser(TurtleRecipe::of)); public static final RegistryEntry> TURTLE_UPGRADE = simple("turtle_upgrade", TurtleUpgradeRecipe::new); - public static final RegistryEntry> TURTLE_OVERLAY = REGISTRY.register("turtle_overlay", TurtleOverlayRecipe.Serializer::new); + public static final RegistryEntry> TURTLE_OVERLAY = REGISTRY.register("turtle_overlay", TurtleOverlayRecipe.Serialiser::new); public static final RegistryEntry> POCKET_COMPUTER_UPGRADE = simple("pocket_computer_upgrade", PocketComputerUpgradeRecipe::new); public static final RegistryEntry> PRINTOUT = simple("printout", PrintoutRecipe::new); public static final RegistryEntry> DISK = simple("disk", DiskRecipe::new); - public static final RegistryEntry> COMPUTER_UPGRADE = REGISTRY.register("computer_upgrade", ComputerUpgradeRecipe.Serializer::new); + public static final RegistryEntry> COMPUTER_UPGRADE = REGISTRY.register("computer_upgrade", () -> CustomShapedRecipe.validatingSerialiser(ComputerUpgradeRecipe::of)); } public static class Permissions { @@ -464,8 +466,8 @@ public final class ModRegistry { * Register any objects which must be done on the main thread. */ public static void registerMainThread() { - CauldronInteraction.WATER.put(ModRegistry.Items.TURTLE_NORMAL.get(), TurtleItem.CAULDRON_INTERACTION); - CauldronInteraction.WATER.put(ModRegistry.Items.TURTLE_ADVANCED.get(), TurtleItem.CAULDRON_INTERACTION); + CauldronInteraction.WATER.put(Items.TURTLE_NORMAL.get(), TurtleItem.CAULDRON_INTERACTION); + CauldronInteraction.WATER.put(Items.TURTLE_ADVANCED.get(), TurtleItem.CAULDRON_INTERACTION); } private static void addTurtle(CreativeModeTab.Output out, TurtleItem turtle) { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/common/HeldItemMenu.java b/projects/common/src/main/java/dan200/computercraft/shared/common/HeldItemMenu.java index bd256a8d4..7a4c5895d 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/common/HeldItemMenu.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/common/HeldItemMenu.java @@ -4,8 +4,6 @@ package dan200.computercraft.shared.common; -import dan200.computercraft.shared.ModRegistry; -import dan200.computercraft.shared.network.container.HeldItemContainerData; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.MenuProvider; @@ -28,10 +26,6 @@ public class HeldItemMenu extends AbstractContainerMenu { stack = player.getItemInHand(hand).copy(); } - public static HeldItemMenu createPrintout(int id, Inventory inventory, HeldItemContainerData data) { - return new HeldItemMenu(ModRegistry.Menus.PRINTOUT.get(), id, inventory.player, data.getHand()); - } - public ItemStack getStack() { return stack; } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/AbstractComputerBlock.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/AbstractComputerBlock.java index 9438da0e0..2bd6f00f4 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/AbstractComputerBlock.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/AbstractComputerBlock.java @@ -7,7 +7,6 @@ package dan200.computercraft.shared.computer.blocks; import dan200.computercraft.annotations.ForgeOverride; import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.shared.common.IBundledRedstoneBlock; -import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.platform.RegistryEntry; import dan200.computercraft.shared.util.BlockEntityHelpers; @@ -42,13 +41,11 @@ import javax.annotation.Nullable; public abstract class AbstractComputerBlock extends HorizontalDirectionalBlock implements IBundledRedstoneBlock, EntityBlock { private static final ResourceLocation DROP = new ResourceLocation(ComputerCraftAPI.MOD_ID, "computer"); - private final ComputerFamily family; protected final RegistryEntry> type; private final BlockEntityTicker serverTicker = (level, pos, state, computer) -> computer.serverTick(); - protected AbstractComputerBlock(Properties settings, ComputerFamily family, RegistryEntry> type) { + protected AbstractComputerBlock(Properties settings, RegistryEntry> type) { super(settings); - this.family = family; this.type = type; } @@ -82,10 +79,6 @@ public abstract class AbstractComputerBlock extends ComputerBlock implements GameMasterBlock { - public CommandComputerBlock(Properties settings, ComputerFamily family, RegistryEntry> type) { - super(settings, family, type); + public CommandComputerBlock(Properties settings, RegistryEntry> type) { + super(settings, type); } } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerBlock.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerBlock.java index ba22baf20..44a3e85f4 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerBlock.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerBlock.java @@ -4,9 +4,8 @@ package dan200.computercraft.shared.computer.blocks; -import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerState; -import dan200.computercraft.shared.computer.items.ComputerItemFactory; +import dan200.computercraft.shared.computer.items.ComputerItem; import dan200.computercraft.shared.platform.RegistryEntry; import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; @@ -25,8 +24,8 @@ public class ComputerBlock extends AbstractComput public static final EnumProperty STATE = EnumProperty.create("state", ComputerState.class); public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; - public ComputerBlock(Properties settings, ComputerFamily family, RegistryEntry> type) { - super(settings, family, type); + public ComputerBlock(Properties settings, RegistryEntry> type) { + super(settings, type); registerDefaultState(defaultBlockState() .setValue(FACING, Direction.NORTH) .setValue(STATE, ComputerState.OFF) @@ -46,6 +45,9 @@ public class ComputerBlock extends AbstractComput @Override protected ItemStack getItem(AbstractComputerBlockEntity tile) { - return tile instanceof ComputerBlockEntity ? ComputerItemFactory.create((ComputerBlockEntity) tile) : ItemStack.EMPTY; + if (!(tile instanceof ComputerBlockEntity computer)) return ItemStack.EMPTY; + if (!(asItem() instanceof ComputerItem item)) return ItemStack.EMPTY; + + return item.create(computer.getComputerID(), computer.getLabel()); } } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerBlockEntity.java index 598841758..6aee79628 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerBlockEntity.java @@ -32,11 +32,9 @@ public class ComputerBlockEntity extends AbstractComputerBlockEntity { @Override protected ServerComputer createComputer(int id) { - var family = getFamily(); return new ServerComputer( (ServerLevel) getLevel(), getBlockPos(), id, label, - family, Config.computerTermWidth, - Config.computerTermHeight + getFamily(), Config.computerTermWidth, Config.computerTermHeight ); } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ComputerFamily.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ComputerFamily.java index da1b912c2..491fb0a5f 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ComputerFamily.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ComputerFamily.java @@ -4,33 +4,8 @@ package dan200.computercraft.shared.computer.core; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; -import net.minecraft.util.GsonHelper; -import net.minecraft.util.StringRepresentable; - -public enum ComputerFamily implements StringRepresentable { - NORMAL("normal"), - ADVANCED("advanced"), - COMMAND("command"); - - private final String name; - - ComputerFamily(String name) { - this.name = name; - } - - public static ComputerFamily getFamily(JsonObject json, String name) { - var familyName = GsonHelper.getAsString(json, name); - for (var family : values()) { - if (family.getSerializedName().equalsIgnoreCase(familyName)) return family; - } - - throw new JsonSyntaxException("Unknown computer family '" + familyName + "' for field " + name); - } - - @Override - public String getSerializedName() { - return name; - } +public enum ComputerFamily { + NORMAL, + ADVANCED, + COMMAND, } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/items/AbstractComputerItem.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/items/AbstractComputerItem.java index 5c40474de..f9499e7dc 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/items/AbstractComputerItem.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/items/AbstractComputerItem.java @@ -8,7 +8,6 @@ import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.filesystem.Mount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.computer.blocks.AbstractComputerBlock; -import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.config.Config; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; @@ -22,11 +21,8 @@ import javax.annotation.Nullable; import java.util.List; public abstract class AbstractComputerItem extends BlockItem implements IComputerItem, IMedia { - private final ComputerFamily family; - public AbstractComputerItem(AbstractComputerBlock block, Properties settings) { super(block, settings); - family = block.getFamily(); } @Override @@ -45,13 +41,6 @@ public abstract class AbstractComputerItem extends BlockItem implements ICompute return IComputerItem.super.getLabel(stack); } - @Override - public final ComputerFamily getFamily() { - return family; - } - - // IMedia implementation - @Override public boolean setLabel(ItemStack stack, @Nullable String label) { if (label != null) { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/items/ComputerItem.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/items/ComputerItem.java index 350d11c9b..56170e454 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/items/ComputerItem.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/items/ComputerItem.java @@ -5,8 +5,8 @@ package dan200.computercraft.shared.computer.items; import dan200.computercraft.shared.computer.blocks.ComputerBlock; -import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.network.chat.Component; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import javax.annotation.Nullable; @@ -24,9 +24,9 @@ public class ComputerItem extends AbstractComputerItem { } @Override - public ItemStack withFamily(ItemStack stack, ComputerFamily family) { - var result = ComputerItemFactory.create(getComputerID(stack), null, family); - if (stack.hasCustomHoverName()) result.setHoverName(stack.getHoverName()); - return result; + public ItemStack changeItem(ItemStack stack, Item newItem) { + return newItem instanceof ComputerItem computer + ? computer.create(getComputerID(stack), getLabel(stack)) + : ItemStack.EMPTY; } } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/items/ComputerItemFactory.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/items/ComputerItemFactory.java deleted file mode 100644 index 127b47903..000000000 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/items/ComputerItemFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission. -// -// SPDX-License-Identifier: LicenseRef-CCPL - -package dan200.computercraft.shared.computer.items; - -import dan200.computercraft.shared.ModRegistry; -import dan200.computercraft.shared.computer.blocks.ComputerBlockEntity; -import dan200.computercraft.shared.computer.core.ComputerFamily; -import net.minecraft.world.item.ItemStack; - -import javax.annotation.Nullable; - -public final class ComputerItemFactory { - private ComputerItemFactory() { - } - - public static ItemStack create(ComputerBlockEntity tile) { - return create(tile.getComputerID(), tile.getLabel(), tile.getFamily()); - } - - public static ItemStack create(int id, @Nullable String label, ComputerFamily family) { - return switch (family) { - case NORMAL -> ModRegistry.Items.COMPUTER_NORMAL.get().create(id, label); - case ADVANCED -> ModRegistry.Items.COMPUTER_ADVANCED.get().create(id, label); - case COMMAND -> ModRegistry.Items.COMPUTER_COMMAND.get().create(id, label); - }; - } -} diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java index c88b93916..03bcb762e 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java @@ -4,7 +4,7 @@ package dan200.computercraft.shared.computer.items; -import dan200.computercraft.shared.computer.core.ComputerFamily; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import javax.annotation.Nullable; @@ -21,7 +21,15 @@ public interface IComputerItem { return stack.hasCustomHoverName() ? stack.getHoverName().getString() : null; } - ComputerFamily getFamily(); - - ItemStack withFamily(ItemStack stack, ComputerFamily family); + /** + * Create a new stack, changing the underlying item. + *

+ * This should copy the computer's data to a different item of the same type (for instance, converting a normal + * computer to an advanced one). + * + * @param stack The current computer stack. + * @param newItem The new item. + * @return The new stack, possibly {@linkplain ItemStack#EMPTY empty} if {@code newItem} is of the same type. + */ + ItemStack changeItem(ItemStack stack, Item newItem); } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java index 075695752..cec37135e 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java @@ -4,57 +4,44 @@ package dan200.computercraft.shared.computer.recipe; -import com.google.gson.JsonObject; +import com.mojang.serialization.DataResult; import dan200.computercraft.shared.ModRegistry; -import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.recipe.ShapedRecipeSpec; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeSerializer; /** - * A recipe which "upgrades" a {@linkplain IComputerItem computer}, converting it from one {@linkplain ComputerFamily - * family} to another. + * A recipe which "upgrades" a {@linkplain IComputerItem computer}, converting to it a new item (for instance a normal + * turtle to an advanced one). + * + * @see IComputerItem#changeItem(ItemStack, Item) */ public final class ComputerUpgradeRecipe extends ComputerConvertRecipe { - private final ComputerFamily family; + private final Item result; - private ComputerUpgradeRecipe(ResourceLocation identifier, ShapedRecipeSpec recipe, ComputerFamily family) { + private ComputerUpgradeRecipe(ResourceLocation identifier, ShapedRecipeSpec recipe) { super(identifier, recipe); - this.family = family; + this.result = recipe.result().getItem(); + } + + public static DataResult of(ResourceLocation id, ShapedRecipeSpec recipe) { + if (!(recipe.result().getItem() instanceof IComputerItem)) { + return DataResult.error(() -> recipe.result().getItem() + " is not a computer item"); + } + + return DataResult.success(new ComputerUpgradeRecipe(id, recipe)); } @Override protected ItemStack convert(IComputerItem item, ItemStack stack) { - return item.withFamily(stack, family); + return item.changeItem(stack, result); } @Override public RecipeSerializer getSerializer() { return ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(); } - - public static class Serializer implements RecipeSerializer { - @Override - public ComputerUpgradeRecipe fromJson(ResourceLocation identifier, JsonObject json) { - var recipe = ShapedRecipeSpec.fromJson(json); - var family = ComputerFamily.getFamily(json, "family"); - return new ComputerUpgradeRecipe(identifier, recipe, family); - } - - @Override - public ComputerUpgradeRecipe fromNetwork(ResourceLocation identifier, FriendlyByteBuf buf) { - var recipe = ShapedRecipeSpec.fromNetwork(buf); - var family = buf.readEnum(ComputerFamily.class); - return new ComputerUpgradeRecipe(identifier, recipe, family); - } - - @Override - public void toNetwork(FriendlyByteBuf buf, ComputerUpgradeRecipe recipe) { - recipe.toSpec().toNetwork(buf); - buf.writeEnum(recipe.family); - } - } } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItem.java b/projects/common/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItem.java index c35265e42..c3e731ca3 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItem.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItem.java @@ -12,7 +12,6 @@ import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.upgrades.UpgradeData; import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.impl.PocketUpgrades; -import dan200.computercraft.shared.ModRegistry; import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerContext; @@ -60,14 +59,6 @@ public class PocketComputerItem extends Item implements IComputerItem, IMedia, I this.family = family; } - public static ItemStack create(int id, @Nullable String label, int colour, ComputerFamily family, @Nullable UpgradeData upgrade) { - return switch (family) { - case NORMAL -> ModRegistry.Items.POCKET_COMPUTER_NORMAL.get().create(id, label, colour, upgrade); - case ADVANCED -> ModRegistry.Items.POCKET_COMPUTER_ADVANCED.get().create(id, label, colour, upgrade); - default -> ItemStack.EMPTY; - }; - } - public ItemStack create(int id, @Nullable String label, int colour, @Nullable UpgradeData upgrade) { var result = new ItemStack(this); if (id >= 0) result.getOrCreateTag().putInt(NBT_ID, id); @@ -243,17 +234,16 @@ public class PocketComputerItem extends Item implements IComputerItem, IMedia, I return IComputerItem.super.getLabel(stack); } - @Override public ComputerFamily getFamily() { return family; } @Override - public ItemStack withFamily(ItemStack stack, ComputerFamily family) { - return create( + public ItemStack changeItem(ItemStack stack, Item newItem) { + return newItem instanceof PocketComputerItem pocket ? pocket.create( getComputerID(stack), getLabel(stack), getColour(stack), - family, getUpgradeWithData(stack) - ); + getUpgradeWithData(stack) + ) : ItemStack.EMPTY; } // IMedia diff --git a/projects/common/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java b/projects/common/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java index b0b25bd87..bf55800a2 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java @@ -81,7 +81,6 @@ public final class PocketComputerUpgradeRecipe extends CustomRecipe { if (upgrade == null) return ItemStack.EMPTY; // Construct the new stack - var family = itemComputer.getFamily(); var computerID = itemComputer.getComputerID(computer); var label = itemComputer.getLabel(computer); var colour = itemComputer.getColour(computer); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlock.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlock.java index 157bb876b..e2b01fa73 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlock.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlock.java @@ -10,7 +10,6 @@ import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.upgrades.UpgradeData; import dan200.computercraft.shared.computer.blocks.AbstractComputerBlock; import dan200.computercraft.shared.computer.blocks.AbstractComputerBlockEntity; -import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.platform.RegistryEntry; import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.items.TurtleItem; @@ -52,6 +51,16 @@ import static dan200.computercraft.shared.util.WaterloggableHelpers.getFluidStat public class TurtleBlock extends AbstractComputerBlock implements SimpleWaterloggedBlock { public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; + /** + * The explosion resistance to use when a turtle is "immune" to explosions. + *

+ * This is used as the default explosion resistance for advanced turtles, and the resistance for entity-based + * explosions (e.g. creepers). + * + * @see #getExplosionResistance(BlockState, BlockGetter, BlockPos, Explosion) + */ + public static final float IMMUNE_EXPLOSION_RESISTANCE = 2000f; + private static final VoxelShape DEFAULT_SHAPE = Shapes.box( 0.125, 0.125, 0.125, 0.875, 0.875, 0.875 @@ -59,8 +68,8 @@ public class TurtleBlock extends AbstractComputerBlock implem private final BlockEntityTicker clientTicker = (level, pos, state, computer) -> computer.clientTick(); - public TurtleBlock(Properties settings, ComputerFamily family, RegistryEntry> type) { - super(settings, family, type); + public TurtleBlock(Properties settings, RegistryEntry> type) { + super(settings, type); registerDefaultState(getStateDefinition().any() .setValue(FACING, Direction.NORTH) .setValue(WATERLOGGED, false) @@ -149,20 +158,21 @@ public class TurtleBlock extends AbstractComputerBlock implem @ForgeOverride public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) { var exploder = explosion.getDirectSourceEntity(); - if (getFamily() == ComputerFamily.ADVANCED || exploder instanceof LivingEntity || exploder instanceof AbstractHurtingProjectile) { - return 2000; + if (exploder instanceof LivingEntity || exploder instanceof AbstractHurtingProjectile) { + return IMMUNE_EXPLOSION_RESISTANCE; } - return explosionResistance; + return getExplosionResistance(); } @Override protected ItemStack getItem(AbstractComputerBlockEntity tile) { if (!(tile instanceof TurtleBlockEntity turtle)) return ItemStack.EMPTY; + if (!(asItem() instanceof TurtleItem item)) return ItemStack.EMPTY; var access = turtle.getAccess(); - return TurtleItem.create( - turtle.getComputerID(), turtle.getLabel(), access.getColour(), turtle.getFamily(), + return item.create( + turtle.getComputerID(), turtle.getLabel(), access.getColour(), withPersistedData(access.getUpgradeWithData(TurtleSide.LEFT)), withPersistedData(access.getUpgradeWithData(TurtleSide.RIGHT)), access.getFuelLevel(), turtle.getOverlay() diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlockEntity.java index e5c9e2f00..87595824b 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlockEntity.java @@ -38,6 +38,7 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nullable; import java.util.Collections; +import java.util.function.IntSupplier; public class TurtleBlockEntity extends AbstractComputerBlockEntity implements BasicContainer { public static final int INVENTORY_SIZE = 16; @@ -53,13 +54,17 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba private final NonNullList inventory = NonNullList.withSize(INVENTORY_SIZE, ItemStack.EMPTY); private final NonNullList inventorySnapshot = NonNullList.withSize(INVENTORY_SIZE, ItemStack.EMPTY); private boolean inventoryChanged = false; + + private final IntSupplier fuelLimit; + private TurtleBrain brain = new TurtleBrain(this); private MoveState moveState = MoveState.NOT_MOVED; private @Nullable IPeripheral peripheral; private @Nullable Runnable onMoved; - public TurtleBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, ComputerFamily family) { + public TurtleBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, IntSupplier fuelLimit, ComputerFamily family) { super(type, pos, state, family); + this.fuelLimit = fuelLimit; } boolean hasMoved() { @@ -172,8 +177,6 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba return hasPeripheralUpgradeOnSide(localSide); } - // IDirectionalTile - @Override public Direction getDirection() { return getBlockState().getValue(TurtleBlock.FACING); @@ -272,6 +275,10 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba // Privates + public int getFuelLimit() { + return fuelLimit.getAsInt(); + } + private boolean hasPeripheralUpgradeOnSide(ComputerSide side) { ITurtleUpgrade upgrade; switch (side) { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index 1b5728ed2..e399096bf 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -395,11 +395,7 @@ public class TurtleBrain implements TurtleAccessInternal { @Override public int getFuelLimit() { - if (owner.getFamily() == ComputerFamily.ADVANCED) { - return Config.advancedTurtleFuelLimit; - } else { - return Config.turtleFuelLimit; - } + return owner.getFuelLimit(); } @Override diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItem.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItem.java index 640872b23..4b5994900 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItem.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItem.java @@ -10,9 +10,7 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.upgrades.UpgradeData; import dan200.computercraft.impl.TurtleUpgrades; -import dan200.computercraft.shared.ModRegistry; import dan200.computercraft.shared.common.IColouredItem; -import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.items.AbstractComputerItem; import dan200.computercraft.shared.turtle.blocks.TurtleBlock; import dan200.computercraft.shared.util.NBTUtil; @@ -20,6 +18,7 @@ import net.minecraft.core.cauldron.CauldronInteraction; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.LayeredCauldronBlock; @@ -32,20 +31,6 @@ public class TurtleItem extends AbstractComputerItem implements IColouredItem { super(block, settings); } - public static ItemStack create( - int id, @Nullable String label, int colour, ComputerFamily family, - @Nullable UpgradeData leftUpgrade, @Nullable UpgradeData rightUpgrade, - int fuelLevel, @Nullable ResourceLocation overlay - ) { - return switch (family) { - case NORMAL -> - ModRegistry.Items.TURTLE_NORMAL.get().create(id, label, colour, leftUpgrade, rightUpgrade, fuelLevel, overlay); - case ADVANCED -> - ModRegistry.Items.TURTLE_ADVANCED.get().create(id, label, colour, leftUpgrade, rightUpgrade, fuelLevel, overlay); - default -> ItemStack.EMPTY; - }; - } - public ItemStack create( int id, @Nullable String label, int colour, @Nullable UpgradeData leftUpgrade, @Nullable UpgradeData rightUpgrade, @@ -119,13 +104,13 @@ public class TurtleItem extends AbstractComputerItem implements IColouredItem { } @Override - public ItemStack withFamily(ItemStack stack, ComputerFamily family) { - return create( + public ItemStack changeItem(ItemStack stack, Item newItem) { + return newItem instanceof TurtleItem turtle ? turtle.create( getComputerID(stack), getLabel(stack), - getColour(stack), family, + getColour(stack), getUpgradeWithData(stack, TurtleSide.LEFT), getUpgradeWithData(stack, TurtleSide.RIGHT), getFuelLevel(stack), getOverlay(stack) - ); + ) : ItemStack.EMPTY; } public @Nullable ITurtleUpgrade getUpgrade(ItemStack stack, TurtleSide side) { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleOverlayRecipe.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleOverlayRecipe.java index 57609c1ce..65d6ee1b2 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleOverlayRecipe.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleOverlayRecipe.java @@ -58,7 +58,7 @@ public class TurtleOverlayRecipe extends CustomShapelessRecipe { return ModRegistry.RecipeSerializers.TURTLE_OVERLAY.get(); } - public static class Serializer implements RecipeSerializer { + public static class Serialiser implements RecipeSerializer { @Override public TurtleOverlayRecipe fromJson(ResourceLocation id, JsonObject json) { var recipe = ShapelessRecipeSpec.fromJson(json); diff --git a/projects/fabric/src/generated/resources/data/computercraft/recipes/computer_advanced_upgrade.json b/projects/fabric/src/generated/resources/data/computercraft/recipes/computer_advanced_upgrade.json index ccbc87c2c..03289f803 100644 --- a/projects/fabric/src/generated/resources/data/computercraft/recipes/computer_advanced_upgrade.json +++ b/projects/fabric/src/generated/resources/data/computercraft/recipes/computer_advanced_upgrade.json @@ -1,7 +1,6 @@ { "type": "computercraft:computer_upgrade", "category": "redstone", - "family": "advanced", "key": {"#": {"tag": "c:gold_ingots"}, "C": {"item": "computercraft:computer_normal"}}, "pattern": ["###", "#C#", "# #"], "result": {"item": "computercraft:computer_advanced"}, diff --git a/projects/fabric/src/generated/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json b/projects/fabric/src/generated/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json index ac2f5a9b7..765944e32 100644 --- a/projects/fabric/src/generated/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json +++ b/projects/fabric/src/generated/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json @@ -1,7 +1,6 @@ { "type": "computercraft:computer_upgrade", "category": "redstone", - "family": "advanced", "key": {"#": {"tag": "c:gold_ingots"}, "C": {"item": "computercraft:pocket_computer_normal"}}, "pattern": ["###", "#C#", "# #"], "result": {"item": "computercraft:pocket_computer_advanced"}, diff --git a/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_advanced.json b/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_advanced.json index 367b93bc2..a720038df 100644 --- a/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_advanced.json +++ b/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_advanced.json @@ -1,7 +1,6 @@ { "type": "computercraft:turtle", "category": "redstone", - "family": "advanced", "key": { "#": {"tag": "c:gold_ingots"}, "C": {"item": "computercraft:computer_advanced"}, diff --git a/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_advanced_upgrade.json b/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_advanced_upgrade.json index 155297a1f..6a50ccec9 100644 --- a/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_advanced_upgrade.json +++ b/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_advanced_upgrade.json @@ -1,7 +1,6 @@ { "type": "computercraft:computer_upgrade", "category": "redstone", - "family": "advanced", "key": { "#": {"tag": "c:gold_ingots"}, "B": {"item": "minecraft:gold_block"}, diff --git a/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_normal.json b/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_normal.json index eb35293ca..09f79a331 100644 --- a/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_normal.json +++ b/projects/fabric/src/generated/resources/data/computercraft/recipes/turtle_normal.json @@ -1,7 +1,6 @@ { "type": "computercraft:turtle", "category": "redstone", - "family": "normal", "key": { "#": {"tag": "c:iron_ingots"}, "C": {"item": "computercraft:computer_normal"}, diff --git a/projects/fabric/src/generated/resources/data/minecraft/tags/blocks/wither_immune.json b/projects/fabric/src/generated/resources/data/minecraft/tags/blocks/wither_immune.json new file mode 100644 index 000000000..acf2c81ae --- /dev/null +++ b/projects/fabric/src/generated/resources/data/minecraft/tags/blocks/wither_immune.json @@ -0,0 +1 @@ +{"replace": false, "values": ["computercraft:computer_command"]} diff --git a/projects/forge/src/generated/resources/data/computercraft/recipes/computer_advanced_upgrade.json b/projects/forge/src/generated/resources/data/computercraft/recipes/computer_advanced_upgrade.json index 05bf8dc26..3a938c9c1 100644 --- a/projects/forge/src/generated/resources/data/computercraft/recipes/computer_advanced_upgrade.json +++ b/projects/forge/src/generated/resources/data/computercraft/recipes/computer_advanced_upgrade.json @@ -1,7 +1,6 @@ { "type": "computercraft:computer_upgrade", "category": "redstone", - "family": "advanced", "key": {"#": {"tag": "forge:ingots/gold"}, "C": {"item": "computercraft:computer_normal"}}, "pattern": ["###", "#C#", "# #"], "result": {"item": "computercraft:computer_advanced"}, diff --git a/projects/forge/src/generated/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json b/projects/forge/src/generated/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json index a139e02dd..2c5ec0cc8 100644 --- a/projects/forge/src/generated/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json +++ b/projects/forge/src/generated/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json @@ -1,7 +1,6 @@ { "type": "computercraft:computer_upgrade", "category": "redstone", - "family": "advanced", "key": {"#": {"tag": "forge:ingots/gold"}, "C": {"item": "computercraft:pocket_computer_normal"}}, "pattern": ["###", "#C#", "# #"], "result": {"item": "computercraft:pocket_computer_advanced"}, diff --git a/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_advanced.json b/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_advanced.json index c0485e66a..1e55d8f69 100644 --- a/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_advanced.json +++ b/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_advanced.json @@ -1,7 +1,6 @@ { "type": "computercraft:turtle", "category": "redstone", - "family": "advanced", "key": { "#": {"tag": "forge:ingots/gold"}, "C": {"item": "computercraft:computer_advanced"}, diff --git a/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_advanced_upgrade.json b/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_advanced_upgrade.json index a1c522fb8..6b1d7cc89 100644 --- a/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_advanced_upgrade.json +++ b/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_advanced_upgrade.json @@ -1,7 +1,6 @@ { "type": "computercraft:computer_upgrade", "category": "redstone", - "family": "advanced", "key": { "#": {"tag": "forge:ingots/gold"}, "B": {"tag": "forge:storage_blocks/gold"}, diff --git a/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_normal.json b/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_normal.json index 49c36fb43..c172dbd3a 100644 --- a/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_normal.json +++ b/projects/forge/src/generated/resources/data/computercraft/recipes/turtle_normal.json @@ -1,7 +1,6 @@ { "type": "computercraft:turtle", "category": "redstone", - "family": "normal", "key": { "#": {"tag": "forge:ingots/iron"}, "C": {"item": "computercraft:computer_normal"}, diff --git a/projects/forge/src/generated/resources/data/minecraft/tags/blocks/wither_immune.json b/projects/forge/src/generated/resources/data/minecraft/tags/blocks/wither_immune.json new file mode 100644 index 000000000..e1cc18b5d --- /dev/null +++ b/projects/forge/src/generated/resources/data/minecraft/tags/blocks/wither_immune.json @@ -0,0 +1 @@ +{"values": ["computercraft:computer_command"]}