mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 04:00:30 +00:00
Flesh out our registry abstraction layer
- Replace our usages of DeferredRegistry with a custom RegistrationHelper. This effectively behaves the same, just without any references to Forge code! - Replace any references to ForgeRegistries with a home-grown Registries class. This just fetches the underlying registry and proxies the method calls. - Change recipe serialisers and loot item conditions to be registered the same way as other entries. - Move any Forge specific registration code off to the main ComputerCraft class.
This commit is contained in:
parent
6d665ad841
commit
564752c8dd
@ -5,14 +5,33 @@
|
||||
*/
|
||||
package dan200.computercraft;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.ForgeComputerCraftAPI;
|
||||
import dan200.computercraft.api.detail.ForgeDetailRegistries;
|
||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
||||
import dan200.computercraft.shared.Config;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.network.NetworkHandler;
|
||||
import dan200.computercraft.shared.peripheral.generic.data.FluidData;
|
||||
import dan200.computercraft.shared.peripheral.generic.methods.EnergyMethods;
|
||||
import dan200.computercraft.shared.peripheral.generic.methods.FluidMethods;
|
||||
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.registries.NewRegistryEvent;
|
||||
import net.minecraftforge.registries.RegistryBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Mod(ComputerCraft.MOD_ID)
|
||||
@Mod.EventBusSubscriber(modid = ComputerCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class ComputerCraft {
|
||||
public static final String MOD_ID = "computercraft";
|
||||
|
||||
@ -56,6 +75,42 @@ public final class ComputerCraft {
|
||||
|
||||
public ComputerCraft() {
|
||||
Config.setup();
|
||||
ModRegistry.setup();
|
||||
ModRegistry.register();
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerRegistries(NewRegistryEvent event) {
|
||||
event.create(new RegistryBuilder<TurtleUpgradeSerialiser<?>>()
|
||||
.setName(TurtleUpgradeSerialiser.REGISTRY_ID.location())
|
||||
.disableSaving().disableSync());
|
||||
|
||||
event.create(new RegistryBuilder<PocketUpgradeSerialiser<?>>()
|
||||
.setName(PocketUpgradeSerialiser.REGISTRY_ID.location())
|
||||
.disableSaving().disableSync());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerCapabilities(RegisterCapabilitiesEvent event) {
|
||||
event.register(IWiredElement.class);
|
||||
event.register(IPeripheral.class);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void init(FMLCommonSetupEvent event) {
|
||||
NetworkHandler.setup();
|
||||
|
||||
event.enqueueWork(ModRegistry::registerMainThread);
|
||||
|
||||
ComputerCraftAPI.registerGenericSource(new InventoryMethods());
|
||||
ComputerCraftAPI.registerGenericSource(new FluidMethods());
|
||||
ComputerCraftAPI.registerGenericSource(new EnergyMethods());
|
||||
|
||||
ForgeComputerCraftAPI.registerGenericCapability(ForgeCapabilities.ITEM_HANDLER);
|
||||
ForgeComputerCraftAPI.registerGenericCapability(ForgeCapabilities.ENERGY);
|
||||
ForgeComputerCraftAPI.registerGenericCapability(ForgeCapabilities.FLUID_HANDLER);
|
||||
|
||||
ForgeDetailRegistries.FLUID_STACK.addProvider(FluidData::fill);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,13 +14,13 @@ import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
||||
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
|
||||
import dan200.computercraft.client.render.TurtleModelLoader;
|
||||
import dan200.computercraft.client.turtle.TurtleModemModeller;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.common.IColouredItem;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.media.items.ItemDisk;
|
||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.renderer.item.ItemProperties;
|
||||
|
@ -11,9 +11,9 @@ import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.pocket.ClientPocketComputers;
|
||||
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
@ -9,8 +9,8 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.core.terminal.Palette;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
|
||||
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
@ -10,10 +10,10 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import dan200.computercraft.client.render.RenderTypes;
|
||||
import dan200.computercraft.core.terminal.Palette;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.core.terminal.Palette;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -10,10 +10,10 @@ import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.client.FrameInfo;
|
||||
import dan200.computercraft.core.terminal.Palette;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.core.terminal.Palette;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package dan200.computercraft.data;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@ -14,8 +13,6 @@ import net.minecraftforge.fml.common.Mod;
|
||||
public class Generators {
|
||||
@SubscribeEvent
|
||||
public static void gather(GatherDataEvent event) {
|
||||
ModRegistry.registerLoot();
|
||||
|
||||
var generator = event.getGenerator();
|
||||
var existingFiles = event.getExistingFileHelper();
|
||||
|
||||
|
@ -9,6 +9,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DataProvider;
|
||||
@ -20,7 +21,6 @@ import net.minecraft.data.models.model.ModelLocationUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.nio.file.Path;
|
||||
@ -75,7 +75,7 @@ public class ModelProvider implements DataProvider {
|
||||
blocks.accept(new BlockModelGenerators(addBlockState, addModel, explicitItems::add));
|
||||
items.accept(new ItemModelGenerators(addModel));
|
||||
|
||||
for (var block : ForgeRegistries.BLOCKS) {
|
||||
for (var block : Registries.BLOCKS) {
|
||||
if (!blockStates.containsKey(block)) continue;
|
||||
|
||||
var item = Item.BY_BLOCK.get(block);
|
||||
@ -87,7 +87,7 @@ public class ModelProvider implements DataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
saveCollection(output, blockStates, x -> blockStatePath.json(ForgeRegistries.BLOCKS.getKey(x)));
|
||||
saveCollection(output, blockStates, x -> blockStatePath.json(Registries.BLOCKS.getKey(x)));
|
||||
saveCollection(output, models, modelPath::json);
|
||||
}
|
||||
|
||||
|
@ -9,21 +9,13 @@ import com.google.gson.JsonObject;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.pocket.PocketUpgradeDataProvider;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeDataProvider;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.common.ColourableRecipe;
|
||||
import dan200.computercraft.shared.common.IColouredItem;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.recipe.ComputerUpgradeRecipe;
|
||||
import dan200.computercraft.shared.media.recipes.DiskRecipe;
|
||||
import dan200.computercraft.shared.media.recipes.PrintoutRecipe;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory;
|
||||
import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe;
|
||||
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
import dan200.computercraft.shared.turtle.recipes.TurtleRecipe;
|
||||
import dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.util.ImpostorRecipe;
|
||||
import dan200.computercraft.shared.util.ImpostorShapelessRecipe;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
@ -31,12 +23,13 @@ import net.minecraft.data.recipes.*;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.DyeItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
@ -63,11 +56,11 @@ class RecipeGenerator extends RecipeProvider {
|
||||
pocketUpgrades(add);
|
||||
turtleUpgrades(add);
|
||||
|
||||
addSpecial(add, PrintoutRecipe.SERIALIZER);
|
||||
addSpecial(add, DiskRecipe.SERIALIZER);
|
||||
addSpecial(add, ColourableRecipe.SERIALIZER);
|
||||
addSpecial(add, TurtleUpgradeRecipe.SERIALIZER);
|
||||
addSpecial(add, PocketComputerUpgradeRecipe.SERIALIZER);
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.PRINTOUT.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.DISK.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.DYEABLE_ITEM.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.TURTLE_UPGRADE.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.POCKET_COMPUTER_UPGRADE.get());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +78,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.group("computercraft:disk")
|
||||
.unlockedBy("has_drive", inventoryChange(ModRegistry.Blocks.DISK_DRIVE.get()))
|
||||
.save(
|
||||
RecipeWrapper.wrap(ImpostorShapelessRecipe.SERIALIZER, add)
|
||||
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPELESS.get(), add)
|
||||
.withResultTag(x -> x.putInt(IColouredItem.NBT_COLOUR, colour.getHex())),
|
||||
new ResourceLocation(ComputerCraft.MOD_ID, "disk_" + (colour.ordinal() + 1))
|
||||
);
|
||||
@ -115,7 +108,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.unlockedBy("has_items",
|
||||
inventoryChange(base.getItem(), upgrade.getCraftingItem().getItem()))
|
||||
.save(
|
||||
RecipeWrapper.wrap(ImpostorRecipe.SERIALIZER, add).withResultTag(result.getTag()),
|
||||
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPED.get(), add).withResultTag(result.getTag()),
|
||||
new ResourceLocation(ComputerCraft.MOD_ID, String.format("turtle_%s/%s/%s",
|
||||
nameId, upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath()
|
||||
))
|
||||
@ -148,7 +141,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.unlockedBy("has_items",
|
||||
inventoryChange(base.getItem(), upgrade.getCraftingItem().getItem()))
|
||||
.save(
|
||||
RecipeWrapper.wrap(ImpostorRecipe.SERIALIZER, add).withResultTag(result.getTag()),
|
||||
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPED.get(), add).withResultTag(result.getTag()),
|
||||
new ResourceLocation(ComputerCraft.MOD_ID, String.format("pocket_%s/%s/%s",
|
||||
nameId, upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath()
|
||||
))
|
||||
@ -200,7 +193,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.define('C', ModRegistry.Items.COMPUTER_ADVANCED.get())
|
||||
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.COMPUTER_NORMAL.get()), itemPredicate(Tags.Items.INGOTS_GOLD)))
|
||||
.save(
|
||||
RecipeWrapper.wrap(ComputerUpgradeRecipe.SERIALIZER, add).withExtraData(family(ComputerFamily.ADVANCED)),
|
||||
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)),
|
||||
new ResourceLocation(ComputerCraft.MOD_ID, "computer_advanced_upgrade")
|
||||
);
|
||||
|
||||
@ -224,7 +217,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.define('C', ModRegistry.Items.COMPUTER_NORMAL.get())
|
||||
.define('I', Tags.Items.CHESTS_WOODEN)
|
||||
.unlockedBy("has_computer", inventoryChange(ModRegistry.Items.COMPUTER_NORMAL.get()))
|
||||
.save(RecipeWrapper.wrap(TurtleRecipe.SERIALIZER, add).withExtraData(family(ComputerFamily.NORMAL)));
|
||||
.save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.TURTLE.get(), add).withExtraData(family(ComputerFamily.NORMAL)));
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped(ModRegistry.Blocks.TURTLE_ADVANCED.get())
|
||||
@ -235,7 +228,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.define('C', ModRegistry.Items.COMPUTER_ADVANCED.get())
|
||||
.define('I', Tags.Items.CHESTS_WOODEN)
|
||||
.unlockedBy("has_computer", inventoryChange(ModRegistry.Items.COMPUTER_NORMAL.get()))
|
||||
.save(RecipeWrapper.wrap(TurtleRecipe.SERIALIZER, add).withExtraData(family(ComputerFamily.ADVANCED)));
|
||||
.save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.TURTLE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)));
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped(ModRegistry.Blocks.TURTLE_ADVANCED.get())
|
||||
@ -247,7 +240,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.define('B', Tags.Items.STORAGE_BLOCKS_GOLD)
|
||||
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.TURTLE_NORMAL.get()), itemPredicate(Tags.Items.INGOTS_GOLD)))
|
||||
.save(
|
||||
RecipeWrapper.wrap(ComputerUpgradeRecipe.SERIALIZER, add).withExtraData(family(ComputerFamily.ADVANCED)),
|
||||
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)),
|
||||
new ResourceLocation(ComputerCraft.MOD_ID, "turtle_advanced_upgrade")
|
||||
);
|
||||
|
||||
@ -314,7 +307,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.define('C', ModRegistry.Items.POCKET_COMPUTER_NORMAL.get())
|
||||
.unlockedBy("has_components", inventoryChange(itemPredicate(ModRegistry.Items.POCKET_COMPUTER_NORMAL.get()), itemPredicate(Tags.Items.INGOTS_GOLD)))
|
||||
.save(
|
||||
RecipeWrapper.wrap(ComputerUpgradeRecipe.SERIALIZER, add).withExtraData(family(ComputerFamily.ADVANCED)),
|
||||
RecipeWrapper.wrap(ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get(), add).withExtraData(family(ComputerFamily.ADVANCED)),
|
||||
new ResourceLocation(ComputerCraft.MOD_ID, "pocket_computer_advanced_upgrade")
|
||||
);
|
||||
|
||||
@ -410,7 +403,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.requires(ModRegistry.Items.PRINTED_PAGE.get(), 2)
|
||||
.requires(Tags.Items.STRING)
|
||||
.unlockedBy("has_printer", inventoryChange(ModRegistry.Blocks.PRINTER.get()))
|
||||
.save(RecipeWrapper.wrap(ImpostorShapelessRecipe.SERIALIZER, add));
|
||||
.save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPELESS.get(), add));
|
||||
|
||||
ShapelessRecipeBuilder
|
||||
.shapeless(ModRegistry.Items.PRINTED_BOOK.get())
|
||||
@ -418,7 +411,7 @@ class RecipeGenerator extends RecipeProvider {
|
||||
.requires(ModRegistry.Items.PRINTED_PAGE.get(), 1)
|
||||
.requires(Tags.Items.STRING)
|
||||
.unlockedBy("has_printer", inventoryChange(ModRegistry.Blocks.PRINTER.get()))
|
||||
.save(RecipeWrapper.wrap(ImpostorShapelessRecipe.SERIALIZER, add));
|
||||
.save(RecipeWrapper.wrap(ModRegistry.RecipeSerializers.IMPOSTOR_SHAPELESS.get(), add));
|
||||
}
|
||||
|
||||
private static DyeColor ofColour(Colour colour) {
|
||||
@ -460,6 +453,6 @@ class RecipeGenerator extends RecipeProvider {
|
||||
}
|
||||
|
||||
private static void addSpecial(Consumer<FinishedRecipe> add, SimpleRecipeSerializer<?> special) {
|
||||
SpecialRecipeBuilder.special(special).save(add, ForgeRegistries.RECIPE_SERIALIZERS.getKey(special).toString());
|
||||
SpecialRecipeBuilder.special(special).save(add, Registries.RECIPE_SERIALIZERS.getKey(special).toString());
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@ import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
import net.minecraftforge.event.server.ServerStoppedEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.MissingMappingsEvent;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -123,12 +121,4 @@ public final class CommonHooks {
|
||||
NetworkHandler.sendToPlayer(event.getPlayer(), packet);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onMissingEntityMappingsEvent(MissingMappingsEvent event) {
|
||||
var id = new ResourceLocation(ComputerCraft.MOD_ID, "turtle_player");
|
||||
for (var mapping : event.getMappings(ForgeRegistries.BLOCKS.getRegistryKey(), ComputerCraft.MOD_ID)) {
|
||||
if (mapping.getKey().equals(id)) mapping.ignore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,9 @@
|
||||
package dan200.computercraft.shared;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.ForgeComputerCraftAPI;
|
||||
import dan200.computercraft.api.detail.ForgeDetailRegistries;
|
||||
import dan200.computercraft.api.detail.VanillaDetailRegistries;
|
||||
import dan200.computercraft.api.media.IMedia;
|
||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
||||
import dan200.computercraft.shared.command.arguments.ComputerArgumentType;
|
||||
@ -33,6 +28,7 @@ import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||
import dan200.computercraft.shared.computer.recipe.ComputerUpgradeRecipe;
|
||||
import dan200.computercraft.shared.data.BlockNamedEntityLootCondition;
|
||||
import dan200.computercraft.shared.data.ConstantLootConditionSerializer;
|
||||
import dan200.computercraft.shared.data.HasComputerIdLootCondition;
|
||||
import dan200.computercraft.shared.data.PlayerCreativeLootCondition;
|
||||
import dan200.computercraft.shared.media.items.ItemDisk;
|
||||
@ -41,7 +37,6 @@ import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||
import dan200.computercraft.shared.media.items.RecordMedia;
|
||||
import dan200.computercraft.shared.media.recipes.DiskRecipe;
|
||||
import dan200.computercraft.shared.media.recipes.PrintoutRecipe;
|
||||
import dan200.computercraft.shared.network.NetworkHandler;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import dan200.computercraft.shared.network.container.ContainerData;
|
||||
import dan200.computercraft.shared.network.container.HeldItemContainerData;
|
||||
@ -49,11 +44,7 @@ import dan200.computercraft.shared.peripheral.diskdrive.BlockDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.generic.data.BlockData;
|
||||
import dan200.computercraft.shared.peripheral.generic.data.FluidData;
|
||||
import dan200.computercraft.shared.peripheral.generic.data.ItemData;
|
||||
import dan200.computercraft.shared.peripheral.generic.methods.EnergyMethods;
|
||||
import dan200.computercraft.shared.peripheral.generic.methods.FluidMethods;
|
||||
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.*;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.BlockWirelessModem;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.TileWirelessModem;
|
||||
@ -64,6 +55,9 @@ import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||
import dan200.computercraft.shared.peripheral.speaker.BlockSpeaker;
|
||||
import dan200.computercraft.shared.peripheral.speaker.TileSpeaker;
|
||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||
import dan200.computercraft.shared.platform.RegistrationHelper;
|
||||
import dan200.computercraft.shared.platform.RegistryEntry;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
||||
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
||||
@ -77,12 +71,12 @@ import dan200.computercraft.shared.turtle.recipes.TurtleRecipe;
|
||||
import dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe;
|
||||
import dan200.computercraft.shared.turtle.upgrades.*;
|
||||
import dan200.computercraft.shared.util.CreativeTabMain;
|
||||
import dan200.computercraft.shared.util.FixedPointTileEntityType;
|
||||
import dan200.computercraft.shared.util.ImpostorRecipe;
|
||||
import dan200.computercraft.shared.util.ImpostorShapelessRecipe;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
|
||||
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.cauldron.CauldronInteraction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@ -91,23 +85,20 @@ import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.RecordItem;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.*;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = ComputerCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class ModRegistry {
|
||||
private static final CreativeModeTab mainItemGroup = new CreativeTabMain();
|
||||
|
||||
@ -115,7 +106,7 @@ public final class ModRegistry {
|
||||
}
|
||||
|
||||
public static final class Blocks {
|
||||
static final DeferredRegister<Block> REGISTRY = DeferredRegister.create(ForgeRegistries.BLOCKS, ComputerCraft.MOD_ID);
|
||||
static final RegistrationHelper<Block> REGISTRY = PlatformHelper.get().createRegistrationHelper(Registry.BLOCK_REGISTRY);
|
||||
|
||||
private static BlockBehaviour.Properties properties() {
|
||||
return BlockBehaviour.Properties.of(Material.STONE).strength(2);
|
||||
@ -129,182 +120,187 @@ public final class ModRegistry {
|
||||
return BlockBehaviour.Properties.of(Material.STONE).strength(1.5f);
|
||||
}
|
||||
|
||||
public static final RegistryObject<BlockComputer<TileComputer>> COMPUTER_NORMAL = REGISTRY.register("computer_normal",
|
||||
public static final RegistryEntry<BlockComputer<TileComputer>> COMPUTER_NORMAL = REGISTRY.register("computer_normal",
|
||||
() -> new BlockComputer<>(properties(), ComputerFamily.NORMAL, BlockEntities.COMPUTER_NORMAL));
|
||||
public static final RegistryObject<BlockComputer<TileComputer>> COMPUTER_ADVANCED = REGISTRY.register("computer_advanced",
|
||||
public static final RegistryEntry<BlockComputer<TileComputer>> COMPUTER_ADVANCED = REGISTRY.register("computer_advanced",
|
||||
() -> new BlockComputer<>(properties(), ComputerFamily.ADVANCED, BlockEntities.COMPUTER_ADVANCED));
|
||||
|
||||
public static final RegistryObject<BlockComputer<TileCommandComputer>> COMPUTER_COMMAND = REGISTRY.register("computer_command", () -> new BlockComputer<>(
|
||||
public static final RegistryEntry<BlockComputer<TileCommandComputer>> COMPUTER_COMMAND = REGISTRY.register("computer_command", () -> new BlockComputer<>(
|
||||
BlockBehaviour.Properties.of(Material.STONE).strength(-1, 6000000.0F),
|
||||
ComputerFamily.COMMAND, BlockEntities.COMPUTER_COMMAND
|
||||
));
|
||||
|
||||
public static final RegistryObject<BlockTurtle> TURTLE_NORMAL = REGISTRY.register("turtle_normal",
|
||||
public static final RegistryEntry<BlockTurtle> TURTLE_NORMAL = REGISTRY.register("turtle_normal",
|
||||
() -> new BlockTurtle(turtleProperties(), ComputerFamily.NORMAL, BlockEntities.TURTLE_NORMAL));
|
||||
public static final RegistryObject<BlockTurtle> TURTLE_ADVANCED = REGISTRY.register("turtle_advanced",
|
||||
public static final RegistryEntry<BlockTurtle> TURTLE_ADVANCED = REGISTRY.register("turtle_advanced",
|
||||
() -> new BlockTurtle(turtleProperties(), ComputerFamily.ADVANCED, BlockEntities.TURTLE_ADVANCED));
|
||||
|
||||
public static final RegistryObject<BlockSpeaker> SPEAKER = REGISTRY.register("speaker", () -> new BlockSpeaker(properties()));
|
||||
public static final RegistryObject<BlockDiskDrive> DISK_DRIVE = REGISTRY.register("disk_drive", () -> new BlockDiskDrive(properties()));
|
||||
public static final RegistryObject<BlockPrinter> PRINTER = REGISTRY.register("printer", () -> new BlockPrinter(properties()));
|
||||
public static final RegistryEntry<BlockSpeaker> SPEAKER = REGISTRY.register("speaker", () -> new BlockSpeaker(properties()));
|
||||
public static final RegistryEntry<BlockDiskDrive> DISK_DRIVE = REGISTRY.register("disk_drive", () -> new BlockDiskDrive(properties()));
|
||||
public static final RegistryEntry<BlockPrinter> PRINTER = REGISTRY.register("printer", () -> new BlockPrinter(properties()));
|
||||
|
||||
public static final RegistryObject<BlockMonitor> MONITOR_NORMAL = REGISTRY.register("monitor_normal",
|
||||
public static final RegistryEntry<BlockMonitor> MONITOR_NORMAL = REGISTRY.register("monitor_normal",
|
||||
() -> new BlockMonitor(properties(), BlockEntities.MONITOR_NORMAL));
|
||||
public static final RegistryObject<BlockMonitor> MONITOR_ADVANCED = REGISTRY.register("monitor_advanced",
|
||||
public static final RegistryEntry<BlockMonitor> MONITOR_ADVANCED = REGISTRY.register("monitor_advanced",
|
||||
() -> new BlockMonitor(properties(), BlockEntities.MONITOR_ADVANCED));
|
||||
|
||||
public static final RegistryObject<BlockWirelessModem> WIRELESS_MODEM_NORMAL = REGISTRY.register("wireless_modem_normal",
|
||||
public static final RegistryEntry<BlockWirelessModem> WIRELESS_MODEM_NORMAL = REGISTRY.register("wireless_modem_normal",
|
||||
() -> new BlockWirelessModem(properties(), BlockEntities.WIRELESS_MODEM_NORMAL));
|
||||
public static final RegistryObject<BlockWirelessModem> WIRELESS_MODEM_ADVANCED = REGISTRY.register("wireless_modem_advanced",
|
||||
public static final RegistryEntry<BlockWirelessModem> WIRELESS_MODEM_ADVANCED = REGISTRY.register("wireless_modem_advanced",
|
||||
() -> new BlockWirelessModem(properties(), BlockEntities.WIRELESS_MODEM_ADVANCED));
|
||||
|
||||
public static final RegistryObject<BlockWiredModemFull> WIRED_MODEM_FULL = REGISTRY.register("wired_modem_full",
|
||||
public static final RegistryEntry<BlockWiredModemFull> WIRED_MODEM_FULL = REGISTRY.register("wired_modem_full",
|
||||
() -> new BlockWiredModemFull(modemProperties()));
|
||||
public static final RegistryObject<BlockCable> CABLE = REGISTRY.register("cable", () -> new BlockCable(modemProperties()));
|
||||
public static final RegistryEntry<BlockCable> CABLE = REGISTRY.register("cable", () -> new BlockCable(modemProperties()));
|
||||
}
|
||||
|
||||
public static class BlockEntities {
|
||||
static final DeferredRegister<BlockEntityType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, ComputerCraft.MOD_ID);
|
||||
static final RegistrationHelper<BlockEntityType<?>> REGISTRY = PlatformHelper.get().createRegistrationHelper(Registry.BLOCK_ENTITY_TYPE_REGISTRY);
|
||||
|
||||
private static <T extends BlockEntity> RegistryObject<BlockEntityType<T>> ofBlock(RegistryObject<? extends Block> block, FixedPointTileEntityType.FixedPointBlockEntitySupplier<T> factory) {
|
||||
return REGISTRY.register(block.getId().getPath(), () -> FixedPointTileEntityType.create(block, factory));
|
||||
private static <T extends BlockEntity> RegistryEntry<BlockEntityType<T>> ofBlock(RegistryEntry<? extends Block> block, BiFunction<BlockPos, BlockState, T> factory) {
|
||||
return REGISTRY.register(block.id().getPath(), () -> PlatformHelper.get().createBlockEntityType(factory, block.get()));
|
||||
}
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileMonitor>> MONITOR_NORMAL =
|
||||
ofBlock(Blocks.MONITOR_NORMAL, (f, p, s) -> new TileMonitor(f, p, s, false));
|
||||
public static final RegistryObject<BlockEntityType<TileMonitor>> MONITOR_ADVANCED =
|
||||
ofBlock(Blocks.MONITOR_ADVANCED, (f, p, s) -> new TileMonitor(f, p, s, true));
|
||||
public static final RegistryEntry<BlockEntityType<TileMonitor>> MONITOR_NORMAL =
|
||||
ofBlock(Blocks.MONITOR_NORMAL, (p, s) -> new TileMonitor(BlockEntities.MONITOR_NORMAL.get(), p, s, false));
|
||||
public static final RegistryEntry<BlockEntityType<TileMonitor>> MONITOR_ADVANCED =
|
||||
ofBlock(Blocks.MONITOR_ADVANCED, (p, s) -> new TileMonitor(BlockEntities.MONITOR_ADVANCED.get(), p, s, true));
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileComputer>> COMPUTER_NORMAL =
|
||||
ofBlock(Blocks.COMPUTER_NORMAL, (f, p, s) -> new TileComputer(f, p, s, ComputerFamily.NORMAL));
|
||||
public static final RegistryObject<BlockEntityType<TileComputer>> COMPUTER_ADVANCED =
|
||||
ofBlock(Blocks.COMPUTER_ADVANCED, (f, p, s) -> new TileComputer(f, p, s, ComputerFamily.ADVANCED));
|
||||
public static final RegistryObject<BlockEntityType<TileCommandComputer>> COMPUTER_COMMAND =
|
||||
ofBlock(Blocks.COMPUTER_COMMAND, TileCommandComputer::new);
|
||||
public static final RegistryEntry<BlockEntityType<TileComputer>> COMPUTER_NORMAL =
|
||||
ofBlock(Blocks.COMPUTER_NORMAL, (p, s) -> new TileComputer(BlockEntities.COMPUTER_NORMAL.get(), p, s, ComputerFamily.NORMAL));
|
||||
public static final RegistryEntry<BlockEntityType<TileComputer>> COMPUTER_ADVANCED =
|
||||
ofBlock(Blocks.COMPUTER_ADVANCED, (p, s) -> new TileComputer(BlockEntities.COMPUTER_ADVANCED.get(), p, s, ComputerFamily.ADVANCED));
|
||||
public static final RegistryEntry<BlockEntityType<TileCommandComputer>> COMPUTER_COMMAND =
|
||||
ofBlock(Blocks.COMPUTER_COMMAND, (p, s) -> new TileCommandComputer(BlockEntities.COMPUTER_COMMAND.get(), p, s));
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileTurtle>> TURTLE_NORMAL =
|
||||
ofBlock(Blocks.TURTLE_NORMAL, (f, p, s) -> new TileTurtle(f, p, s, ComputerFamily.NORMAL));
|
||||
public static final RegistryObject<BlockEntityType<TileTurtle>> TURTLE_ADVANCED =
|
||||
ofBlock(Blocks.TURTLE_ADVANCED, (f, p, s) -> new TileTurtle(f, p, s, ComputerFamily.ADVANCED));
|
||||
public static final RegistryEntry<BlockEntityType<TileTurtle>> TURTLE_NORMAL =
|
||||
ofBlock(Blocks.TURTLE_NORMAL, (p, s) -> new TileTurtle(BlockEntities.TURTLE_NORMAL.get(), p, s, ComputerFamily.NORMAL));
|
||||
public static final RegistryEntry<BlockEntityType<TileTurtle>> TURTLE_ADVANCED =
|
||||
ofBlock(Blocks.TURTLE_ADVANCED, (p, s) -> new TileTurtle(BlockEntities.TURTLE_ADVANCED.get(), p, s, ComputerFamily.ADVANCED));
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileSpeaker>> SPEAKER = ofBlock(Blocks.SPEAKER, TileSpeaker::new);
|
||||
public static final RegistryObject<BlockEntityType<TileDiskDrive>> DISK_DRIVE = ofBlock(Blocks.DISK_DRIVE, TileDiskDrive::new);
|
||||
public static final RegistryObject<BlockEntityType<TilePrinter>> PRINTER = ofBlock(Blocks.PRINTER, TilePrinter::new);
|
||||
public static final RegistryObject<BlockEntityType<TileWiredModemFull>> WIRED_MODEM_FULL = ofBlock(Blocks.WIRED_MODEM_FULL, TileWiredModemFull::new);
|
||||
public static final RegistryObject<BlockEntityType<TileCable>> CABLE = ofBlock(Blocks.CABLE, TileCable::new);
|
||||
public static final RegistryEntry<BlockEntityType<TileSpeaker>> SPEAKER =
|
||||
ofBlock(Blocks.SPEAKER, (p, s) -> new TileSpeaker(BlockEntities.SPEAKER.get(), p, s));
|
||||
public static final RegistryEntry<BlockEntityType<TileDiskDrive>> DISK_DRIVE =
|
||||
ofBlock(Blocks.DISK_DRIVE, (p, s) -> new TileDiskDrive(BlockEntities.DISK_DRIVE.get(), p, s));
|
||||
public static final RegistryEntry<BlockEntityType<TilePrinter>> PRINTER =
|
||||
ofBlock(Blocks.PRINTER, (p, s) -> new TilePrinter(BlockEntities.PRINTER.get(), p, s));
|
||||
public static final RegistryEntry<BlockEntityType<TileWiredModemFull>> WIRED_MODEM_FULL =
|
||||
ofBlock(Blocks.WIRED_MODEM_FULL, (p, s) -> new TileWiredModemFull(BlockEntities.WIRED_MODEM_FULL.get(), p, s));
|
||||
public static final RegistryEntry<BlockEntityType<TileCable>> CABLE =
|
||||
ofBlock(Blocks.CABLE, (p, s) -> new TileCable(BlockEntities.CABLE.get(), p, s));
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileWirelessModem>> WIRELESS_MODEM_NORMAL =
|
||||
ofBlock(Blocks.WIRELESS_MODEM_NORMAL, (f, p, s) -> new TileWirelessModem(f, p, s, false));
|
||||
public static final RegistryObject<BlockEntityType<TileWirelessModem>> WIRELESS_MODEM_ADVANCED =
|
||||
ofBlock(Blocks.WIRELESS_MODEM_ADVANCED, (f, p, s) -> new TileWirelessModem(f, p, s, true));
|
||||
public static final RegistryEntry<BlockEntityType<TileWirelessModem>> WIRELESS_MODEM_NORMAL =
|
||||
ofBlock(Blocks.WIRELESS_MODEM_NORMAL, (p, s) -> new TileWirelessModem(BlockEntities.WIRELESS_MODEM_NORMAL.get(), p, s, false));
|
||||
public static final RegistryEntry<BlockEntityType<TileWirelessModem>> WIRELESS_MODEM_ADVANCED =
|
||||
ofBlock(Blocks.WIRELESS_MODEM_ADVANCED, (p, s) -> new TileWirelessModem(BlockEntities.WIRELESS_MODEM_ADVANCED.get(), p, s, true));
|
||||
}
|
||||
|
||||
public static final class Items {
|
||||
static final DeferredRegister<Item> REGISTRY = DeferredRegister.create(ForgeRegistries.ITEMS, ComputerCraft.MOD_ID);
|
||||
static final RegistrationHelper<Item> REGISTRY = PlatformHelper.get().createRegistrationHelper(Registry.ITEM_REGISTRY);
|
||||
|
||||
private static Item.Properties properties() {
|
||||
return new Item.Properties().tab(mainItemGroup);
|
||||
}
|
||||
|
||||
private static <B extends Block, I extends Item> RegistryObject<I> ofBlock(RegistryObject<B> parent, BiFunction<B, Item.Properties, I> supplier) {
|
||||
return REGISTRY.register(parent.getId().getPath(), () -> supplier.apply(parent.get(), properties()));
|
||||
private static <B extends Block, I extends Item> RegistryEntry<I> ofBlock(RegistryEntry<B> parent, BiFunction<B, Item.Properties, I> supplier) {
|
||||
return REGISTRY.register(parent.id().getPath(), () -> supplier.apply(parent.get(), properties()));
|
||||
}
|
||||
|
||||
public static final RegistryObject<ItemComputer> COMPUTER_NORMAL = ofBlock(Blocks.COMPUTER_NORMAL, ItemComputer::new);
|
||||
public static final RegistryObject<ItemComputer> COMPUTER_ADVANCED = ofBlock(Blocks.COMPUTER_ADVANCED, ItemComputer::new);
|
||||
public static final RegistryObject<ItemComputer> COMPUTER_COMMAND = ofBlock(Blocks.COMPUTER_COMMAND, ItemComputer::new);
|
||||
public static final RegistryEntry<ItemComputer> COMPUTER_NORMAL = ofBlock(Blocks.COMPUTER_NORMAL, ItemComputer::new);
|
||||
public static final RegistryEntry<ItemComputer> COMPUTER_ADVANCED = ofBlock(Blocks.COMPUTER_ADVANCED, ItemComputer::new);
|
||||
public static final RegistryEntry<ItemComputer> COMPUTER_COMMAND = ofBlock(Blocks.COMPUTER_COMMAND, ItemComputer::new);
|
||||
|
||||
public static final RegistryObject<ItemPocketComputer> POCKET_COMPUTER_NORMAL = REGISTRY.register("pocket_computer_normal",
|
||||
public static final RegistryEntry<ItemPocketComputer> POCKET_COMPUTER_NORMAL = REGISTRY.register("pocket_computer_normal",
|
||||
() -> new ItemPocketComputer(properties().stacksTo(1), ComputerFamily.NORMAL));
|
||||
public static final RegistryObject<ItemPocketComputer> POCKET_COMPUTER_ADVANCED = REGISTRY.register("pocket_computer_advanced",
|
||||
public static final RegistryEntry<ItemPocketComputer> POCKET_COMPUTER_ADVANCED = REGISTRY.register("pocket_computer_advanced",
|
||||
() -> new ItemPocketComputer(properties().stacksTo(1), ComputerFamily.ADVANCED));
|
||||
|
||||
public static final RegistryObject<ItemTurtle> TURTLE_NORMAL = ofBlock(Blocks.TURTLE_NORMAL, ItemTurtle::new);
|
||||
public static final RegistryObject<ItemTurtle> TURTLE_ADVANCED = ofBlock(Blocks.TURTLE_ADVANCED, ItemTurtle::new);
|
||||
public static final RegistryEntry<ItemTurtle> TURTLE_NORMAL = ofBlock(Blocks.TURTLE_NORMAL, ItemTurtle::new);
|
||||
public static final RegistryEntry<ItemTurtle> TURTLE_ADVANCED = ofBlock(Blocks.TURTLE_ADVANCED, ItemTurtle::new);
|
||||
|
||||
public static final RegistryObject<ItemDisk> DISK =
|
||||
public static final RegistryEntry<ItemDisk> DISK =
|
||||
REGISTRY.register("disk", () -> new ItemDisk(properties().stacksTo(1)));
|
||||
public static final RegistryObject<ItemTreasureDisk> TREASURE_DISK =
|
||||
public static final RegistryEntry<ItemTreasureDisk> TREASURE_DISK =
|
||||
REGISTRY.register("treasure_disk", () -> new ItemTreasureDisk(properties().stacksTo(1)));
|
||||
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_PAGE = REGISTRY.register("printed_page",
|
||||
public static final RegistryEntry<ItemPrintout> PRINTED_PAGE = REGISTRY.register("printed_page",
|
||||
() -> new ItemPrintout(properties().stacksTo(1), ItemPrintout.Type.PAGE));
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_PAGES = REGISTRY.register("printed_pages",
|
||||
public static final RegistryEntry<ItemPrintout> PRINTED_PAGES = REGISTRY.register("printed_pages",
|
||||
() -> new ItemPrintout(properties().stacksTo(1), ItemPrintout.Type.PAGES));
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_BOOK = REGISTRY.register("printed_book",
|
||||
public static final RegistryEntry<ItemPrintout> PRINTED_BOOK = REGISTRY.register("printed_book",
|
||||
() -> new ItemPrintout(properties().stacksTo(1), ItemPrintout.Type.BOOK));
|
||||
|
||||
public static final RegistryObject<BlockItem> SPEAKER = ofBlock(Blocks.SPEAKER, BlockItem::new);
|
||||
public static final RegistryObject<BlockItem> DISK_DRIVE = ofBlock(Blocks.DISK_DRIVE, BlockItem::new);
|
||||
public static final RegistryObject<BlockItem> PRINTER = ofBlock(Blocks.PRINTER, BlockItem::new);
|
||||
public static final RegistryObject<BlockItem> MONITOR_NORMAL = ofBlock(Blocks.MONITOR_NORMAL, BlockItem::new);
|
||||
public static final RegistryObject<BlockItem> MONITOR_ADVANCED = ofBlock(Blocks.MONITOR_ADVANCED, BlockItem::new);
|
||||
public static final RegistryObject<BlockItem> WIRELESS_MODEM_NORMAL = ofBlock(Blocks.WIRELESS_MODEM_NORMAL, BlockItem::new);
|
||||
public static final RegistryObject<BlockItem> WIRELESS_MODEM_ADVANCED = ofBlock(Blocks.WIRELESS_MODEM_ADVANCED, BlockItem::new);
|
||||
public static final RegistryObject<BlockItem> WIRED_MODEM_FULL = ofBlock(Blocks.WIRED_MODEM_FULL, BlockItem::new);
|
||||
public static final RegistryEntry<BlockItem> SPEAKER = ofBlock(Blocks.SPEAKER, BlockItem::new);
|
||||
public static final RegistryEntry<BlockItem> DISK_DRIVE = ofBlock(Blocks.DISK_DRIVE, BlockItem::new);
|
||||
public static final RegistryEntry<BlockItem> PRINTER = ofBlock(Blocks.PRINTER, BlockItem::new);
|
||||
public static final RegistryEntry<BlockItem> MONITOR_NORMAL = ofBlock(Blocks.MONITOR_NORMAL, BlockItem::new);
|
||||
public static final RegistryEntry<BlockItem> MONITOR_ADVANCED = ofBlock(Blocks.MONITOR_ADVANCED, BlockItem::new);
|
||||
public static final RegistryEntry<BlockItem> WIRELESS_MODEM_NORMAL = ofBlock(Blocks.WIRELESS_MODEM_NORMAL, BlockItem::new);
|
||||
public static final RegistryEntry<BlockItem> WIRELESS_MODEM_ADVANCED = ofBlock(Blocks.WIRELESS_MODEM_ADVANCED, BlockItem::new);
|
||||
public static final RegistryEntry<BlockItem> WIRED_MODEM_FULL = ofBlock(Blocks.WIRED_MODEM_FULL, BlockItem::new);
|
||||
|
||||
public static final RegistryObject<ItemBlockCable.Cable> CABLE = REGISTRY.register("cable",
|
||||
public static final RegistryEntry<ItemBlockCable.Cable> CABLE = REGISTRY.register("cable",
|
||||
() -> new ItemBlockCable.Cable(Blocks.CABLE.get(), properties()));
|
||||
public static final RegistryObject<ItemBlockCable.WiredModem> WIRED_MODEM = REGISTRY.register("wired_modem",
|
||||
public static final RegistryEntry<ItemBlockCable.WiredModem> WIRED_MODEM = REGISTRY.register("wired_modem",
|
||||
() -> new ItemBlockCable.WiredModem(Blocks.CABLE.get(), properties()));
|
||||
}
|
||||
|
||||
public static class TurtleSerialisers {
|
||||
static final DeferredRegister<TurtleUpgradeSerialiser<?>> REGISTRY = DeferredRegister.create(TurtleUpgradeSerialiser.REGISTRY_ID.location(), ComputerCraft.MOD_ID);
|
||||
static final RegistrationHelper<TurtleUpgradeSerialiser<?>> REGISTRY = PlatformHelper.get().createRegistrationHelper(TurtleUpgradeSerialiser.REGISTRY_ID);
|
||||
|
||||
public static final RegistryObject<TurtleUpgradeSerialiser<TurtleSpeaker>> SPEAKER =
|
||||
public static final RegistryEntry<TurtleUpgradeSerialiser<TurtleSpeaker>> SPEAKER =
|
||||
REGISTRY.register("speaker", () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleSpeaker::new));
|
||||
public static final RegistryObject<TurtleUpgradeSerialiser<TurtleCraftingTable>> WORKBENCH =
|
||||
public static final RegistryEntry<TurtleUpgradeSerialiser<TurtleCraftingTable>> WORKBENCH =
|
||||
REGISTRY.register("workbench", () -> TurtleUpgradeSerialiser.simpleWithCustomItem(TurtleCraftingTable::new));
|
||||
public static final RegistryObject<TurtleUpgradeSerialiser<TurtleModem>> WIRELESS_MODEM_NORMAL =
|
||||
public static final RegistryEntry<TurtleUpgradeSerialiser<TurtleModem>> WIRELESS_MODEM_NORMAL =
|
||||
REGISTRY.register("wireless_modem_normal", () -> TurtleUpgradeSerialiser.simpleWithCustomItem((id, item) -> new TurtleModem(id, item, false)));
|
||||
public static final RegistryObject<TurtleUpgradeSerialiser<TurtleModem>> WIRELESS_MODEM_ADVANCED =
|
||||
public static final RegistryEntry<TurtleUpgradeSerialiser<TurtleModem>> WIRELESS_MODEM_ADVANCED =
|
||||
REGISTRY.register("wireless_modem_advanced", () -> TurtleUpgradeSerialiser.simpleWithCustomItem((id, item) -> new TurtleModem(id, item, true)));
|
||||
|
||||
public static final RegistryObject<TurtleUpgradeSerialiser<TurtleTool>> TOOL = REGISTRY.register("tool", () -> TurtleToolSerialiser.INSTANCE);
|
||||
public static final RegistryEntry<TurtleUpgradeSerialiser<TurtleTool>> TOOL = REGISTRY.register("tool", () -> TurtleToolSerialiser.INSTANCE);
|
||||
}
|
||||
|
||||
public static class PocketUpgradeSerialisers {
|
||||
static final DeferredRegister<PocketUpgradeSerialiser<?>> REGISTRY = DeferredRegister.create(PocketUpgradeSerialiser.REGISTRY_ID, ComputerCraft.MOD_ID);
|
||||
static final RegistrationHelper<PocketUpgradeSerialiser<?>> REGISTRY = PlatformHelper.get().createRegistrationHelper(PocketUpgradeSerialiser.REGISTRY_ID);
|
||||
|
||||
public static final RegistryObject<PocketUpgradeSerialiser<PocketSpeaker>> SPEAKER =
|
||||
public static final RegistryEntry<PocketUpgradeSerialiser<PocketSpeaker>> SPEAKER =
|
||||
REGISTRY.register("speaker", () -> PocketUpgradeSerialiser.simpleWithCustomItem(PocketSpeaker::new));
|
||||
public static final RegistryObject<PocketUpgradeSerialiser<PocketModem>> WIRELESS_MODEM_NORMAL =
|
||||
public static final RegistryEntry<PocketUpgradeSerialiser<PocketModem>> WIRELESS_MODEM_NORMAL =
|
||||
REGISTRY.register("wireless_modem_normal", () -> PocketUpgradeSerialiser.simpleWithCustomItem((id, item) -> new PocketModem(id, item, false)));
|
||||
public static final RegistryObject<PocketUpgradeSerialiser<PocketModem>> WIRELESS_MODEM_ADVANCED =
|
||||
public static final RegistryEntry<PocketUpgradeSerialiser<PocketModem>> WIRELESS_MODEM_ADVANCED =
|
||||
REGISTRY.register("wireless_modem_advanced", () -> PocketUpgradeSerialiser.simpleWithCustomItem((id, item) -> new PocketModem(id, item, true)));
|
||||
}
|
||||
|
||||
public static class Menus {
|
||||
static final DeferredRegister<MenuType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.MENU_TYPES, ComputerCraft.MOD_ID);
|
||||
static final RegistrationHelper<MenuType<?>> REGISTRY = PlatformHelper.get().createRegistrationHelper(Registry.MENU_REGISTRY);
|
||||
|
||||
public static final RegistryObject<MenuType<ContainerComputerBase>> COMPUTER = REGISTRY.register("computer",
|
||||
public static final RegistryEntry<MenuType<ContainerComputerBase>> COMPUTER = REGISTRY.register("computer",
|
||||
() -> ContainerData.toType(ComputerContainerData::new, ComputerMenuWithoutInventory::new));
|
||||
|
||||
public static final RegistryObject<MenuType<ContainerComputerBase>> POCKET_COMPUTER = REGISTRY.register("pocket_computer",
|
||||
public static final RegistryEntry<MenuType<ContainerComputerBase>> POCKET_COMPUTER = REGISTRY.register("pocket_computer",
|
||||
() -> ContainerData.toType(ComputerContainerData::new, ComputerMenuWithoutInventory::new));
|
||||
|
||||
public static final RegistryObject<MenuType<ContainerComputerBase>> POCKET_COMPUTER_NO_TERM = REGISTRY.register("pocket_computer_no_term",
|
||||
public static final RegistryEntry<MenuType<ContainerComputerBase>> POCKET_COMPUTER_NO_TERM = REGISTRY.register("pocket_computer_no_term",
|
||||
() -> ContainerData.toType(ComputerContainerData::new, ComputerMenuWithoutInventory::new));
|
||||
|
||||
public static final RegistryObject<MenuType<ContainerTurtle>> TURTLE = REGISTRY.register("turtle",
|
||||
public static final RegistryEntry<MenuType<ContainerTurtle>> TURTLE = REGISTRY.register("turtle",
|
||||
() -> ContainerData.toType(ComputerContainerData::new, ContainerTurtle::ofMenuData));
|
||||
|
||||
public static final RegistryObject<MenuType<ContainerDiskDrive>> DISK_DRIVE = REGISTRY.register("disk_drive",
|
||||
public static final RegistryEntry<MenuType<ContainerDiskDrive>> DISK_DRIVE = REGISTRY.register("disk_drive",
|
||||
() -> new MenuType<>(ContainerDiskDrive::new));
|
||||
|
||||
public static final RegistryObject<MenuType<ContainerPrinter>> PRINTER = REGISTRY.register("printer",
|
||||
public static final RegistryEntry<MenuType<ContainerPrinter>> PRINTER = REGISTRY.register("printer",
|
||||
() -> new MenuType<>(ContainerPrinter::new));
|
||||
|
||||
public static final RegistryObject<MenuType<ContainerHeldItem>> PRINTOUT = REGISTRY.register("printout",
|
||||
public static final RegistryEntry<MenuType<ContainerHeldItem>> PRINTOUT = REGISTRY.register("printout",
|
||||
() -> ContainerData.toType(HeldItemContainerData::new, ContainerHeldItem::createPrintout));
|
||||
|
||||
public static final RegistryObject<MenuType<ContainerViewComputer>> VIEW_COMPUTER = REGISTRY.register("view_computer",
|
||||
public static final RegistryEntry<MenuType<ContainerViewComputer>> VIEW_COMPUTER = REGISTRY.register("view_computer",
|
||||
() -> ContainerData.toType(ComputerContainerData::new, ContainerViewComputer::new));
|
||||
}
|
||||
|
||||
static class ArgumentTypes {
|
||||
static final DeferredRegister<ArgumentTypeInfo<?, ?>> REGISTRY = DeferredRegister.create(Registry.COMMAND_ARGUMENT_TYPE_REGISTRY, ComputerCraft.MOD_ID);
|
||||
static final RegistrationHelper<ArgumentTypeInfo<?, ?>> REGISTRY = PlatformHelper.get().createRegistrationHelper(Registry.COMMAND_ARGUMENT_TYPE_REGISTRY);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T extends ArgumentType<?>> void registerUnsafe(String name, Class<T> type, ArgumentTypeInfo<?, ?> serializer) {
|
||||
@ -327,60 +323,51 @@ public final class ModRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LootItemConditionTypes {
|
||||
static final RegistrationHelper<LootItemConditionType> REGISTRY = PlatformHelper.get().createRegistrationHelper(Registry.LOOT_ITEM_REGISTRY);
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerRegistries(NewRegistryEvent event) {
|
||||
event.create(new RegistryBuilder<TurtleUpgradeSerialiser<?>>()
|
||||
.setName(TurtleUpgradeSerialiser.REGISTRY_ID.location())
|
||||
.disableSaving().disableSync());
|
||||
public static final RegistryEntry<LootItemConditionType> BLOCK_NAMED = REGISTRY.register("block_named",
|
||||
() -> ConstantLootConditionSerializer.type(BlockNamedEntityLootCondition.INSTANCE));
|
||||
|
||||
event.create(new RegistryBuilder<PocketUpgradeSerialiser<?>>()
|
||||
.setName(PocketUpgradeSerialiser.REGISTRY_ID.location())
|
||||
.disableSaving().disableSync());
|
||||
public static final RegistryEntry<LootItemConditionType> PLAYER_CREATIVE = REGISTRY.register("player_creative",
|
||||
() -> ConstantLootConditionSerializer.type(PlayerCreativeLootCondition.INSTANCE));
|
||||
|
||||
public static final RegistryEntry<LootItemConditionType> HAS_ID = REGISTRY.register("has_id",
|
||||
() -> ConstantLootConditionSerializer.type(HasComputerIdLootCondition.INSTANCE));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerRecipeSerializers(RegisterEvent event) {
|
||||
event.register(ForgeRegistries.RECIPE_SERIALIZERS.getRegistryKey(), registry -> {
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "colour"), ColourableRecipe.SERIALIZER);
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "computer_upgrade"), ComputerUpgradeRecipe.SERIALIZER);
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "pocket_computer_upgrade"), PocketComputerUpgradeRecipe.SERIALIZER);
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "disk"), DiskRecipe.SERIALIZER);
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "printout"), PrintoutRecipe.SERIALIZER);
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "turtle"), TurtleRecipe.SERIALIZER);
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "turtle_upgrade"), TurtleUpgradeRecipe.SERIALIZER);
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "impostor_shapeless"), ImpostorShapelessRecipe.SERIALIZER);
|
||||
registry.register(new ResourceLocation(ComputerCraft.MOD_ID, "impostor_shaped"), ImpostorRecipe.SERIALIZER);
|
||||
});
|
||||
public static class RecipeSerializers {
|
||||
static final RegistrationHelper<RecipeSerializer<?>> REGISTRY = PlatformHelper.get().createRegistrationHelper(Registry.RECIPE_SERIALIZER_REGISTRY);
|
||||
|
||||
private static <T extends CustomRecipe> RegistryEntry<SimpleRecipeSerializer<T>> simple(String name, Function<ResourceLocation, T> factory) {
|
||||
return REGISTRY.register(name, () -> new SimpleRecipeSerializer<>(factory));
|
||||
}
|
||||
|
||||
public static final RegistryEntry<SimpleRecipeSerializer<ColourableRecipe>> DYEABLE_ITEM = simple("colour", ColourableRecipe::new);
|
||||
public static final RegistryEntry<TurtleRecipe.Serializer> TURTLE = REGISTRY.register("turtle", TurtleRecipe.Serializer::new);
|
||||
public static final RegistryEntry<SimpleRecipeSerializer<TurtleUpgradeRecipe>> TURTLE_UPGRADE = simple("turtle_upgrade", TurtleUpgradeRecipe::new);
|
||||
public static final RegistryEntry<SimpleRecipeSerializer<PocketComputerUpgradeRecipe>> POCKET_COMPUTER_UPGRADE = simple("pocket_computer_upgrade", PocketComputerUpgradeRecipe::new);
|
||||
public static final RegistryEntry<SimpleRecipeSerializer<PrintoutRecipe>> PRINTOUT = simple("printout", PrintoutRecipe::new);
|
||||
public static final RegistryEntry<SimpleRecipeSerializer<DiskRecipe>> DISK = simple("disk", DiskRecipe::new);
|
||||
public static final RegistryEntry<ComputerUpgradeRecipe.Serializer> COMPUTER_UPGRADE = REGISTRY.register("computer_upgrade", ComputerUpgradeRecipe.Serializer::new);
|
||||
public static final RegistryEntry<ImpostorRecipe.Serializer> IMPOSTOR_SHAPED = REGISTRY.register("impostor_shaped", ImpostorRecipe.Serializer::new);
|
||||
public static final RegistryEntry<ImpostorShapelessRecipe.Serializer> IMPOSTOR_SHAPELESS = REGISTRY.register("impostor_shapeless", ImpostorShapelessRecipe.Serializer::new);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerCapabilities(RegisterCapabilitiesEvent event) {
|
||||
event.register(IWiredElement.class);
|
||||
event.register(IPeripheral.class);
|
||||
}
|
||||
public static void register() {
|
||||
Blocks.REGISTRY.register();
|
||||
BlockEntities.REGISTRY.register();
|
||||
Items.REGISTRY.register();
|
||||
TurtleSerialisers.REGISTRY.register();
|
||||
PocketUpgradeSerialisers.REGISTRY.register();
|
||||
Menus.REGISTRY.register();
|
||||
ArgumentTypes.REGISTRY.register();
|
||||
LootItemConditionTypes.REGISTRY.register();
|
||||
RecipeSerializers.REGISTRY.register();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void init(FMLCommonSetupEvent event) {
|
||||
NetworkHandler.setup();
|
||||
|
||||
event.enqueueWork(() -> {
|
||||
registerProviders();
|
||||
registerLoot();
|
||||
});
|
||||
|
||||
ComputerCraftAPI.registerGenericSource(new InventoryMethods());
|
||||
ComputerCraftAPI.registerGenericSource(new FluidMethods());
|
||||
ComputerCraftAPI.registerGenericSource(new EnergyMethods());
|
||||
|
||||
ComputerCraftAPI.registerRefuelHandler(new FurnaceRefuelHandler());
|
||||
}
|
||||
|
||||
private static void registerProviders() {
|
||||
// Register bundled power providers
|
||||
ComputerCraftAPI.registerBundledRedstoneProvider(new DefaultBundledRedstoneProvider());
|
||||
|
||||
// Register media providers
|
||||
ComputerCraftAPI.registerRefuelHandler(new FurnaceRefuelHandler());
|
||||
ComputerCraftAPI.registerMediaProvider(stack -> {
|
||||
var item = stack.getItem();
|
||||
if (item instanceof IMedia media) return media;
|
||||
@ -388,41 +375,12 @@ public final class ModRegistry {
|
||||
return null;
|
||||
});
|
||||
|
||||
// Register generic capabilities. This can technically be done off-thread, but we need it to happen
|
||||
// after Forge's common setup, so this is easiest.
|
||||
ForgeComputerCraftAPI.registerGenericCapability(ForgeCapabilities.ITEM_HANDLER);
|
||||
ForgeComputerCraftAPI.registerGenericCapability(ForgeCapabilities.ENERGY);
|
||||
ForgeComputerCraftAPI.registerGenericCapability(ForgeCapabilities.FLUID_HANDLER);
|
||||
|
||||
VanillaDetailRegistries.ITEM_STACK.addProvider(ItemData::fill);
|
||||
VanillaDetailRegistries.BLOCK_IN_WORLD.addProvider(BlockData::fill);
|
||||
ForgeDetailRegistries.FLUID_STACK.addProvider(FluidData::fill);
|
||||
|
||||
CauldronInteraction.WATER.put(Items.TURTLE_NORMAL.get(), ItemTurtle.CAULDRON_INTERACTION);
|
||||
CauldronInteraction.WATER.put(Items.TURTLE_ADVANCED.get(), ItemTurtle.CAULDRON_INTERACTION);
|
||||
}
|
||||
|
||||
public static void registerLoot() {
|
||||
registerCondition("block_named", BlockNamedEntityLootCondition.TYPE);
|
||||
registerCondition("player_creative", PlayerCreativeLootCondition.TYPE);
|
||||
registerCondition("has_id", HasComputerIdLootCondition.TYPE);
|
||||
}
|
||||
|
||||
private static void registerCondition(String name, LootItemConditionType serializer) {
|
||||
Registry.register(
|
||||
Registry.LOOT_CONDITION_TYPE,
|
||||
new ResourceLocation(ComputerCraft.MOD_ID, name), serializer
|
||||
);
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
var bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
Blocks.REGISTRY.register(bus);
|
||||
BlockEntities.REGISTRY.register(bus);
|
||||
Items.REGISTRY.register(bus);
|
||||
TurtleSerialisers.REGISTRY.register(bus);
|
||||
PocketUpgradeSerialisers.REGISTRY.register(bus);
|
||||
Menus.REGISTRY.register(bus);
|
||||
ArgumentTypes.REGISTRY.register(bus);
|
||||
public static void registerMainThread() {
|
||||
CauldronInteraction.WATER.put(ModRegistry.Items.TURTLE_NORMAL.get(), ItemTurtle.CAULDRON_INTERACTION);
|
||||
CauldronInteraction.WATER.put(ModRegistry.Items.TURTLE_ADVANCED.get(), ItemTurtle.CAULDRON_INTERACTION);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import com.google.gson.*;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@ -17,7 +18,6 @@ import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -119,7 +119,7 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends
|
||||
var root = GsonHelper.convertToJsonObject(json, "top element");
|
||||
var serialiserId = new ResourceLocation(GsonHelper.getAsString(root, "type"));
|
||||
|
||||
var serialiser = RegistryManager.ACTIVE.getRegistry(registry).getValue(serialiserId);
|
||||
var serialiser = PlatformHelper.get().tryGetRegistryObject(registry, serialiserId);
|
||||
if (serialiser == null) throw new JsonSyntaxException("Unknown upgrade type '" + serialiserId + "'");
|
||||
|
||||
// TODO: Can we track which mod this resource came from and use that instead? It's theoretically possible,
|
||||
|
@ -9,10 +9,10 @@ import com.google.gson.JsonObject;
|
||||
import com.mojang.brigadier.Message;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -25,7 +25,7 @@ public class ArgumentUtils {
|
||||
public static <A extends ArgumentType<?>> JsonObject serializeToJson(ArgumentTypeInfo.Template<A> template) {
|
||||
var object = new JsonObject();
|
||||
object.addProperty("type", "argument");
|
||||
object.addProperty("parser", ForgeRegistries.COMMAND_ARGUMENT_TYPES.getKey(template.type()).toString());
|
||||
object.addProperty("parser", Registries.COMMAND_ARGUMENT_TYPES.getKey(template.type()).toString());
|
||||
|
||||
var properties = new JsonObject();
|
||||
serializeToJson(properties, template.type(), template);
|
||||
@ -45,12 +45,12 @@ public class ArgumentUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <A extends ArgumentType<?>, T extends ArgumentTypeInfo.Template<A>> void serializeToNetwork(FriendlyByteBuf buffer, ArgumentTypeInfo<A, T> type, ArgumentTypeInfo.Template<A> template) {
|
||||
buffer.writeRegistryIdUnsafe(ForgeRegistries.COMMAND_ARGUMENT_TYPES, type);
|
||||
Registries.writeId(buffer, Registries.COMMAND_ARGUMENT_TYPES, type);
|
||||
type.serializeToNetwork((T) template, buffer);
|
||||
}
|
||||
|
||||
public static ArgumentTypeInfo.Template<?> deserialize(FriendlyByteBuf buffer) {
|
||||
var type = buffer.readRegistryIdUnsafe(ForgeRegistries.COMMAND_ARGUMENT_TYPES);
|
||||
var type = Registries.readId(buffer, Registries.COMMAND_ARGUMENT_TYPES);
|
||||
Objects.requireNonNull(type, "Unknown argument type");
|
||||
return type.deserializeFromNetwork(buffer);
|
||||
}
|
||||
|
@ -7,7 +7,10 @@ package dan200.computercraft.shared.command.text;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
|
||||
/**
|
||||
* Various helpers for building chat messages.
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.shared.platform.RegistryEntry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
@ -20,15 +21,14 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class BlockGeneric extends BaseEntityBlock {
|
||||
private final RegistryObject<? extends BlockEntityType<? extends TileGeneric>> type;
|
||||
private final RegistryEntry<? extends BlockEntityType<? extends TileGeneric>> type;
|
||||
|
||||
public BlockGeneric(Properties settings, RegistryObject<? extends BlockEntityType<? extends TileGeneric>> type) {
|
||||
public BlockGeneric(Properties settings, RegistryEntry<? extends BlockEntityType<? extends TileGeneric>> type) {
|
||||
super(settings);
|
||||
this.type = type;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.util.ColourTracker;
|
||||
import dan200.computercraft.shared.util.ColourUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@ -12,13 +13,12 @@ import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ColourableRecipe extends CustomRecipe {
|
||||
private ColourableRecipe(ResourceLocation id) {
|
||||
public ColourableRecipe(ResourceLocation id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@ -78,8 +78,6 @@ public final class ColourableRecipe extends CustomRecipe {
|
||||
@Override
|
||||
@Nonnull
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.DYEABLE_ITEM.get();
|
||||
}
|
||||
|
||||
public static final SimpleRecipeSerializer<?> SERIALIZER = new SimpleRecipeSerializer<>(ColourableRecipe::new);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ 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.platform.RegistryEntry;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
@ -20,7 +21,6 @@ import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -29,7 +29,7 @@ public class BlockComputer<T extends TileComputer> extends BlockComputerBase<T>
|
||||
public static final EnumProperty<ComputerState> STATE = EnumProperty.create("state", ComputerState.class);
|
||||
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
||||
|
||||
public BlockComputer(Properties settings, ComputerFamily family, RegistryObject<BlockEntityType<T>> type) {
|
||||
public BlockComputer(Properties settings, ComputerFamily family, RegistryEntry<BlockEntityType<T>> type) {
|
||||
super(settings, family, type);
|
||||
registerDefaultState(defaultBlockState()
|
||||
.setValue(FACING, Direction.NORTH)
|
||||
|
@ -10,6 +10,7 @@ import dan200.computercraft.shared.common.BlockGeneric;
|
||||
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 net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@ -30,7 +31,6 @@ import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -39,10 +39,10 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
private static final ResourceLocation DROP = new ResourceLocation(ComputerCraft.MOD_ID, "computer");
|
||||
|
||||
private final ComputerFamily family;
|
||||
protected final RegistryObject<BlockEntityType<T>> type;
|
||||
protected final RegistryEntry<BlockEntityType<T>> type;
|
||||
private final BlockEntityTicker<T> serverTicker = (level, pos, state, computer) -> computer.serverTick();
|
||||
|
||||
protected BlockComputerBase(Properties settings, ComputerFamily family, RegistryObject<BlockEntityType<T>> type) {
|
||||
protected BlockComputerBase(Properties settings, ComputerFamily family, RegistryEntry<BlockEntityType<T>> type) {
|
||||
super(settings, type);
|
||||
this.family = family;
|
||||
this.type = type;
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.computer.recipe;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.items.IComputerItem;
|
||||
import net.minecraft.core.NonNullList;
|
||||
@ -15,8 +16,8 @@ import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ComputerUpgradeRecipe extends ComputerFamilyRecipe {
|
||||
public ComputerUpgradeRecipe(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family) {
|
||||
public final class ComputerUpgradeRecipe extends ComputerFamilyRecipe {
|
||||
private ComputerUpgradeRecipe(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family) {
|
||||
super(identifier, group, width, height, ingredients, result, family);
|
||||
}
|
||||
|
||||
@ -29,13 +30,13 @@ public class ComputerUpgradeRecipe extends ComputerFamilyRecipe {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get();
|
||||
}
|
||||
|
||||
public static final RecipeSerializer<ComputerUpgradeRecipe> SERIALIZER = new Serializer<>() {
|
||||
public static class Serializer extends ComputerFamilyRecipe.Serializer<ComputerUpgradeRecipe> {
|
||||
@Override
|
||||
protected ComputerUpgradeRecipe create(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family) {
|
||||
return new ComputerUpgradeRecipe(identifier, group, width, height, ingredients, result, family);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.computer.terminal;
|
||||
|
||||
import dan200.computercraft.core.terminal.Palette;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.core.terminal.Palette;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.data;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.world.Nameable;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParam;
|
||||
@ -17,11 +18,10 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A loot condition which checks if the tile entity has a name.
|
||||
* A loot condition which checks if the block entity has a name.
|
||||
*/
|
||||
public final class BlockNamedEntityLootCondition implements LootItemCondition {
|
||||
public static final BlockNamedEntityLootCondition INSTANCE = new BlockNamedEntityLootCondition();
|
||||
public static final LootItemConditionType TYPE = ConstantLootConditionSerializer.type(INSTANCE);
|
||||
public static final Builder BUILDER = () -> INSTANCE;
|
||||
|
||||
private BlockNamedEntityLootCondition() {
|
||||
@ -42,6 +42,6 @@ public final class BlockNamedEntityLootCondition implements LootItemCondition {
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootItemConditionType getType() {
|
||||
return TYPE;
|
||||
return ModRegistry.LootItemConditionTypes.BLOCK_NAMED.get();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.data;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.computer.blocks.IComputerTile;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParam;
|
||||
@ -17,11 +18,10 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A loot condition which checks if the tile entity has has a non-0 ID.
|
||||
* A loot condition which checks if the tile entity has a non-0 ID.
|
||||
*/
|
||||
public final class HasComputerIdLootCondition implements LootItemCondition {
|
||||
public static final HasComputerIdLootCondition INSTANCE = new HasComputerIdLootCondition();
|
||||
public static final LootItemConditionType TYPE = ConstantLootConditionSerializer.type(INSTANCE);
|
||||
public static final Builder BUILDER = () -> INSTANCE;
|
||||
|
||||
private HasComputerIdLootCondition() {
|
||||
@ -42,6 +42,6 @@ public final class HasComputerIdLootCondition implements LootItemCondition {
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootItemConditionType getType() {
|
||||
return TYPE;
|
||||
return ModRegistry.LootItemConditionTypes.HAS_ID.get();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.data;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParam;
|
||||
@ -21,7 +22,6 @@ import java.util.Set;
|
||||
*/
|
||||
public final class PlayerCreativeLootCondition implements LootItemCondition {
|
||||
public static final PlayerCreativeLootCondition INSTANCE = new PlayerCreativeLootCondition();
|
||||
public static final LootItemConditionType TYPE = ConstantLootConditionSerializer.type(INSTANCE);
|
||||
public static final Builder BUILDER = () -> INSTANCE;
|
||||
|
||||
private PlayerCreativeLootCondition() {
|
||||
@ -42,6 +42,6 @@ public final class PlayerCreativeLootCondition implements LootItemCondition {
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootItemConditionType getType() {
|
||||
return TYPE;
|
||||
return ModRegistry.LootItemConditionTypes.PLAYER_CREATIVE.get();
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.media.IMedia;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.common.IColouredItem;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.NonNullList;
|
||||
|
@ -9,8 +9,8 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.media.IMedia;
|
||||
import dan200.computercraft.core.filesystem.SubMount;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -5,8 +5,9 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.media.recipes;
|
||||
|
||||
import dan200.computercraft.shared.media.items.ItemDisk;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.media.items.ItemDisk;
|
||||
import dan200.computercraft.shared.util.ColourTracker;
|
||||
import dan200.computercraft.shared.util.ColourUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@ -15,7 +16,6 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
@ -83,8 +83,6 @@ public class DiskRecipe extends CustomRecipe {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.DISK.get();
|
||||
}
|
||||
|
||||
public static final SimpleRecipeSerializer<DiskRecipe> SERIALIZER = new SimpleRecipeSerializer<>(DiskRecipe::new);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.media.recipes;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
@ -12,14 +13,13 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class PrintoutRecipe extends CustomRecipe {
|
||||
private PrintoutRecipe(ResourceLocation id) {
|
||||
public PrintoutRecipe(ResourceLocation id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@ -122,8 +122,6 @@ public final class PrintoutRecipe extends CustomRecipe {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.PRINTOUT.get();
|
||||
}
|
||||
|
||||
public static final SimpleRecipeSerializer<?> SERIALIZER = new SimpleRecipeSerializer<>(PrintoutRecipe::new);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package dan200.computercraft.shared.network.client;
|
||||
|
||||
import dan200.computercraft.shared.network.NetworkMessage;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
@ -14,7 +15,6 @@ import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -46,7 +46,7 @@ public class PlayRecordClientMessage implements NetworkMessage {
|
||||
pos = buf.readBlockPos();
|
||||
if (buf.readBoolean()) {
|
||||
name = buf.readUtf(Short.MAX_VALUE);
|
||||
soundEvent = buf.readRegistryIdSafe(SoundEvent.class);
|
||||
soundEvent = Registries.readKey(buf, Registries.SOUND_EVENTS);
|
||||
} else {
|
||||
name = null;
|
||||
soundEvent = null;
|
||||
@ -61,7 +61,7 @@ public class PlayRecordClientMessage implements NetworkMessage {
|
||||
} else {
|
||||
buf.writeBoolean(true);
|
||||
buf.writeUtf(name);
|
||||
buf.writeRegistryId(ForgeRegistries.SOUND_EVENTS, soundEvent);
|
||||
Registries.writeKey(buf, Registries.SOUND_EVENTS, soundEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,12 @@ import dan200.computercraft.shared.PocketUpgrades;
|
||||
import dan200.computercraft.shared.TurtleUpgrades;
|
||||
import dan200.computercraft.shared.UpgradeManager;
|
||||
import dan200.computercraft.shared.network.NetworkMessage;
|
||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
@ -39,20 +40,22 @@ public class UpgradesLoadedMessage implements NetworkMessage {
|
||||
}
|
||||
|
||||
public UpgradesLoadedMessage(@Nonnull FriendlyByteBuf buf) {
|
||||
turtleUpgrades = fromBytes(buf, RegistryManager.ACTIVE.getRegistry(TurtleUpgradeSerialiser.REGISTRY_ID));
|
||||
pocketUpgrades = fromBytes(buf, RegistryManager.ACTIVE.getRegistry(PocketUpgradeSerialiser.REGISTRY_ID));
|
||||
turtleUpgrades = fromBytes(buf, TurtleUpgradeSerialiser.REGISTRY_ID);
|
||||
pocketUpgrades = fromBytes(buf, PocketUpgradeSerialiser.REGISTRY_ID);
|
||||
}
|
||||
|
||||
private <R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase> Map<String, UpgradeManager.UpgradeWrapper<R, T>> fromBytes(
|
||||
@Nonnull FriendlyByteBuf buf, @Nonnull IForgeRegistry<R> registry
|
||||
@Nonnull FriendlyByteBuf buf, ResourceKey<Registry<R>> registryKey
|
||||
) {
|
||||
var registry = PlatformHelper.get().wrap(registryKey);
|
||||
|
||||
var size = buf.readVarInt();
|
||||
Map<String, UpgradeManager.UpgradeWrapper<R, T>> upgrades = new HashMap<>(size);
|
||||
for (var i = 0; i < size; i++) {
|
||||
var id = buf.readUtf();
|
||||
|
||||
var serialiserId = buf.readResourceLocation();
|
||||
var serialiser = registry.getValue(serialiserId);
|
||||
var serialiser = registry.tryGet(serialiserId);
|
||||
if (serialiser == null) throw new IllegalStateException("Unknown serialiser " + serialiserId);
|
||||
|
||||
var upgrade = serialiser.fromNetwork(new ResourceLocation(id), buf);
|
||||
@ -66,13 +69,15 @@ public class UpgradesLoadedMessage implements NetworkMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(@Nonnull FriendlyByteBuf buf) {
|
||||
toBytes(buf, RegistryManager.ACTIVE.getRegistry(TurtleUpgradeSerialiser.REGISTRY_ID), turtleUpgrades);
|
||||
toBytes(buf, RegistryManager.ACTIVE.getRegistry(PocketUpgradeSerialiser.REGISTRY_ID), pocketUpgrades);
|
||||
toBytes(buf, TurtleUpgradeSerialiser.REGISTRY_ID, turtleUpgrades);
|
||||
toBytes(buf, PocketUpgradeSerialiser.REGISTRY_ID, pocketUpgrades);
|
||||
}
|
||||
|
||||
private <R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase> void toBytes(
|
||||
@Nonnull FriendlyByteBuf buf, IForgeRegistry<R> registry, Map<String, UpgradeManager.UpgradeWrapper<R, T>> upgrades
|
||||
@Nonnull FriendlyByteBuf buf, ResourceKey<Registry<R>> registryKey, Map<String, UpgradeManager.UpgradeWrapper<R, T>> upgrades
|
||||
) {
|
||||
var registry = PlatformHelper.get().wrap(registryKey);
|
||||
|
||||
buf.writeVarInt(upgrades.size());
|
||||
for (var entry : upgrades.entrySet()) {
|
||||
buf.writeUtf(entry.getKey());
|
||||
|
@ -12,8 +12,8 @@ import dan200.computercraft.api.lua.MethodResult;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IDynamicPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -27,9 +27,9 @@ class GenericPeripheral implements IDynamicPeripheral {
|
||||
private final List<SaturatedMethod> methods;
|
||||
|
||||
GenericPeripheral(BlockEntity tile, String name, Set<String> additionalTypes, List<SaturatedMethod> methods) {
|
||||
var type = ForgeRegistries.BLOCK_ENTITY_TYPES.getKey(tile.getType());
|
||||
var type = Registries.BLOCK_ENTITY_TYPES.getKey(tile.getType());
|
||||
this.tile = tile;
|
||||
this.type = name != null ? name : (type != null ? type.toString() : "unknown");
|
||||
this.type = name != null ? name : type.toString();
|
||||
this.additionalTypes = additionalTypes;
|
||||
this.methods = methods;
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
package dan200.computercraft.shared.peripheral.generic.data;
|
||||
|
||||
import dan200.computercraft.api.detail.BlockReference;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
@ -17,7 +17,7 @@ public class BlockData {
|
||||
public static void fillBasic(@Nonnull Map<? super String, Object> data, @Nonnull BlockReference block) {
|
||||
var state = block.state();
|
||||
|
||||
data.put("name", DataHelpers.getId(ForgeRegistries.BLOCKS, state.getBlock()));
|
||||
data.put("name", DataHelpers.getId(Registries.BLOCKS, state.getBlock()));
|
||||
|
||||
Map<Object, Object> stateTable = new HashMap<>();
|
||||
for (Map.Entry<Property<?>, ? extends Comparable<?>> entry : state.getValues().entrySet()) {
|
||||
|
@ -5,12 +5,11 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.peripheral.generic.data;
|
||||
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -28,9 +27,7 @@ public final class DataHelpers {
|
||||
return tags.collect(Collectors.toMap(x -> x.location().toString(), x -> true));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> String getId(@Nonnull IForgeRegistry<T> registry, T entry) {
|
||||
var id = registry.getKey(entry);
|
||||
return id == null ? null : id.toString();
|
||||
public static <T> String getId(@Nonnull Registries.RegistryWrapper<T> registry, T entry) {
|
||||
return registry.getKey(entry).toString();
|
||||
}
|
||||
}
|
||||
|
@ -5,15 +5,15 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.peripheral.generic.data;
|
||||
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Map;
|
||||
|
||||
public class FluidData {
|
||||
public static void fillBasic(@Nonnull Map<? super String, Object> data, @Nonnull FluidStack stack) {
|
||||
data.put("name", DataHelpers.getId(ForgeRegistries.FLUIDS, stack.getFluid()));
|
||||
data.put("name", DataHelpers.getId(Registries.FLUIDS, stack.getFluid()));
|
||||
data.put("amount", stack.getAmount());
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
package dan200.computercraft.shared.peripheral.generic.data;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import dan200.computercraft.shared.util.NBTUtil;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
@ -13,7 +14,6 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.EnchantedBookItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -25,7 +25,7 @@ import java.util.*;
|
||||
public class ItemData {
|
||||
@Nonnull
|
||||
public static <T extends Map<? super String, Object>> T fillBasicSafe(@Nonnull T data, @Nonnull ItemStack stack) {
|
||||
data.put("name", DataHelpers.getId(ForgeRegistries.ITEMS, stack.getItem()));
|
||||
data.put("name", DataHelpers.getId(Registries.ITEMS, stack.getItem()));
|
||||
data.put("count", stack.getCount());
|
||||
return data;
|
||||
}
|
||||
@ -154,7 +154,7 @@ public class ItemData {
|
||||
var enchantment = entry.getKey();
|
||||
var level = entry.getValue();
|
||||
var enchant = new HashMap<String, Object>(3);
|
||||
enchant.put("name", DataHelpers.getId(ForgeRegistries.ENCHANTMENTS, enchantment));
|
||||
enchant.put("name", DataHelpers.getId(Registries.ENCHANTMENTS, enchantment));
|
||||
enchant.put("level", level);
|
||||
enchant.put("displayName", enchantment.getFullname(level).getString());
|
||||
enchants.add(enchant);
|
||||
|
@ -6,9 +6,9 @@
|
||||
package dan200.computercraft.shared.peripheral.generic.methods;
|
||||
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.ResourceLocationException;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -35,7 +35,7 @@ final class ArgumentHelpers {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static <T> T getRegistryEntry(String name, String typeName, IForgeRegistry<T> registry) throws LuaException {
|
||||
public static <T> T getRegistryEntry(String name, String typeName, Registries.RegistryWrapper<T> registry) throws LuaException {
|
||||
ResourceLocation id;
|
||||
try {
|
||||
id = new ResourceLocation(name);
|
||||
@ -43,10 +43,8 @@ final class ArgumentHelpers {
|
||||
id = null;
|
||||
}
|
||||
|
||||
T value;
|
||||
if (id == null || !registry.containsKey(id) || (value = registry.getValue(id)) == null) {
|
||||
throw new LuaException(String.format("Unknown %s '%s'", typeName, name));
|
||||
}
|
||||
var value = registry.tryGet(id);
|
||||
if (id == null || value == null) throw new LuaException(String.format("Unknown %s '%s'", typeName, name));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -12,13 +12,13 @@ import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.api.peripheral.GenericPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.PeripheralType;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -94,7 +94,7 @@ public class FluidMethods implements GenericPeripheral {
|
||||
String toName, Optional<Integer> limit, Optional<String> fluidName
|
||||
) throws LuaException {
|
||||
var fluid = fluidName.isPresent()
|
||||
? getRegistryEntry(fluidName.get(), "fluid", ForgeRegistries.FLUIDS)
|
||||
? getRegistryEntry(fluidName.get(), "fluid", Registries.FLUIDS)
|
||||
: null;
|
||||
|
||||
// Find location to transfer to
|
||||
@ -134,7 +134,7 @@ public class FluidMethods implements GenericPeripheral {
|
||||
String fromName, Optional<Integer> limit, Optional<String> fluidName
|
||||
) throws LuaException {
|
||||
var fluid = fluidName.isPresent()
|
||||
? getRegistryEntry(fluidName.get(), "fluid", ForgeRegistries.FLUIDS)
|
||||
? getRegistryEntry(fluidName.get(), "fluid", Registries.FLUIDS)
|
||||
: null;
|
||||
|
||||
// Find location to transfer to
|
||||
|
@ -6,6 +6,7 @@
|
||||
package dan200.computercraft.shared.peripheral.modem.wired;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.NonNullList;
|
||||
@ -18,7 +19,6 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -61,7 +61,7 @@ public abstract class ItemBlockCable extends BlockItem {
|
||||
@Override
|
||||
public String getDescriptionId() {
|
||||
if (translationKey == null) {
|
||||
translationKey = Util.makeDescriptionId("block", ForgeRegistries.ITEMS.getKey(this));
|
||||
translationKey = Util.makeDescriptionId("block", Registries.ITEMS.getKey(this));
|
||||
}
|
||||
return translationKey;
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
package dan200.computercraft.shared.peripheral.modem.wired;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.shared.Peripherals;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.Peripherals;
|
||||
import dan200.computercraft.shared.computer.core.ServerContext;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
|
@ -19,9 +19,9 @@ import dan200.computercraft.api.peripheral.IWorkMonitor;
|
||||
import dan200.computercraft.api.peripheral.NotAttachedException;
|
||||
import dan200.computercraft.core.apis.PeripheralAPI;
|
||||
import dan200.computercraft.core.asm.PeripheralMethod;
|
||||
import dan200.computercraft.core.util.LuaUtil;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemPeripheral;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
||||
import dan200.computercraft.core.util.LuaUtil;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -7,6 +7,7 @@ package dan200.computercraft.shared.peripheral.modem.wireless;
|
||||
|
||||
import dan200.computercraft.shared.common.BlockGeneric;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemShapes;
|
||||
import dan200.computercraft.shared.platform.RegistryEntry;
|
||||
import dan200.computercraft.shared.util.WaterloggableHelpers;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@ -27,7 +28,6 @@ import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -39,7 +39,7 @@ public class BlockWirelessModem extends BlockGeneric implements SimpleWaterlogge
|
||||
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
||||
public static final BooleanProperty ON = BooleanProperty.create("on");
|
||||
|
||||
public BlockWirelessModem(Properties settings, RegistryObject<? extends BlockEntityType<? extends TileWirelessModem>> type) {
|
||||
public BlockWirelessModem(Properties settings, RegistryEntry<? extends BlockEntityType<? extends TileWirelessModem>> type) {
|
||||
super(settings, type);
|
||||
registerDefaultState(getStateDefinition().any()
|
||||
.setValue(FACING, Direction.NORTH)
|
||||
|
@ -6,6 +6,7 @@
|
||||
package dan200.computercraft.shared.peripheral.monitor;
|
||||
|
||||
import dan200.computercraft.shared.common.BlockGeneric;
|
||||
import dan200.computercraft.shared.platform.RegistryEntry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@ -22,7 +23,6 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -35,7 +35,7 @@ public class BlockMonitor extends BlockGeneric {
|
||||
|
||||
public static final EnumProperty<MonitorEdgeState> STATE = EnumProperty.create("state", MonitorEdgeState.class);
|
||||
|
||||
public BlockMonitor(Properties settings, RegistryObject<? extends BlockEntityType<? extends TileMonitor>> type) {
|
||||
public BlockMonitor(Properties settings, RegistryEntry<? extends BlockEntityType<? extends TileMonitor>> type) {
|
||||
super(settings, type);
|
||||
// TODO: Test underwater - do we need isSolid at all?
|
||||
registerDefaultState(getStateDefinition().any()
|
||||
|
@ -17,6 +17,7 @@ import dan200.computercraft.shared.network.client.SpeakerAudioClientMessage;
|
||||
import dan200.computercraft.shared.network.client.SpeakerMoveClientMessage;
|
||||
import dan200.computercraft.shared.network.client.SpeakerPlayClientMessage;
|
||||
import dan200.computercraft.shared.network.client.SpeakerStopClientMessage;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import dan200.computercraft.shared.util.PauseAwareTimer;
|
||||
import net.minecraft.ResourceLocationException;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@ -24,7 +25,6 @@ import net.minecraft.network.protocol.game.ClientboundCustomSoundPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
@ -219,7 +219,7 @@ public abstract class SpeakerPeripheral implements IPeripheral {
|
||||
|
||||
synchronized (pendingNotes) {
|
||||
if (pendingNotes.size() >= ComputerCraft.maxNotesPerTick) return false;
|
||||
pendingNotes.add(new PendingSound(ForgeRegistries.SOUND_EVENTS.getKey(instrument.getSoundEvent()), volume, (float) Math.pow(2.0, (pitch - 12.0) / 12.0)));
|
||||
pendingNotes.add(new PendingSound(Registries.SOUND_EVENTS.getKey(instrument.getSoundEvent()), volume, (float) Math.pow(2.0, (pitch - 12.0) / 12.0)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.platform;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* This extends {@linkplain dan200.computercraft.impl.PlatformHelper the API's loader abstraction layer}, adding
|
||||
* additional methods used by the actual mod.
|
||||
*/
|
||||
public interface PlatformHelper extends dan200.computercraft.impl.PlatformHelper {
|
||||
/**
|
||||
* Get the current {@link PlatformHelper} instance.
|
||||
*
|
||||
* @return The current instance.
|
||||
*/
|
||||
static PlatformHelper get() {
|
||||
return (PlatformHelper) dan200.computercraft.impl.PlatformHelper.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a Minecraft registry in our own abstraction layer.
|
||||
*
|
||||
* @param registry The registry to wrap.
|
||||
* @param <T> The type of object stored in this registry.
|
||||
* @return The wrapped registry.
|
||||
*/
|
||||
<T> Registries.RegistryWrapper<T> wrap(ResourceKey<Registry<T>> registry);
|
||||
|
||||
/**
|
||||
* Create a registration helper for a specific registry.
|
||||
*
|
||||
* @param registry The registry we'll add entries to.
|
||||
* @param <T> The type of object stored in the registry.
|
||||
* @return The registration helper.
|
||||
*/
|
||||
<T> RegistrationHelper<T> createRegistrationHelper(ResourceKey<Registry<T>> registry);
|
||||
|
||||
/**
|
||||
* A version of {@link #getRegistryObject(ResourceKey, ResourceLocation)} which allows missing entries.
|
||||
*
|
||||
* @param registry The registry to look up this object in.
|
||||
* @param id The ID to look up.
|
||||
* @param <T> The type of object the registry stores.
|
||||
* @return The registered object or {@code null}.
|
||||
*/
|
||||
@Nullable
|
||||
<T> T tryGetRegistryObject(ResourceKey<Registry<T>> registry, ResourceLocation id);
|
||||
|
||||
/**
|
||||
* Create a new block entity type which serves a particular block.
|
||||
*
|
||||
* @param factory The method which creates a new block entity with this type, typically the constructor.
|
||||
* @param block The block this block entity exists on.
|
||||
* @param <T> The type of block entity we're creating.
|
||||
* @return The new block entity type.
|
||||
*/
|
||||
<T extends BlockEntity> BlockEntityType<T> createBlockEntityType(BiFunction<BlockPos, BlockState, T> factory, Block block);
|
||||
}
|
@ -6,17 +6,30 @@
|
||||
package dan200.computercraft.shared.platform;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import dan200.computercraft.impl.PlatformHelper;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@AutoService(PlatformHelper.class)
|
||||
@AutoService(dan200.computercraft.impl.PlatformHelper.class)
|
||||
public class PlatformHelperImpl implements PlatformHelper {
|
||||
@Override
|
||||
public <T> ResourceLocation getRegistryKey(ResourceKey<Registry<T>> registry, T object) {
|
||||
@ -32,9 +45,97 @@ public class PlatformHelperImpl implements PlatformHelper {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Registries.RegistryWrapper<T> wrap(ResourceKey<Registry<T>> key) {
|
||||
return new RegistryWrapperImpl<>(key.location(), RegistryManager.ACTIVE.getRegistry(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> RegistrationHelper<T> createRegistrationHelper(ResourceKey<Registry<T>> registry) {
|
||||
return new RegistrationHelperImpl<>(DeferredRegister.create(registry, ComputerCraftAPI.MOD_ID));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <K> K tryGetRegistryObject(ResourceKey<Registry<K>> registry, ResourceLocation id) {
|
||||
return RegistryManager.ACTIVE.getRegistry(registry).getValue(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityType<T> createBlockEntityType(BiFunction<BlockPos, BlockState, T> factory, Block block) {
|
||||
return new BlockEntityType<>(factory::apply, Set.of(block), null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CompoundTag getShareTag(ItemStack item) {
|
||||
return item.getShareTag();
|
||||
}
|
||||
|
||||
private record RegistryWrapperImpl<T>(
|
||||
ResourceLocation name, ForgeRegistry<T> registry
|
||||
) implements Registries.RegistryWrapper<T> {
|
||||
@Override
|
||||
public int getId(T object) {
|
||||
var id = registry.getID(object);
|
||||
if (id == -1) throw new IllegalStateException(object + " was not registered in " + name);
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getKey(T object) {
|
||||
var key = registry.getKey(object);
|
||||
if (key == null) throw new IllegalStateException(object + " was not registered in " + name);
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(ResourceLocation location) {
|
||||
var object = registry.getValue(location);
|
||||
if (object == null) throw new IllegalStateException(location + " was not registered in " + name);
|
||||
return object;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public T tryGet(ResourceLocation location) {
|
||||
return registry.getValue(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int id) {
|
||||
var object = registry.getValue(id);
|
||||
if (object == null) throw new IllegalStateException(id + " was not registered in " + name);
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return registry.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
private record RegistrationHelperImpl<T>(DeferredRegister<T> registry) implements RegistrationHelper<T> {
|
||||
@Override
|
||||
public <U extends T> RegistryEntry<U> register(String name, Supplier<U> create) {
|
||||
return new RegistryEntryImpl<>(registry.register(name, create));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
registry.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
}
|
||||
}
|
||||
|
||||
private record RegistryEntryImpl<T>(RegistryObject<T> object) implements RegistryEntry<T> {
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return object().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return object.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.platform;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Provides a utility for registering entries in Minecraft's {@linkplain Registry registries}.
|
||||
* <p>
|
||||
* This is similar to Forge's {@code DeferredRegistry}: registration does not happen immediately, instead a reference
|
||||
* to the registered item is returned (see {@link RegistryEntry}). When registration does occur (due to an event or mod
|
||||
* initialisation), the entry is created and added to the registry.
|
||||
*
|
||||
* @param <T> The parent type of all objects in the registry, such as {@link Block}
|
||||
* @see PlatformHelper#createRegistrationHelper(ResourceKey) Obtain a new instance of this interface.
|
||||
*/
|
||||
public interface RegistrationHelper<T> {
|
||||
/**
|
||||
* Register an entry in this helper. This does <em>NOT</em> immediately register the object in the underlying
|
||||
* {@link Registry}.
|
||||
*
|
||||
* @param name The name of this entry.
|
||||
* @param create A factory method to create the entry.
|
||||
* @param <U> The type of this item in the registry.
|
||||
* @return The {@link RegistryEntry} for the registered entry.
|
||||
*/
|
||||
<U extends T> RegistryEntry<U> register(String name, Supplier<U> create);
|
||||
|
||||
/**
|
||||
* Register this helper.
|
||||
*/
|
||||
void register();
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.platform;
|
||||
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Mimics {@link Registry} but using {@link PlatformHelper}'s recipe abstractions.
|
||||
*/
|
||||
public final class Registries {
|
||||
public static final RegistryWrapper<Item> ITEMS = PlatformHelper.get().wrap(Registry.ITEM_REGISTRY);
|
||||
public static final RegistryWrapper<Block> BLOCKS = PlatformHelper.get().wrap(Registry.BLOCK_REGISTRY);
|
||||
public static final RegistryWrapper<BlockEntityType<?>> BLOCK_ENTITY_TYPES = PlatformHelper.get().wrap(Registry.BLOCK_ENTITY_TYPE_REGISTRY);
|
||||
public static final RegistryWrapper<Fluid> FLUIDS = PlatformHelper.get().wrap(Registry.FLUID_REGISTRY);
|
||||
public static final RegistryWrapper<Enchantment> ENCHANTMENTS = PlatformHelper.get().wrap(Registry.ENCHANTMENT_REGISTRY);
|
||||
public static final RegistryWrapper<ArgumentTypeInfo<?, ?>> COMMAND_ARGUMENT_TYPES = PlatformHelper.get().wrap(Registry.COMMAND_ARGUMENT_TYPE_REGISTRY);
|
||||
public static final RegistryWrapper<SoundEvent> SOUND_EVENTS = PlatformHelper.get().wrap(Registry.SOUND_EVENT_REGISTRY);
|
||||
public static final RegistryWrapper<RecipeSerializer<?>> RECIPE_SERIALIZERS = PlatformHelper.get().wrap(Registry.RECIPE_SERIALIZER_REGISTRY);
|
||||
|
||||
public interface RegistryWrapper<T> extends Iterable<T> {
|
||||
int getId(T object);
|
||||
|
||||
ResourceLocation getKey(T object);
|
||||
|
||||
T get(ResourceLocation location);
|
||||
|
||||
@Nullable
|
||||
T tryGet(ResourceLocation location);
|
||||
|
||||
T get(int id);
|
||||
}
|
||||
|
||||
private Registries() {
|
||||
}
|
||||
|
||||
public static <K> void writeId(FriendlyByteBuf buf, RegistryWrapper<K> registry, K object) {
|
||||
buf.writeVarInt(registry.getId(object));
|
||||
}
|
||||
|
||||
public static <K> K readId(FriendlyByteBuf buf, RegistryWrapper<K> registry) {
|
||||
var id = buf.readVarInt();
|
||||
return registry.get(id);
|
||||
}
|
||||
|
||||
public static <K> void writeKey(FriendlyByteBuf buf, RegistryWrapper<K> registry, K object) {
|
||||
buf.writeResourceLocation(registry.getKey(object));
|
||||
}
|
||||
|
||||
public static <K> K readKey(FriendlyByteBuf buf, RegistryWrapper<K> registry) {
|
||||
var id = buf.readResourceLocation();
|
||||
return registry.get(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.platform;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A reference to an entry in a {@link Registry}.
|
||||
*
|
||||
* @param <U> The type of the object registered.
|
||||
* @see RegistrationHelper
|
||||
*/
|
||||
public interface RegistryEntry<U> extends Supplier<U> {
|
||||
/**
|
||||
* Get the ID of this registered item.
|
||||
*
|
||||
* @return This registered item.
|
||||
*/
|
||||
ResourceLocation id();
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
package dan200.computercraft.shared.pocket.recipes;
|
||||
|
||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.PocketUpgrades;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
@ -15,13 +16,12 @@ import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class PocketComputerUpgradeRecipe extends CustomRecipe {
|
||||
private PocketComputerUpgradeRecipe(ResourceLocation identifier) {
|
||||
public PocketComputerUpgradeRecipe(ResourceLocation identifier) {
|
||||
super(identifier);
|
||||
}
|
||||
|
||||
@ -95,8 +95,6 @@ public final class PocketComputerUpgradeRecipe extends CustomRecipe {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.POCKET_COMPUTER_UPGRADE.get();
|
||||
}
|
||||
|
||||
public static final SimpleRecipeSerializer<PocketComputerUpgradeRecipe> SERIALIZER = new SimpleRecipeSerializer<>(PocketComputerUpgradeRecipe::new);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockComputerBase;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
||||
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.ITurtleItem;
|
||||
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
@ -37,7 +38,6 @@ import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -55,7 +55,7 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements Simple
|
||||
|
||||
private final BlockEntityTicker<TileTurtle> clientTicker = (level, pos, state, computer) -> computer.clientTick();
|
||||
|
||||
public BlockTurtle(Properties settings, ComputerFamily family, RegistryObject<BlockEntityType<TileTurtle>> type) {
|
||||
public BlockTurtle(Properties settings, ComputerFamily family, RegistryEntry<BlockEntityType<TileTurtle>> type) {
|
||||
super(settings, family, type);
|
||||
registerDefaultState(getStateDefinition().any()
|
||||
.setValue(FACING, Direction.NORTH)
|
||||
|
@ -13,12 +13,12 @@ import dan200.computercraft.api.lua.MethodResult;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.*;
|
||||
import dan200.computercraft.core.computer.ComputerSide;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.TurtleUpgrades;
|
||||
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||
import dan200.computercraft.core.util.Colour;
|
||||
import dan200.computercraft.shared.util.Holiday;
|
||||
import dan200.computercraft.shared.util.HolidayUtil;
|
||||
import dan200.computercraft.shared.util.InventoryDelegate;
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.turtle.recipes;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.items.IComputerItem;
|
||||
import dan200.computercraft.shared.computer.recipe.ComputerFamilyRecipe;
|
||||
@ -18,14 +19,14 @@ import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class TurtleRecipe extends ComputerFamilyRecipe {
|
||||
private TurtleRecipe(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family) {
|
||||
public TurtleRecipe(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family) {
|
||||
super(identifier, group, width, height, ingredients, result, family);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.TURTLE.get();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ -37,10 +38,10 @@ public final class TurtleRecipe extends ComputerFamilyRecipe {
|
||||
return TurtleItemFactory.create(computerID, label, -1, getFamily(), null, null, 0, null);
|
||||
}
|
||||
|
||||
public static final RecipeSerializer<TurtleRecipe> SERIALIZER = new Serializer<>() {
|
||||
public static class Serializer extends ComputerFamilyRecipe.Serializer<TurtleRecipe> {
|
||||
@Override
|
||||
protected TurtleRecipe create(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family) {
|
||||
return new TurtleRecipe(identifier, group, width, height, ingredients, result, family);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package dan200.computercraft.shared.turtle.recipes;
|
||||
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.TurtleUpgrades;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.turtle.items.ITurtleItem;
|
||||
@ -16,13 +17,12 @@ import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class TurtleUpgradeRecipe extends CustomRecipe {
|
||||
private TurtleUpgradeRecipe(ResourceLocation id) {
|
||||
public TurtleUpgradeRecipe(ResourceLocation id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@ -137,8 +137,6 @@ public final class TurtleUpgradeRecipe extends CustomRecipe {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.TURTLE_UPGRADE.get();
|
||||
}
|
||||
|
||||
public static final SimpleRecipeSerializer<TurtleUpgradeRecipe> SERIALIZER = new SimpleRecipeSerializer<>(TurtleUpgradeRecipe::new);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ package dan200.computercraft.shared.turtle.upgrades;
|
||||
import com.google.gson.JsonObject;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
||||
import dan200.computercraft.shared.platform.Registries;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@ -15,7 +16,6 @@ import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -46,7 +46,7 @@ public final class TurtleToolSerialiser implements TurtleUpgradeSerialiser<Turtl
|
||||
@Override
|
||||
public TurtleTool fromNetwork(@Nonnull ResourceLocation id, @Nonnull FriendlyByteBuf buffer) {
|
||||
var adjective = buffer.readUtf();
|
||||
var craftingItem = buffer.readRegistryIdUnsafe(ForgeRegistries.ITEMS);
|
||||
var craftingItem = Registries.readId(buffer, Registries.ITEMS);
|
||||
var toolItem = buffer.readItem();
|
||||
// damageMultiplier and breakable aren't used by the client, but we need to construct the upgrade exactly
|
||||
// as otherwise syncing on an SP world will overwrite the (shared) upgrade registry with an invalid upgrade!
|
||||
@ -59,7 +59,7 @@ public final class TurtleToolSerialiser implements TurtleUpgradeSerialiser<Turtl
|
||||
@Override
|
||||
public void toNetwork(@Nonnull FriendlyByteBuf buffer, @Nonnull TurtleTool upgrade) {
|
||||
buffer.writeUtf(upgrade.getUnlocalisedAdjective());
|
||||
buffer.writeRegistryIdUnsafe(ForgeRegistries.ITEMS, upgrade.getCraftingItem().getItem());
|
||||
Registries.writeId(buffer, Registries.ITEMS, upgrade.getCraftingItem().getItem());
|
||||
buffer.writeItem(upgrade.item);
|
||||
buffer.writeFloat(upgrade.damageMulitiplier);
|
||||
buffer.writeBoolean(upgrade.breakable != null);
|
||||
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.util;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A {@link BlockEntityType} whose supplier uses itself as an argument.
|
||||
*
|
||||
* @param <T> The type of the produced tile entity.
|
||||
*/
|
||||
public final class FixedPointTileEntityType<T extends BlockEntity> extends BlockEntityType<T> {
|
||||
private final Supplier<? extends Block> block;
|
||||
|
||||
private FixedPointTileEntityType(Supplier<? extends Block> block, BlockEntitySupplier<T> builder) {
|
||||
super(builder, Collections.emptySet(), null);
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public static <T extends BlockEntity> FixedPointTileEntityType<T> create(Supplier<? extends Block> block, FixedPointBlockEntitySupplier<T> builder) {
|
||||
return new FixedPointSupplier<>(block, builder).factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(@Nonnull BlockState block) {
|
||||
return block.getBlock() == this.block.get();
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block.get();
|
||||
}
|
||||
|
||||
private static final class FixedPointSupplier<T extends BlockEntity> implements BlockEntitySupplier<T> {
|
||||
final FixedPointTileEntityType<T> factory;
|
||||
private final FixedPointBlockEntitySupplier<T> builder;
|
||||
|
||||
private FixedPointSupplier(Supplier<? extends Block> block, FixedPointBlockEntitySupplier<T> builder) {
|
||||
factory = new FixedPointTileEntityType<>(block, this);
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public T create(@Nonnull BlockPos pos, @Nonnull BlockState state) {
|
||||
return builder.create(factory, pos, state);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FixedPointBlockEntitySupplier<T extends BlockEntity> {
|
||||
T create(BlockEntityType<T> type, BlockPos pos, BlockState state);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
package dan200.computercraft.shared.util;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@ -48,10 +49,10 @@ public final class ImpostorRecipe extends ShapedRecipe {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.IMPOSTOR_SHAPED.get();
|
||||
}
|
||||
|
||||
public static final RecipeSerializer<ImpostorRecipe> SERIALIZER = new RecipeSerializer<ImpostorRecipe>() {
|
||||
public static class Serializer implements RecipeSerializer<ImpostorRecipe> {
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImpostorRecipe fromJson(@Nonnull ResourceLocation identifier, @Nonnull JsonObject json) {
|
||||
@ -80,5 +81,5 @@ public final class ImpostorRecipe extends ShapedRecipe {
|
||||
for (var ingredient : recipe.getIngredients()) ingredient.toNetwork(buf);
|
||||
buf.writeItem(recipe.getResultItem());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ package dan200.computercraft.shared.util;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@ -50,10 +51,10 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
return ModRegistry.RecipeSerializers.IMPOSTOR_SHAPELESS.get();
|
||||
}
|
||||
|
||||
public static final RecipeSerializer<ImpostorShapelessRecipe> SERIALIZER = new RecipeSerializer<ImpostorShapelessRecipe>() {
|
||||
public static final class Serializer implements RecipeSerializer<ImpostorShapelessRecipe> {
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImpostorShapelessRecipe fromJson(@Nonnull ResourceLocation id, @Nonnull JsonObject json) {
|
||||
@ -99,5 +100,5 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe {
|
||||
for (var ingredient : recipe.getIngredients()) ingredient.toNetwork(buffer);
|
||||
buffer.writeItem(recipe.getResultItem());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user