diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/command/argument/ArgumentInfoMod.java b/loader-common/src/main/java/org/cyclops/cyclopscore/command/argument/ArgumentInfoMod.java index 38224112a7..fd366beef7 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/command/argument/ArgumentInfoMod.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/command/argument/ArgumentInfoMod.java @@ -7,7 +7,6 @@ import net.minecraft.network.FriendlyByteBuf; import org.cyclops.cyclopscore.helper.ModBaseCommon; import org.cyclops.cyclopscore.init.IModBase; -import org.cyclops.cyclopscore.network.PacketCodec; /** * A generic argument serializer for argument types with a mod property. @@ -22,7 +21,7 @@ public void serializeToNetwork(ArgumentInfoMod.Template t, FriendlyByteBuf packe @Override public ArgumentInfoMod.Template deserializeFromNetwork(FriendlyByteBuf packetBuffer) { - return new Template(ModBaseCommon.getCommon(packetBuffer.readUtf(PacketCodec.READ_STRING_MAX_LENGTH))); + return new Template(ModBaseCommon.getCommon(packetBuffer.readUtf())); } @Override diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/ConfigHandlerCommon.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/ConfigHandlerCommon.java index c34127eec1..ec7ab2a7d9 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/ConfigHandlerCommon.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/ConfigHandlerCommon.java @@ -83,22 +83,22 @@ public void loadModInit() { } /** - * Iterate over the given ExtendedConfigs and call {@link ConfigurableTypeActionCommon#onRegisterForge(ExtendedConfigCommon)} + * Iterate over the given ExtendedConfigs and call {@link ConfigurableTypeActionCommon#onRegistriesCreated(ExtendedConfigCommon)} * during the net.neoforged.neoforge.registries.NewRegistryEvent event. */ - public void loadForgeRegistries() { + public void loadRegistriesCreated() { for (ExtendedConfigCommon eConfig : this.configurables) { - eConfig.getConfigurableType().getConfigurableTypeAction().onRegisterForge(eConfig); + eConfig.getConfigurableType().getConfigurableTypeAction().onRegistriesCreated(eConfig); } } /** - * Iterate over the given ExtendedConfigs and call {@link ConfigurableTypeActionCommon#onRegisterForgeFilled(ExtendedConfigCommon)} + * Iterate over the given ExtendedConfigs and call {@link ConfigurableTypeActionCommon#onRegistriesFilled(ExtendedConfigCommon)} * during the RegisterEvent event. */ - public void loadForgeRegistriesFilled() { + public void loadRegistriesFilled() { for (ExtendedConfigCommon eConfig : this.configurables) { - eConfig.getConfigurableType().getConfigurableTypeAction().onRegisterForgeFilled(eConfig); + eConfig.getConfigurableType().getConfigurableTypeAction().onRegistriesFilled(eConfig); } } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/BlockAction.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/BlockAction.java index ed048253bc..47f1f4056d 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/BlockAction.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/BlockAction.java @@ -59,7 +59,7 @@ public static void register(@Nullable BiFunction eConfig) { + public void onRegistriesFilled(BlockConfigCommon eConfig) { // Register block and set creative tab. register(eConfig.getItemConstructor(), eConfig, () -> { eConfig.onForgeRegistered(); // Manually call after item has been registered @@ -74,7 +74,7 @@ public static void handleDynamicBlockModel(BlockConfigCommon extendedConfig) { protected void polish(BlockConfigCommon config) { // Register creative tab entry - for (ItemStack itemStack : config.getDefaultCreativeTabEntriesPublic()) { + for (ItemStack itemStack : config.getDefaultCreativeTabEntries()) { config.getMod().registerDefaultCreativeTabEntry(itemStack, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS); } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/CapabilityAction.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/CapabilityAction.java index b04939ca26..2a1c1ee265 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/CapabilityAction.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/CapabilityAction.java @@ -14,8 +14,8 @@ public class CapabilityAction extends ConfigurableTypeAct public CapabilityAction() {} @Override - public void onRegisterForge(CapabilityConfigCommon config) { - super.onRegisterForge(config); + public void onRegistriesCreated(CapabilityConfigCommon config) { + super.onRegistriesCreated(config); config.getRegistrar().apply(config); } } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConfigurableTypeActionCommon.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConfigurableTypeActionCommon.java index aa812620e1..67136e4124 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConfigurableTypeActionCommon.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConfigurableTypeActionCommon.java @@ -30,18 +30,18 @@ public void onRegisterModInit(C eConfig) { } /** - * Logic to register things right after the Forge registries have been created. + * Logic to register things right after the registries have been created. * @param eConfig The config to be registered. */ - public void onRegisterForge(C eConfig) { // TODO: rename in next major version + public void onRegistriesCreated(C eConfig) { } /** - * Logic to register things before Forge registries are being filled. + * Logic to register things before registries are being filled. * @param eConfig The config to be registered. */ - public void onRegisterForgeFilled(C eConfig) { // TODO: rename in next major version + public void onRegistriesFilled(C eConfig) { } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConfigurableTypeActionRegistry.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConfigurableTypeActionRegistry.java index 5d97f134e6..2975fa5bad 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConfigurableTypeActionRegistry.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConfigurableTypeActionRegistry.java @@ -13,7 +13,7 @@ public class ConfigurableTypeActionRegistry { @Override - public void onRegisterForgeFilled(C eConfig) { + public void onRegistriesFilled(C eConfig) { register(eConfig); } } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/EntityActionCommon.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/EntityActionCommon.java index 0090f38891..b4ee97a1f0 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/EntityActionCommon.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/EntityActionCommon.java @@ -17,7 +17,7 @@ public class EntityActionCommon extends ConfigurableTypeActionRegistry, EntityType, M> { @Override - public void onRegisterForgeFilled(EntityConfigCommon eConfig) { + public void onRegistriesFilled(EntityConfigCommon eConfig) { // Register item and set creative tab. register(eConfig, () -> { this.polish(eConfig); diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemAction.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemAction.java index d5c932c2b7..b5caf26592 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemAction.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemAction.java @@ -22,7 +22,7 @@ public class ItemAction extends ConfigurableTypeActionRegist protected static final List> MODEL_ENTRIES = Lists.newArrayList(); @Override - public void onRegisterForgeFilled(ItemConfigCommon eConfig) { + public void onRegistriesFilled(ItemConfigCommon eConfig) { // Register item and set creative tab. register(eConfig, () -> { this.polish(eConfig); @@ -37,7 +37,7 @@ public static void handleItemModel(ItemConfigCommon exte protected void polish(ItemConfigCommon config) { // Register creative tab entry - for (ItemStack itemStack : config.getDefaultCreativeTabEntriesPublic()) { + for (ItemStack itemStack : config.getDefaultCreativeTabEntries()) { config.getMod().registerDefaultCreativeTabEntry(itemStack, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS); } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/BlockConfigCommon.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/BlockConfigCommon.java index fe80decf5b..8a6f885d7a 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/BlockConfigCommon.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/BlockConfigCommon.java @@ -84,11 +84,7 @@ public ConfigurableTypeCommon getConfigurableType() { return ConfigurableTypeCommon.BLOCK; } - public Collection getDefaultCreativeTabEntriesPublic() { // TODO: rm in next major, and make other method public - return this.defaultCreativeTabEntries(); - } - - protected Collection defaultCreativeTabEntries() { + public Collection getDefaultCreativeTabEntries() { return Collections.singleton(new ItemStack(getInstance())); } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/ItemClientConfig.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/ItemClientConfig.java index eb6a6abe65..5b3c317c20 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/ItemClientConfig.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/ItemClientConfig.java @@ -2,8 +2,11 @@ import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; +import org.cyclops.cyclopscore.client.model.IDynamicModelElementCommon; import org.cyclops.cyclopscore.init.IModBase; +import javax.annotation.Nullable; + /** * @author rubensworks * @param The mod type @@ -31,4 +34,12 @@ public ModelResourceLocation registerDynamicModel() { ResourceLocation itemName = ResourceLocation.fromNamespaceAndPath(getItemConfig().getMod().getModId(), getItemConfig().getNamedId()); return new ModelResourceLocation(itemName, "inventory"); } + + /** + * @return An optional dynamic model element + */ + @Nullable + public IDynamicModelElementCommon getDynamicModelElement() { + return null; + } } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/ItemConfigCommon.java b/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/ItemConfigCommon.java index 54b7e83163..cc5b3fec97 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/ItemConfigCommon.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/config/extendedconfig/ItemConfigCommon.java @@ -50,11 +50,7 @@ public ConfigurableTypeCommon getConfigurableType() { return ConfigurableTypeCommon.ITEM; } - public Collection getDefaultCreativeTabEntriesPublic() { // TODO: rm in next major, and make other method public - return this.getDefaultCreativeTabEntries(); - } - - protected Collection getDefaultCreativeTabEntries() { + public Collection getDefaultCreativeTabEntries() { return Collections.singleton(new ItemStack(getInstance())); } diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/network/IPacketCodecRunnable.java b/loader-common/src/main/java/org/cyclops/cyclopscore/network/IPacketCodecRunnable.java new file mode 100644 index 0000000000..45b98ee89e --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/network/IPacketCodecRunnable.java @@ -0,0 +1,18 @@ +package org.cyclops.cyclopscore.network; + +import java.lang.reflect.Field; + +/** + * @author rubensworks + */ +public interface IPacketCodecRunnable { + + /** + * Run a type of codec. + * + * @param field The field annotated with {@link CodecField}. + * @param action The action that must be applied to the field. + */ + public void run(Field field, PacketCodec.ICodecAction action); + +} diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/network/PacketCodec.java b/loader-common/src/main/java/org/cyclops/cyclopscore/network/PacketCodec.java index b8807c5527..5f55063bdd 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/network/PacketCodec.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/network/PacketCodec.java @@ -4,7 +4,6 @@ import net.minecraft.network.RegistryFriendlyByteBuf; import org.cyclops.cyclopscore.datastructure.SingleCache; -import javax.annotation.Nullable; import java.lang.reflect.Field; import java.util.Arrays; import java.util.Comparator; @@ -17,34 +16,10 @@ */ public abstract class PacketCodec> extends PacketBase { - @Deprecated // TODO: rm in next major - public static final int READ_STRING_MAX_LENGTH = 32767; - public PacketCodec(Type type) { super(type); } - /** - * Register a new coded action. - * @param clazz A class type. - * @param action A codec action for the given type. - */ - @Deprecated // TODO: rm in next major - public static void addCodedAction(Class clazz, ICodecAction action) { - PacketCodecs.addCodedAction(clazz, action); - } - - @Deprecated // TODO: rm in next major - @Nullable - protected static ICodecAction getActionSuper(Class clazz) { - return PacketCodecs.getActionSuper(clazz); - } - - @Deprecated // TODO: rm in next major - public static ICodecAction getAction(Class clazz) { - return PacketCodecs.getAction(clazz); - } - protected SingleCache> fieldCache = new SingleCache>( new SingleCache.ICacheUpdater>() { @@ -85,10 +60,10 @@ public boolean isKeyEqual(Void cacheKey, Void newKey) { }); - private void loopCodecFields(ICodecRunnable runnable) { + private void loopCodecFields(IPacketCodecRunnable runnable) { for (Field field : fieldCache.get(null)) { Class clazz = field.getType(); - ICodecAction action = getAction(clazz); + ICodecAction action = PacketCodecs.getAction(clazz); // Make private fields temporarily accessible. boolean accessible = field.isAccessible(); @@ -124,28 +99,6 @@ public void decode(final RegistryFriendlyByteBuf input) { }); } - /** - * Write the given object into the packet buffer. - * @param packetBuffer A packet buffer. - * @param object An object. - */ - @Deprecated // TODO: rm in next major - public static void write(RegistryFriendlyByteBuf packetBuffer, Object object) { - PacketCodecs.write(packetBuffer, object); - } - - /** - * Read the an object of the given type from the packet buffer. - * @param The type of object. - * @param packetBuffer A packet buffer. - * @param clazz The class type to read. - * @return The read object. - */ - @Deprecated // TODO: rm in next major - public static T read(RegistryFriendlyByteBuf packetBuffer, Class clazz) { - return PacketCodecs.read(packetBuffer, clazz); - } - public static interface ICodecAction { /** @@ -164,16 +117,4 @@ public static interface ICodecAction { } - // TODO: extract to separate file in next major - public static interface ICodecRunnable { - - /** - * Run a type of codec. - * @param field The field annotated with {@link CodecField}. - * @param action The action that must be applied to the field. - */ - public void run(Field field, ICodecAction action); - - } - } diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConditionActionFabric.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConditionActionFabric.java index 9519ce5fec..c12d79964b 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConditionActionFabric.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ConditionActionFabric.java @@ -14,8 +14,8 @@ public class ConditionActionFabric extends ConfigurableTypeActionCommon, ResourceConditionType, ModBaseFabric> { @Override - public void onRegisterForge(ConditionConfigFabric eConfig) { - super.onRegisterForge(eConfig); + public void onRegistriesCreated(ConditionConfigFabric eConfig) { + super.onRegistriesCreated(eConfig); ResourceConditions.register(eConfig.getInstance()); } } diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/init/ModBaseFabric.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/init/ModBaseFabric.java index ddb14c125e..bb3e3fbbaf 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/init/ModBaseFabric.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/init/ModBaseFabric.java @@ -60,8 +60,8 @@ public void onInitialize() { this.loaded = true; getConfigHandler().loadSetup(); - getConfigHandler().loadForgeRegistries(); - getConfigHandler().loadForgeRegistriesFilled(); + getConfigHandler().loadRegistriesCreated(); + getConfigHandler().loadRegistriesFilled(); CommandRegistrationCallback.EVENT.register(this::onRegisterCommands); // Register proxy things diff --git a/loader-forge/src/main/java/org/cyclops/cyclopscore/client/model/IDynamicModelElement.java b/loader-forge/src/main/java/org/cyclops/cyclopscore/client/model/IDynamicModelElement.java deleted file mode 100644 index a4c0bc6641..0000000000 --- a/loader-forge/src/main/java/org/cyclops/cyclopscore/client/model/IDynamicModelElement.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.cyclops.cyclopscore.client.model; - -import net.minecraft.client.resources.model.BakedModel; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.ModelEvent; - -/** - * Interface for blocks and items which can have a dynamic model. - * @author rubensworks - */ -@Deprecated // TODO: rm in next major -public interface IDynamicModelElement { - - /** - * @return If this block has a dynamic model. - */ - public boolean hasDynamicModel(); - - /** - * Should return not null if {@link IDynamicModelElement#hasDynamicModel()} is true. - * This will only be called once. - * @param event The model bake event. - * @return A dynamic model instance. - */ - @OnlyIn(Dist.CLIENT) - public BakedModel createDynamicModel(ModelEvent.ModifyBakingResult event); - -} diff --git a/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/BlockActionForge.java b/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/BlockActionForge.java index 921fc9a849..09a8ca8a86 100644 --- a/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/BlockActionForge.java +++ b/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/BlockActionForge.java @@ -8,7 +8,6 @@ import net.minecraftforge.client.event.RegisterColorHandlersEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.commons.lang3.tuple.Pair; -import org.cyclops.cyclopscore.client.model.IDynamicModelElement; import org.cyclops.cyclopscore.client.model.IDynamicModelElementCommon; import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon; import org.cyclops.cyclopscore.helper.ModHelpersForge; @@ -32,12 +31,6 @@ protected void polish(BlockConfigCommon config) { super.polish(config); if(config.getMod().getModHelpers().getMinecraftHelpers().isClientSide()) { - // Handle dynamic models - if(config.getInstance() instanceof IDynamicModelElement && - ((IDynamicModelElement) config.getInstance()).hasDynamicModel()) { - BlockAction.handleDynamicBlockModel(config); - } - IDynamicModelElementCommon dynamicModelElement = config.getBlockClientConfig().getDynamicModelElement(); if (dynamicModelElement != null) { BlockAction.handleDynamicBlockModel(config); @@ -58,13 +51,8 @@ public static void onModelRegistryLoad(ModelEvent.RegisterModelStateDefinitions public static void onModelBakeEvent(ModelEvent.ModifyBakingResult event){ for (BlockConfigCommon config : MODEL_ENTRIES) { BakedModel dynamicModel; - if (config.getInstance() instanceof IDynamicModelElement) { - IDynamicModelElement dynamicModelElement = (IDynamicModelElement) config.getInstance(); - dynamicModel = dynamicModelElement.createDynamicModel(event); - } else { - IDynamicModelElementCommon dynamicModelElement = config.getBlockClientConfig().getDynamicModelElement(); - dynamicModel = dynamicModelElement.createDynamicModel(pair -> event.getResults().blockStateModels().put(pair.getLeft(), pair.getRight())); - } + IDynamicModelElementCommon dynamicModelElement = config.getBlockClientConfig().getDynamicModelElement(); + dynamicModel = dynamicModelElement.createDynamicModel(pair -> event.getResults().blockStateModels().put(pair.getLeft(), pair.getRight())); if (config.getBlockClientConfig().dynamicBlockVariantLocation != null) { event.getResults().blockStateModels().put(config.getBlockClientConfig().dynamicBlockVariantLocation, dynamicModel); } diff --git a/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/FluidActionForge.java b/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/FluidActionForge.java index 8ff5c4c79d..2420af00cb 100644 --- a/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/FluidActionForge.java +++ b/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/FluidActionForge.java @@ -45,7 +45,7 @@ public List>> get() { private boolean registryEventPassed = false; @Override - public void onRegisterForge(FluidConfigForge config) { + public void onRegistriesCreated(FluidConfigForge config) { if (this.registryEventPassed) { throw new IllegalStateException(String.format("Tried registering %s after its registration event.", config.getNamedId())); diff --git a/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemActionForge.java b/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemActionForge.java index a0783273d4..ef43726360 100644 --- a/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemActionForge.java +++ b/loader-forge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemActionForge.java @@ -4,7 +4,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.ModelEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import org.cyclops.cyclopscore.client.model.IDynamicModelElement; +import org.cyclops.cyclopscore.client.model.IDynamicModelElementCommon; import org.cyclops.cyclopscore.config.extendedconfig.ItemConfigCommon; import org.cyclops.cyclopscore.helper.ModHelpersForge; import org.cyclops.cyclopscore.init.ModBaseForge; @@ -26,9 +26,8 @@ protected void polish(ItemConfigCommon config) { super.polish(config); if(config.getMod().getModHelpers().getMinecraftHelpers().isClientSide()) { - // Handle dynamic models - if(config.getInstance() instanceof IDynamicModelElement && - ((IDynamicModelElement) config.getInstance()).hasDynamicModel()) { + IDynamicModelElementCommon dynamicModelElement = config.getItemClientConfig().getDynamicModelElement(); + if (dynamicModelElement != null) { ItemAction.handleItemModel(config); } } @@ -44,9 +43,9 @@ public static void onModelRegistryLoad(ModelEvent.RegisterModelStateDefinitions @OnlyIn(Dist.CLIENT) public static void onModelBakeEvent(ModelEvent.ModifyBakingResult event){ for (ItemConfigCommon config : MODEL_ENTRIES) { - IDynamicModelElement dynamicModelElement = (IDynamicModelElement) config.getInstance(); + IDynamicModelElementCommon dynamicModelElement = config.getItemClientConfig().getDynamicModelElement(); if (config.getItemClientConfig().dynamicItemVariantLocation != null) { - event.getResults().blockStateModels().put(config.getItemClientConfig().dynamicItemVariantLocation, dynamicModelElement.createDynamicModel(event)); + event.getResults().blockStateModels().put(config.getItemClientConfig().dynamicItemVariantLocation, dynamicModelElement.createDynamicModel(pair -> event.getResults().blockStateModels().put(pair.getLeft(), pair.getRight()))); } } } diff --git a/loader-forge/src/main/java/org/cyclops/cyclopscore/init/ModBaseForge.java b/loader-forge/src/main/java/org/cyclops/cyclopscore/init/ModBaseForge.java index 12e66b77ea..d1312d6041 100644 --- a/loader-forge/src/main/java/org/cyclops/cyclopscore/init/ModBaseForge.java +++ b/loader-forge/src/main/java/org/cyclops/cyclopscore/init/ModBaseForge.java @@ -105,7 +105,7 @@ public IEventBus getModEventBus() { } protected PacketHandlerForge constructPacketHandler() { - return new PacketHandlerForge(this); // TODO + return new PacketHandlerForge(this); } @Override @@ -153,7 +153,7 @@ protected void setupClient(FMLClientSetupEvent event) { * @param event The Forge registry creation event. */ private void afterRegistriesCreated(NewRegistryEvent event) { - getConfigHandler().loadForgeRegistries(); + getConfigHandler().loadRegistriesCreated(); } /** @@ -163,7 +163,7 @@ private void afterRegistriesCreated(NewRegistryEvent event) { private void beforeRegistriedFilled(RegisterEvent event) { if (event.getRegistryKey().equals(ForgeRegistries.SOUND_EVENTS.getRegistryKey())) { // We only need to call this once, and the SOUND_EVENTS event is emitted first. - getConfigHandler().loadForgeRegistriesFilled(); + getConfigHandler().loadRegistriesFilled(); } } diff --git a/loader-forge/src/main/java/org/cyclops/cyclopscore/neywork/PacketHandlerForge.java b/loader-forge/src/main/java/org/cyclops/cyclopscore/neywork/PacketHandlerForge.java index 557d0bc621..5cad7c70ce 100644 --- a/loader-forge/src/main/java/org/cyclops/cyclopscore/neywork/PacketHandlerForge.java +++ b/loader-forge/src/main/java/org/cyclops/cyclopscore/neywork/PacketHandlerForge.java @@ -21,7 +21,6 @@ import org.cyclops.cyclopscore.init.ModBaseForge; import org.cyclops.cyclopscore.network.IPacketHandler; import org.cyclops.cyclopscore.network.PacketBase; -import org.jetbrains.annotations.Nullable; import java.util.List; @@ -120,14 +119,4 @@ public void sendToAll(PacketBase packet) { networkChannel.send(packet, PacketDistributor.ALL.noArg()); } - @Deprecated // TODO: rm in next major - public static class PacketCodecException extends RuntimeException { - public PacketCodecException(String message, Throwable cause) { - super(message, cause); - } - } - - @Deprecated // TODO: rm in next major - public static record TargetPoint(ServerLevel level, double x, double y, double z, double radius, @Nullable ServerPlayer excluded) {} - } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/RegistryEntries.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/RegistryEntries.java index 15411484c1..4f78f6c457 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/RegistryEntries.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/RegistryEntries.java @@ -8,7 +8,7 @@ import net.neoforged.neoforge.fluids.SimpleFluidContent; import net.neoforged.neoforge.registries.DeferredHolder; import org.cyclops.cyclopscore.infobook.test.ContainerInfoBookTest; -import org.cyclops.cyclopscore.inventory.SimpleInventory; +import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon; /** * Referenced registry entries. @@ -24,6 +24,6 @@ public class RegistryEntries { public static final DeferredHolder, DataComponentType> COMPONENT_CAPACITY = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("cyclopscore:capacity")); public static final DeferredHolder, DataComponentType> COMPONENT_ENERGY_STORAGE = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("cyclopscore:energy_storage")); public static final DeferredHolder, DataComponentType> COMPONENT_FLUID_CONTENT = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("cyclopscore:fluid_content")); - public static final DeferredHolder, DataComponentType> COMPONENT_INVENTORY = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("cyclopscore:inventory")); + public static final DeferredHolder, DataComponentType> COMPONENT_INVENTORY = DeferredHolder.create(Registries.DATA_COMPONENT_TYPE, ResourceLocation.parse("cyclopscore:inventory")); } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/gui/container/ContainerScreenScrolling.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/gui/container/ContainerScreenScrolling.java deleted file mode 100644 index 6da220daa8..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/gui/container/ContainerScreenScrolling.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.cyclops.cyclopscore.client.gui.container; - -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.inventory.Slot; -import org.cyclops.cyclopscore.client.gui.component.WidgetScrollBar; -import org.cyclops.cyclopscore.client.gui.component.input.WidgetTextFieldExtended; -import org.cyclops.cyclopscore.inventory.container.ScrollingInventoryContainer; -import org.lwjgl.glfw.GLFW; - -import java.awt.*; - -/** - * Gui for an inventory container that has a scrollbar and search field. - * @author rubensworks - */ -@Deprecated // TODO: rm in next major -public abstract class ContainerScreenScrolling extends ContainerScreenExtended { - - private static final int SEARCH_WIDTH = 89; - - private WidgetTextFieldExtended searchField = null; - private WidgetScrollBar scrollbar = null; - - public ContainerScreenScrolling(T container, Inventory playerInventory, Component title) { - super(container, playerInventory, title); - } - - @Override - public void init() { - super.init(); - - if(isSearchEnabled()) { - int searchWidth = getSearchWidth(); - int searchX = getSearchX(); - int searchY = getSearchY(); - if(this.searchField == null) { - this.searchField = new WidgetTextFieldExtended(this.font, this.leftPos + searchX, this.topPos + searchY, searchWidth, this.font.lineHeight, Component.translatable("gui.cyclopscore.search")); - this.searchField.setMaxLength(64); - this.searchField.setMaxLength(15); - this.searchField.setBordered(false); - this.searchField.setVisible(true); - this.searchField.setTextColor(16777215); - this.searchField.setCanLoseFocus(true); - this.searchField.setValue(""); - this.searchField.setWidth(searchWidth); - this.searchField.setX(this.leftPos + (searchX + searchWidth) - this.searchField.getWidth()); - } else { - this.searchField.setWidth(searchWidth); - this.searchField.setX(this.leftPos + (searchX + searchWidth) - this.searchField.getWidth()); - this.searchField.setY(this.topPos + searchY); - } - this.addWidget(this.searchField); - } - - // Initial element load. - if (scrollbar == null) { - getMenu().updateFilter(""); - this.scrollbar = new WidgetScrollBar(this.leftPos + getScrollX(), this.topPos + getScrollY(), getScrollHeight(), - Component.translatable("gui.cyclopscore.scrollbar"), getMenu(), - getMenu().getPageSize(), getScrollRegion()); - this.scrollbar.setTotalRows(getMenu().getFilteredItemCount() / getMenu().getColumns()); - } - - this.addWidget(this.scrollbar); - getScrollbar().scrollTo(this.scrollbar.getCurrentScroll()); - } - - /** - * @return A custom region in which scrolling should also be allowed next to the scrollbar itself. - */ - protected Rectangle getScrollRegion() { - return null; - } - - @Override - public boolean charTyped(char typedChar, int keyCode) { - if (isSearchEnabled() && this.searchField.isFocused()) { - if (this.searchField.charTyped(typedChar, keyCode)) { - this.updateSearch(searchField.getValue()); - } - return true; - } else { - return super.charTyped(typedChar, keyCode); - } - } - - @Override - public boolean keyPressed(int typedChar, int keyCode, int modifiers) { - if (isSearchEnabled() && this.searchField.isFocused() && typedChar != GLFW.GLFW_KEY_ESCAPE) { - if (this.searchField.keyPressed(typedChar, keyCode, modifiers)) { - this.updateSearch(searchField.getValue()); - } - return true; - } else { - return super.keyPressed(typedChar, keyCode, modifiers); - } - } - - @Override - protected void drawCurrentScreen(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { - if (isSubsetRenderSlots()) { - // Temporarily swap slot list, to avoid rendering all slots (which would include the hidden ones) - NonNullList oldSlots = this.container.slots; - int startIndex = getMenu().getFirstElement(); - NonNullList newSlots = NonNullList.create(); - newSlots.addAll(oldSlots.subList(startIndex, Math.min(oldSlots.size(), startIndex - + (getMenu().getPageSize() * getMenu().getColumns())))); - newSlots.addAll(oldSlots.subList(getMenu().getUnfilteredItemCount(), oldSlots.size())); - this.container.slots = newSlots; - super.drawCurrentScreen(guiGraphics, mouseX, mouseY, partialTicks); - this.container.slots = oldSlots; - } else { - super.drawCurrentScreen(guiGraphics, mouseX, mouseY, partialTicks); - } - } - - /** - * @return If the optimization should be done for only rendering the visible slots. Default: false - */ - protected boolean isSubsetRenderSlots() { - return false; - } - - @Override - protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) { - super.renderBg(guiGraphics, partialTicks, mouseX, mouseY); - if(isSearchEnabled()) this.searchField.render(guiGraphics, mouseX, mouseY, partialTicks); - this.scrollbar.renderWidget(guiGraphics, mouseX, mouseY, partialTicks); - } - - @Override - public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double mouseXPrev, double mouseYPrev) { - if (this.getFocused() != null && this.isDragging() && mouseButton == 0 - && this.getFocused().mouseDragged(mouseX, mouseY, mouseButton, mouseXPrev, mouseYPrev)) { - return true; - } - return super.mouseDragged(mouseX, mouseY, mouseButton, mouseXPrev, mouseYPrev); - } - - protected void updateSearch(String searchString) { - getMenu().updateFilter(searchString); - this.scrollbar.setTotalRows(getMenu().getFilteredItemCount() / getMenu().getColumns()); - this.scrollbar.scrollTo(0); - } - - public EditBox getSearchField() { - return searchField; - } - - public WidgetScrollBar getScrollbar() { - return scrollbar; - } - - protected int getScrollX() { - return 175; - } - - protected int getScrollY() { - return 18; - } - - protected int getScrollHeight() { - return 112; - } - - protected boolean isSearchEnabled() { - return true; - } - - protected int getSearchX() { - return 82; - } - - protected int getSearchY() { - return 6; - } - - protected int getSearchWidth() { - return SEARCH_WIDTH; - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/model/IDynamicModelElement.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/model/IDynamicModelElement.java deleted file mode 100644 index 31d402a1bf..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/model/IDynamicModelElement.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.cyclops.cyclopscore.client.model; - -import net.minecraft.client.resources.model.BakedModel; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.client.event.ModelEvent; - -/** - * Interface for blocks and items which can have a dynamic model. - * @author rubensworks - */ -@Deprecated // TODO: rm in next major -public interface IDynamicModelElement { - - /** - * @return If this block has a dynamic model. - */ - public boolean hasDynamicModel(); - - /** - * Should return not null if {@link IDynamicModelElement#hasDynamicModel()} is true. - * This will only be called once. - * @param event The model bake event. - * @return A dynamic model instance. - */ - @OnlyIn(Dist.CLIENT) - public BakedModel createDynamicModel(ModelEvent.ModifyBakingResult event); - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/component/DataComponentInventoryConfig.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/component/DataComponentInventoryConfig.java index a8e9b5ea20..5cfc68520e 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/component/DataComponentInventoryConfig.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/component/DataComponentInventoryConfig.java @@ -3,15 +3,15 @@ import org.cyclops.cyclopscore.CyclopsCoreNeoForge; import org.cyclops.cyclopscore.config.extendedconfig.DataComponentConfigCommon; import org.cyclops.cyclopscore.init.ModBaseNeoForge; -import org.cyclops.cyclopscore.inventory.SimpleInventory; +import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon; /** * @author rubensworks */ -public class DataComponentInventoryConfig extends DataComponentConfigCommon> { +public class DataComponentInventoryConfig extends DataComponentConfigCommon> { public DataComponentInventoryConfig() { super(CyclopsCoreNeoForge._instance, "inventory", builder -> builder - .persistent(SimpleInventory.CODEC) - .networkSynchronized(SimpleInventory.STREAM_CODEC)); + .persistent(SimpleInventoryCommon.CODEC) + .networkSynchronized(SimpleInventoryCommon.STREAM_CODEC)); } } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/FluidActionNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/FluidActionNeoForge.java index 81f8478d8e..e4818efc4e 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/FluidActionNeoForge.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/FluidActionNeoForge.java @@ -45,7 +45,7 @@ public List>> get() { private boolean registryEventPassed = false; @Override - public void onRegisterForge(FluidConfigNeoForge config) { + public void onRegistriesCreated(FluidConfigNeoForge config) { if (this.registryEventPassed) { throw new IllegalStateException(String.format("Tried registering %s after its registration event.", config.getNamedId())); diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemActionNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemActionNeoForge.java index 3ab2259315..51b314fb58 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemActionNeoForge.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/config/configurabletypeaction/ItemActionNeoForge.java @@ -6,7 +6,7 @@ import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.client.event.ModelEvent; import org.cyclops.cyclopscore.Reference; -import org.cyclops.cyclopscore.client.model.IDynamicModelElement; +import org.cyclops.cyclopscore.client.model.IDynamicModelElementCommon; import org.cyclops.cyclopscore.config.extendedconfig.ItemConfigCommon; import org.cyclops.cyclopscore.init.ModBaseNeoForge; @@ -21,9 +21,8 @@ protected void polish(ItemConfigCommon config) { super.polish(config); if(config.getMod().getModHelpers().getMinecraftHelpers().isClientSide()) { - // Handle dynamic models - if(config.getInstance() instanceof IDynamicModelElement && - ((IDynamicModelElement) config.getInstance()).hasDynamicModel()) { + IDynamicModelElementCommon dynamicModelElement = config.getItemClientConfig().getDynamicModelElement(); + if (dynamicModelElement != null) { ItemAction.handleItemModel(config); } } @@ -41,9 +40,9 @@ public static void onModelRegistryLoad(ModelEvent.RegisterAdditional event) { @SubscribeEvent public static void onModelBakeEvent(ModelEvent.ModifyBakingResult event){ for (ItemConfigCommon config : MODEL_ENTRIES) { - IDynamicModelElement dynamicModelElement = (IDynamicModelElement) config.getInstance(); + IDynamicModelElementCommon dynamicModelElement = config.getItemClientConfig().getDynamicModelElement(); if (config.getItemClientConfig().dynamicItemVariantLocation != null) { - event.getBakingResult().blockStateModels().put(config.getItemClientConfig().dynamicItemVariantLocation, dynamicModelElement.createDynamicModel(event)); + event.getBakingResult().blockStateModels().put(config.getItemClientConfig().dynamicItemVariantLocation, dynamicModelElement.createDynamicModel(pair -> event.getBakingResult().blockStateModels().put(pair.getLeft(), pair.getRight()))); } } } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/InfoBookParser.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/InfoBookParser.java index 6f1b3d1595..dfca659bb3 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/InfoBookParser.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/InfoBookParser.java @@ -52,13 +52,6 @@ public class InfoBookParser { // Infosection factories registerSectionFactory("", new IInfoSectionFactory() { - @Override - public InfoSection create(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey, - ArrayList paragraphs, List appendixes, - ArrayList tagList) { - return this.create(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList, null); - } - @Override public InfoSection create(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey, ArrayList paragraphs, List appendixes, @@ -707,16 +700,9 @@ protected static IReward createReward(IInfoBook infoBook, String type, Element n public static interface IInfoSectionFactory { - @Deprecated // TODO: RM in next major MC version public InfoSection create(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey, ArrayList paragraphs, List appendixes, - ArrayList tagList); - - public default InfoSection create(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey, - ArrayList paragraphs, List appendixes, - ArrayList tagList, ModBaseNeoForge mod) { - return this.create(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList); - } + ArrayList tagList, ModBaseNeoForge mod); } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/InfoSection.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/InfoSection.java index c83bb2e4d1..394ca78edb 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/InfoSection.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/InfoSection.java @@ -62,12 +62,6 @@ public InfoSection(IInfoBook infoBook, InfoSection parent, int childIndex, Strin this.tagList = tagList; } - @Deprecated // TODO: RM in next major MC version - public InfoSection(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey, - List paragraphs, List appendixes, ArrayList tagList) { - this(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList, null); - } - public String getRelativeWebPath() { if (isRoot()) { return ""; diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/ScreenInfoBook.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/ScreenInfoBook.java index 2cad73650c..3fd72235c3 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/ScreenInfoBook.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/ScreenInfoBook.java @@ -22,7 +22,7 @@ import org.apache.logging.log4j.Level; import org.cyclops.cyclopscore.CyclopsCoreNeoForge; import org.cyclops.cyclopscore.helper.IModHelpers; -import org.cyclops.cyclopscore.inventory.container.ContainerExtended; +import org.cyclops.cyclopscore.inventory.container.ContainerExtendedCommon; import org.cyclops.cyclopscore.network.packet.RequestPlayerNbtPacket; import org.lwjgl.opengl.GL11; @@ -32,7 +32,7 @@ * Base gui for {@link IInfoBook}. * @author rubensworks */ -public abstract class ScreenInfoBook extends AbstractContainerScreen { +public abstract class ScreenInfoBook extends AbstractContainerScreen { private static final int HR_WIDTH = 88; private static final int HR_HEIGHT = 10; diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/test/ContainerInfoBookTest.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/test/ContainerInfoBookTest.java index d774375d51..900cacf3e4 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/test/ContainerInfoBookTest.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/test/ContainerInfoBookTest.java @@ -1,16 +1,16 @@ package org.cyclops.cyclopscore.infobook.test; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.SimpleContainer; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; import org.cyclops.cyclopscore.RegistryEntries; -import org.cyclops.cyclopscore.inventory.container.InventoryContainer; +import org.cyclops.cyclopscore.inventory.container.InventoryContainerCommon; /** * Container for the test book. * @author rubensworks */ -public class ContainerInfoBookTest extends InventoryContainer { +public class ContainerInfoBookTest extends InventoryContainerCommon { public ContainerInfoBookTest(int id, Inventory inventory, FriendlyByteBuf packetBuffer) { this(id, inventory); diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/test/ContainerInfoBookTestConfig.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/test/ContainerInfoBookTestConfig.java index ba0160b314..336be90823 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/test/ContainerInfoBookTestConfig.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/infobook/test/ContainerInfoBookTestConfig.java @@ -4,7 +4,7 @@ import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigCommon; import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigScreenFactoryProvider; import org.cyclops.cyclopscore.init.IModBase; -import org.cyclops.cyclopscore.inventory.container.ContainerTypeData; +import org.cyclops.cyclopscore.inventory.container.ContainerTypeDataCommon; /** * Config for {@link ContainerInfoBookTest}. @@ -15,7 +15,7 @@ public class ContainerInfoBookTestConfig extends GuiConfigCo public ContainerInfoBookTestConfig(M mod) { super(mod, "test_infobook", - eConfig -> new ContainerTypeData<>(ContainerInfoBookTest::new, FeatureFlags.VANILLA_SET)); + eConfig -> new ContainerTypeDataCommon<>(ContainerInfoBookTest::new, FeatureFlags.VANILLA_SET)); } @Override diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/init/ModBaseNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/init/ModBaseNeoForge.java index f46486a75f..9cb9830d04 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/init/ModBaseNeoForge.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/init/ModBaseNeoForge.java @@ -278,7 +278,7 @@ protected void onRegisterKeyMappings(RegisterKeyMappingsEvent event) { * @param event The Forge registry creation event. */ private void afterRegistriesCreated(NewRegistryEvent event) { - getConfigHandler().loadForgeRegistries(); + getConfigHandler().loadRegistriesCreated(); } /** @@ -288,7 +288,7 @@ private void afterRegistriesCreated(NewRegistryEvent event) { private void beforeRegistriedFilled(RegisterEvent event) { if (event.getRegistryKey().equals(BuiltInRegistries.ATTRIBUTE.key())) { // We only need to call this once, and the ATTRIBUTE event is emitted first. - getConfigHandler().loadForgeRegistriesFilled(); + getConfigHandler().loadRegistriesFilled(); } } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/IndexedInventory.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/IndexedInventory.java index b12d55d4cb..83fc061d14 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/IndexedInventory.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/IndexedInventory.java @@ -19,7 +19,7 @@ * */ @Deprecated // TODO: rm in next major, after porting IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference -public class IndexedInventory extends LargeInventory implements IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference { +public class IndexedInventory extends LargeInventoryCommon implements IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference { private final Map> index = Maps.newIdentityHashMap(); private IntSet emptySlots; diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/LargeInventory.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/LargeInventory.java deleted file mode 100644 index 195bb0fa8c..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/LargeInventory.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.cyclops.cyclopscore.inventory; - -import net.minecraft.core.HolderLookup; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.world.item.ItemStack; - -/** - * A large inventory implementation. - * @author rubensworks - * - */ -@Deprecated // TODO: rm in next major -public class LargeInventory extends SimpleInventory { - - /** - * Default constructor for NBT persistence, don't call this yourself. - */ - public LargeInventory() { - this(0, 0); - } - - /** - * Make a new instance. - * @param size The amount of slots in the inventory. - * @param stackLimit The stack limit for each slot. - */ - public LargeInventory(int size, int stackLimit) { - super(size, stackLimit); - } - - public void readFromNBT(HolderLookup.Provider provider, CompoundTag data, String tag) { - ListTag nbttaglist = data.getList(tag, Tag.TAG_COMPOUND); - - for (int j = 0; j < getContainerSize(); ++j) - contents[j] = ItemStack.EMPTY; - - for (int j = 0; j < nbttaglist.size(); ++j) { - CompoundTag slot = nbttaglist.getCompound(j); - int index; - if (slot.contains("index")) { - index = slot.getInt("index"); - } else { - index = slot.getInt("Slot"); - } - if (index >= 0 && index < getContainerSize()) { - contents[index] = ItemStack.parseOptional(provider, slot); - } - } - } - - public void writeToNBT(HolderLookup.Provider provider, CompoundTag data, String tag) { - ListTag slots = new ListTag(); - for (int index = 0; index < getContainerSize(); ++index) { - ItemStack itemStack = getItem(index); - if (!itemStack.isEmpty() && itemStack.getCount() > 0) { - CompoundTag slot = new CompoundTag(); - slot.putInt("Slot", index); - slots.add(itemStack.save(provider, slot)); - } - } - data.put(tag, slots); - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/NBTSimpleInventoryItemHeld.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/NBTSimpleInventoryItemHeld.java index 7d0beefc28..5b9acacbbd 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/NBTSimpleInventoryItemHeld.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/NBTSimpleInventoryItemHeld.java @@ -12,7 +12,7 @@ * @author rubensworks * */ -public class NBTSimpleInventoryItemHeld extends SimpleInventory { +public class NBTSimpleInventoryItemHeld extends SimpleInventoryCommon { protected final Player player; protected final ItemLocation itemLocation; @@ -34,7 +34,7 @@ public NBTSimpleInventoryItemHeld(Player player, ItemLocation itemLocation, int this.tagName = tagName; ItemStack itemStack = itemLocation.getItemStack(player); - SimpleInventory contents = itemStack.get(RegistryEntries.COMPONENT_INVENTORY); + SimpleInventoryCommon contents = itemStack.get(RegistryEntries.COMPONENT_INVENTORY); if (contents != null) { for (int i = 0; i < contents.getContainerSize(); i++) { setItem(i, contents.getItem(i)); diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/NBTSimpleInventoryItemStack.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/NBTSimpleInventoryItemStack.java index 67cd529821..7cb346a7fe 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/NBTSimpleInventoryItemStack.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/NBTSimpleInventoryItemStack.java @@ -11,7 +11,7 @@ * @author rubensworks * */ -public class NBTSimpleInventoryItemStack extends SimpleInventory { +public class NBTSimpleInventoryItemStack extends SimpleInventoryCommon { protected final ItemStack itemStack; protected final String tagName; @@ -29,7 +29,7 @@ public NBTSimpleInventoryItemStack(ItemStack itemStack, int size, int stackLimit this.itemStack = itemStack; this.tagName = tagName; - SimpleInventory contents = itemStack.get(RegistryEntries.COMPONENT_INVENTORY); + SimpleInventoryCommon contents = itemStack.get(RegistryEntries.COMPONENT_INVENTORY); if (contents != null) { for (int i = 0; i < contents.getContainerSize(); i++) { setItem(i, contents.getItem(i)); diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/SimpleInventory.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/SimpleInventory.java deleted file mode 100644 index 14bb91cba8..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/SimpleInventory.java +++ /dev/null @@ -1,321 +0,0 @@ -package org.cyclops.cyclopscore.inventory; - -import com.google.common.collect.Lists; -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.core.Direction; -import net.minecraft.core.HolderLookup; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.world.WorldlyContainer; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.items.IItemHandler; -import net.neoforged.neoforge.items.wrapper.InvWrapper; -import net.neoforged.neoforge.items.wrapper.SidedInvWrapper; -import org.cyclops.cyclopscore.persist.IDirtyMarkListener; - -import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.stream.IntStream; - -/** - * A basic inventory implementation. - * @author rubensworks - * - */ -@Deprecated // TODO: rm in next major -public class SimpleInventory implements INBTInventory, WorldlyContainer { - - public static final Codec CODEC = RecordCodecBuilder.create((builder) -> builder - .group(Codec.INT.fieldOf("size").forGetter(SimpleInventory::getContainerSize), - Codec.INT.fieldOf("stackLimit").forGetter(SimpleInventory::getMaxStackSize), - ItemStack.OPTIONAL_CODEC.listOf().fieldOf("contents").forGetter(i -> Arrays.asList(i.getItemStacks()))) - .apply(builder, SimpleInventory::new)); - public static final StreamCodec STREAM_CODEC = StreamCodec.composite( - ByteBufCodecs.INT, SimpleInventory::getContainerSize, - ByteBufCodecs.INT, SimpleInventory::getMaxStackSize, - ItemStack.OPTIONAL_STREAM_CODEC.apply(ByteBufCodecs.list()), i -> Arrays.asList(i.getItemStacks()), - SimpleInventory::new - ); - - protected final ItemStack[] contents; - private final int stackLimit; - private final List dirtyMarkListeners = Lists.newLinkedList(); - - private int hash; - - /** - * Default constructor for NBT persistence, don't call this yourself. - */ - public SimpleInventory() { - this(0, 0); - } - - /** - * Make a new instance. - * @param size The amount of slots in the inventory. - * @param stackLimit The stack limit for each slot. - */ - public SimpleInventory(int size, int stackLimit) { - contents = new ItemStack[size]; - for (int i = 0; i < contents.length; i++) { - contents[i] = ItemStack.EMPTY; - } - this.stackLimit = stackLimit; - } - - public SimpleInventory(int size, int stackLimit, List contents) { - this.contents = new ItemStack[size]; - for (int i = 0; i < this.contents.length; i++) { - this.contents[i] = contents.get(i); - } - this.stackLimit = stackLimit; - } - - /** - * Add a dirty marking listener. - * @param dirtyMarkListener The dirty mark listener. - */ - public synchronized void addDirtyMarkListener(IDirtyMarkListener dirtyMarkListener) { - this.dirtyMarkListeners.add(dirtyMarkListener); - } - - /** - * Remove a dirty marking listener. - * @param dirtyMarkListener The dirty mark listener. - */ - public synchronized void removeDirtyMarkListener(IDirtyMarkListener dirtyMarkListener) { - this.dirtyMarkListeners.remove(dirtyMarkListener); - } - - @Override - public int getContainerSize() { - return contents.length; - } - - @Override - public ItemStack getItem(int slotId) { - return contents[slotId]; - } - - @Override - public ItemStack removeItem(int slotId, int count) { - ItemStack stack = getItem(slotId); - if (slotId < getContainerSize() && !stack.isEmpty()) { - if (stack.getCount() > count) { - ItemStack slotContents = stack.copy(); - ItemStack result = slotContents.split(count); - setItem(slotId, slotContents); - return result; - } - setItem(slotId, ItemStack.EMPTY); - onInventoryChanged(); - return stack; - } - return ItemStack.EMPTY; - } - - @Override - public void setItem(int slotId, ItemStack itemstack) { - if (slotId >= getContainerSize()) { - return; - } - this.contents[slotId] = Objects.requireNonNull(itemstack); - - if (!itemstack.isEmpty() && itemstack.getCount() > this.getMaxStackSize()) { - itemstack.setCount(this.getMaxStackSize()); - } - onInventoryChanged(); - } - - @Override - public int getMaxStackSize() { - return stackLimit; - } - - protected void onInventoryChanged() { - setChanged(); - } - - @Override - public boolean stillValid(Player entityplayer) { - return true; - } - - @Override - public void startOpen(Player playerIn) { - - } - - @Override - public void stopOpen(Player playerIn) { - - } - - @Override - public void read(HolderLookup.Provider provider, CompoundTag data) { - readFromNBT(provider, data, "items"); - } - - public void readFromNBT(HolderLookup.Provider provider, CompoundTag data, String tag) { - ListTag nbttaglist = data.getList(tag, Tag.TAG_COMPOUND); - - for (int j = 0; j < getContainerSize(); ++j) - contents[j] = ItemStack.EMPTY; - - for (int j = 0; j < nbttaglist.size(); ++j) { - CompoundTag slot = nbttaglist.getCompound(j); - int index; - if (slot.contains("index")) { - index = slot.getInt("index"); - } else { - index = slot.getByte("Slot"); - } - if (index >= 0 && index < getContainerSize()) { - contents[index] = ItemStack.parseOptional(provider, slot); - } - } - } - - @Override - public void write(HolderLookup.Provider provider, CompoundTag data) { - writeToNBT(provider, data, "items"); - } - - public void writeToNBT(HolderLookup.Provider provider, CompoundTag data, String tag) { - ListTag slots = new ListTag(); - for (byte index = 0; index < getContainerSize(); ++index) { - ItemStack itemStack = getItem(index); - if (!itemStack.isEmpty() && itemStack.getCount() > 0) { - CompoundTag slot = new CompoundTag(); - slot.putByte("Slot", index); - slots.add(itemStack.save(provider, slot)); - } - } - data.put(tag, slots); - } - - @Override - public ItemStack removeItemNoUpdate(int slotId) { - ItemStack stackToTake = getItem(slotId); - if (stackToTake.isEmpty()) { - return ItemStack.EMPTY; - } - - setItem(slotId, ItemStack.EMPTY); - return stackToTake; - } - - /** - * Get the array of {@link net.minecraft.world.item.ItemStack} inside this inventory. - * @return The items in this inventory. - */ - public ItemStack[] getItemStacks() { - return contents; - } - - @Override - public boolean canPlaceItem(int i, ItemStack itemstack) { - return i < getContainerSize() && i >= 0; - } - - @Override - public void clearContent() { - for(int i = 0; i < getContainerSize(); i++) { - contents[i] = ItemStack.EMPTY; - } - } - - @Override - public void setChanged() { - this.hash++; - List dirtyMarkListeners; - synchronized (this) { - dirtyMarkListeners = Lists.newLinkedList(this.dirtyMarkListeners); - } - for(IDirtyMarkListener dirtyMarkListener : dirtyMarkListeners) { - dirtyMarkListener.onDirty(); - } - } - - @Override - public boolean isEmpty() { - for(int i = 0; i < getContainerSize(); i++) { - if(!getItem(i).isEmpty()) { - return false; - } - } - return true; - } - - @Override - public CompoundTag toNBT(HolderLookup.Provider provider) { - CompoundTag tag = new CompoundTag(); - write(provider, tag); - return tag; - } - - @Override - public void fromNBT(HolderLookup.Provider provider, CompoundTag tag) { - read(provider, tag); - } - - public IItemHandler getItemHandler() { - return new InvWrapper(this); - } - - public IItemHandler getItemHandlerSided(Direction side) { - return new SidedInvWrapper(this, side); - } - - /** - * @return The inventory state. - */ - public int getState() { - return hash; - } - - @Override - public int[] getSlotsForFace(Direction side) { - return IntStream.range(0, getContainerSize()).toArray(); - } - - @Override - public boolean canPlaceItemThroughFace(int index, ItemStack itemStackIn, @Nullable Direction direction) { - return true; - } - - @Override - public boolean canTakeItemThroughFace(int index, ItemStack stack, Direction direction) { - return true; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SimpleInventory)) return false; - - SimpleInventory that = (SimpleInventory) o; - - if (stackLimit != that.stackLimit) return false; - if (contents.length != that.contents.length) return false; - for (int i = 0; i < contents.length; i++) { - if (!ItemStack.isSameItemSameComponents(contents[i], that.contents[i])) { - return false; - } - } - return true; - } - - @Override - public int hashCode() { - return this.hash; - } -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/SimpleInventoryState.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/SimpleInventoryState.java index 7e5be519d8..7dbbb3eef6 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/SimpleInventoryState.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/SimpleInventoryState.java @@ -3,14 +3,14 @@ import org.cyclops.commoncapabilities.api.capability.inventorystate.IInventoryState; /** - * An inventory state implementation for a {@link SimpleInventory}. + * An inventory state implementation for a {@link SimpleInventoryCommon}. * @author rubensworks */ public class SimpleInventoryState implements IInventoryState { - private final SimpleInventory inventory; + private final SimpleInventoryCommon inventory; - public SimpleInventoryState(SimpleInventory inventory) { + public SimpleInventoryState(SimpleInventoryCommon inventory) { this.inventory = inventory; } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ContainerTypeData.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ContainerTypeData.java deleted file mode 100644 index a07bb35a5b..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ContainerTypeData.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.cyclops.cyclopscore.inventory.container; - -import net.minecraft.world.flag.FeatureFlagSet; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.MenuType; -import net.neoforged.neoforge.network.IContainerFactory; - -/** - * A {@link MenuType} for a {@link MenuType.MenuSupplier}, - * which enables additional information to be passed to containers using packet buffers. - * This enables more convenient syntax via lambdas than the default {@link MenuType}. - * - * For example: `new ContainerTypeData(ContainerAbilityContainer::new))`. - * - * @author rubensworks - */ -@Deprecated // TODO: rm in next major -public class ContainerTypeData extends MenuType { - public ContainerTypeData(IContainerFactory factory, FeatureFlagSet featureFlagSet) { - super(factory, featureFlagSet); - } -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/InventoryContainer.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/InventoryContainer.java deleted file mode 100644 index 77a6129c25..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/InventoryContainer.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.cyclops.cyclopscore.inventory.container; - -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.Container; -import net.minecraft.world.inventory.MenuType; - -import javax.annotation.Nullable; - -/** - * A container for an inventory. - * @author rubensworks - */ -@Deprecated // TODO: rm in next major -public abstract class InventoryContainer extends ContainerExtended { - - protected final Container inventory; - - public InventoryContainer(@Nullable MenuType type, int id, Inventory playerInventory, Container inventory) { - super(type, id, playerInventory); - this.inventory = inventory; - if (isAssertInventorySize()) { - checkContainerSize(inventory, getSizeInventory()); - } - this.inventory.startOpen(playerInventory.player); - } - - protected boolean isAssertInventorySize() { - return true; - } - - public Container getContainerInventory() { - return inventory; - } - - @Override - protected int getSizeInventory() { - return inventory.getContainerSize(); - } - - @Override - public boolean stillValid(Player player) { - return this.inventory.stillValid(player); - } - - @Override - public void removed(Player player) { - super.removed(player); - this.inventory.stopOpen(player); - } -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ItemInventoryContainer.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ItemInventoryContainer.java deleted file mode 100644 index e6abceaff6..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ItemInventoryContainer.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.cyclops.cyclopscore.inventory.container; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.Container; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.ClickType; -import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.inventory.Slot; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.cyclops.cyclopscore.inventory.InventoryLocationPlayer; -import org.cyclops.cyclopscore.inventory.ItemLocation; - -import javax.annotation.Nullable; - -/** - * A container for an item. - * - * Implementations of this class will typically have two constructors, - * which will look something like this: - *
- *     // Called by the client-side screen factory
- *     public MyContainer(int id, PlayerInventory inventory, FriendlyByteBuf packetBuffer) {
- *         this(id, inventory, readItemIndex(packetBuffer), readHand(packetBuffer));
- *     }
- *
- *     // Called by the server-side container provider
- *     public MyContainer(int id, PlayerInventory inventory, int itemIndex, Hand hand) {
- *         super(RegistryEntries.CONTAINER_MY, id, inventory, itemIndex, hand);
- *     }
- * 
- * - * @param The item instance. - * @author rubensworks - */ -@Deprecated // TODO: rm in next major -public abstract class ItemInventoryContainer extends ContainerExtended { - - protected I item; - protected ItemLocation itemLocation; - - /** - * Make a new instance. - * @param type The container type. - * @param id The container id. - * @param inventory The player inventory. - * @param itemLocation The item location. - */ - public ItemInventoryContainer(@Nullable MenuType type, int id, Inventory inventory, ItemLocation itemLocation) { - super(type, id, inventory); - this.item = (I) itemLocation.getItemStack(inventory.player).getItem(); - this.itemLocation = itemLocation; - } - - public static int readItemIndex(FriendlyByteBuf packetBuffer) { - return packetBuffer.readInt(); - } - - public static InteractionHand readHand(FriendlyByteBuf packetBuffer) { - return packetBuffer.readBoolean() ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND; - } - - /** - * Get the item instance. - * @return The item. - */ - public I getItem() { - return item; - } - - @Override - public boolean stillValid(Player player) { - ItemStack item = getItemStack(player); - return item != null && item.getItem() == getItem(); - } - - public ItemStack getItemStack(Player player) { - return this.itemLocation.getItemStack(player); - } - - @Override - protected Slot createNewSlot(Container inventory, int index, int x, int y) { - return new Slot(inventory, index, x, y) { - - @Override - public boolean mayPickup(Player player) { - return this.getItem() != itemLocation.getItemStack(player); - } - - }; - } - - @Override - public void clicked(int slotId, int arg, ClickType clickType, Player player) { - if (clickType == ClickType.SWAP && itemLocation.inventoryLocation() == InventoryLocationPlayer.getInstance() && arg == itemLocation.slot()) { - // Don't allow swapping with the slot of the active item. - return; - } - super.clicked(slotId, arg, clickType, player); - } -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ScrollingInventoryContainer.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ScrollingInventoryContainer.java deleted file mode 100644 index 29db532e0a..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/inventory/container/ScrollingInventoryContainer.java +++ /dev/null @@ -1,191 +0,0 @@ -package org.cyclops.cyclopscore.inventory.container; - -import com.google.common.collect.Lists; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.Container; -import net.minecraft.world.inventory.MenuType; -import org.apache.commons.lang3.tuple.Pair; -import org.cyclops.cyclopscore.client.gui.component.WidgetScrollBar; - -import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.List; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -/** - * An inventory container that has a scrollbar and searchfield. - * Terminology: - * row: The row index from visible elements. - * elementIndex: The element index in all available elements - * visible: Currently on-screen by the user, maximum amount of elements is determined by the pageSize - * filtered: All items that are browsable by the user, might be more than the pageSize allows what leads to a scrollbar. - * unfiltered: All items, pattern searching will happen in this list. - * @author rubensworks - */ -@Deprecated // TODO: rm in next major -public abstract class ScrollingInventoryContainer extends InventoryContainer implements WidgetScrollBar.IScrollCallback { - - private final List unfilteredItems; - private List> filteredItems; // Pair: original index - item - private final List visibleItems; - private final IItemPredicate itemSearchPredicate; - private String lastSearchString = ""; - private int firstElement = 0; - - @SuppressWarnings("unchecked") - public ScrollingInventoryContainer(@Nullable MenuType type, int id, Inventory playerInventory, - Container inventory, List items, IItemPredicate filterer) { - super(type, id, playerInventory, inventory); - this.unfilteredItems = Lists.newArrayList(items); - this.filteredItems = Lists.newLinkedList(); - this.visibleItems = (List) Arrays.asList(new Object[getPageSize() * getColumns()]); - for(int i = 0; i < getPageSize(); i++) { - this.visibleItems.set(i, null); - } - this.itemSearchPredicate = filterer; - } - - protected List getUnfilteredItems() { - return this.unfilteredItems; - } - - protected List> getFilteredItems() { - return this.filteredItems; - } - - public int getUnfilteredItemCount() { - return getUnfilteredItems().size(); - } - - public int getFilteredItemCount() { - return getFilteredItems().size(); - } - - public int getFirstElement() { - return this.firstElement; - } - - /** - * @return The maximum amount of columns to show. - */ - public int getColumns() { - return 1; - } - - /** - * @return The stepsize for scrolling. - */ - public int getScrollStepSize() { - return getColumns(); - } - - @Override - public void onScroll(int firstRow) { - firstElement = firstRow * getScrollStepSize(); - if(firstElement < 0) firstElement = 0; - for(int i = 0; i < getPageSize(); i++) { - for(int j = 0; j < getColumns(); j++) { - int index = i * getColumns() + j; - int elementIndex = index + firstElement; - this.visibleItems.set(index, null); - if(elementIndex < getFilteredItemCount()) { - Pair filteredItem = getFilteredItems().get(elementIndex); - enableElementAt(index, filteredItem.getLeft(), filteredItem.getRight()); - } - } - } - } - - /** - * @return The allowed page size. - */ - public abstract int getPageSize(); - - /** - * After scrolling, this will be called to make items visible. - * @param visibleIndex The visible item index. - * @param elementIndex The absolute element index. - * @param element The element to show. - */ - protected void enableElementAt(int visibleIndex, int elementIndex, E element) { - this.visibleItems.set(visibleIndex, element); - } - - /** - * Check if the given element is visible. - * @param row The row the the given element is at. - * @return If it is visible. - */ - public boolean isElementVisible(int row) { - return row < getPageSize() && getVisibleElement(row) != null; - } - - /** - * Get the currently visible element at the given row. - * @param row The row the the given element is at. - * @return The elements - */ - public E getVisibleElement(int row) { - if(row >= visibleItems.size()) return null; - return this.visibleItems.get(row); - } - - public void refreshFilter() { - updateFilter(lastSearchString); - } - - /** - * Update the filtered items. - * @param searchString The input string to search by. - */ - public void updateFilter(String searchString) { - this.lastSearchString = searchString; - Pattern pattern; - try { - pattern = Pattern.compile(".*" + searchString.toLowerCase() + ".*"); - } catch (PatternSyntaxException e) { - pattern = Pattern.compile(".*"); - } - this.filteredItems = filter(getUnfilteredItems(), itemSearchPredicate, pattern); - onScroll(0); // Reset scroll, will also refresh items on-screen. - } - - protected List> filter(List input, IItemPredicate predicate, Pattern pattern) { - List> filtered = Lists.newLinkedList(); - int i = 0; - for(E item : input) { - if(predicate.apply(item, pattern) && additionalApplies(item)) { - filtered.add(Pair.of(i, item)); - } - i++; - } - return filtered; - } - - /** - * An additional conditional that can be added for filtering items. - * @param item The item to check. - * @return If the item should be shown. - */ - protected boolean additionalApplies(E item) { - return true; - } - - /** - * Predicate for matching items used to search. - * @param The type of item. - */ - public static interface IItemPredicate { - - /** - * Check if the given item matches a string pattern. - * @param item The item to check. - * @param pattern The pattern to check. - * @return If the item matches - */ - public boolean apply(E item, Pattern pattern); - - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/item/IInformationProvider.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/item/IInformationProvider.java index d9e918c951..b3c3c31ff9 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/item/IInformationProvider.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/item/IInformationProvider.java @@ -1,10 +1,10 @@ package org.cyclops.cyclopscore.item; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.item.ItemStack; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.Component; import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; @@ -32,7 +32,7 @@ public interface IInformationProvider { * A prefix for additional info. */ @Deprecated - public static String INFO_PREFIX = ChatFormatting.DARK_PURPLE.toString() + ChatFormatting.ITALIC.toString(); // TODO: remove in next major + public static String INFO_PREFIX = ChatFormatting.DARK_PURPLE.toString() + ChatFormatting.ITALIC.toString(); /** * Additional info prefix styles */ diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/network/PacketHandlerNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/network/PacketHandlerNeoForge.java index 2a8a271010..2fef8379b3 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/network/PacketHandlerNeoForge.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/network/PacketHandlerNeoForge.java @@ -17,7 +17,6 @@ import net.neoforged.neoforge.network.registration.PayloadRegistrar; import org.apache.commons.lang3.tuple.Pair; import org.cyclops.cyclopscore.init.ModBaseNeoForge; -import org.jetbrains.annotations.Nullable; import java.util.List; @@ -92,16 +91,6 @@ public void sendToPlayer(PacketBase packet, ServerPlayer player) { PacketDistributor.sendToPlayer(player, packet); } - /** - * Send a packet to all in the target range. - * @param packet The packet. - * @param point The point. - */ - @Deprecated // TODO: rm in next major - public void sendToAllAround(PacketBase packet, TargetPoint point) { - PacketDistributor.sendToPlayersNear(point.level, point.excluded, point.x, point.y, point.z, point.radius, packet); - } - @Override public void sendToAllAroundPoint(PacketBase packet, IPacketHandler.TargetPoint point) { PacketDistributor.sendToPlayersNear(point.level(), point.excluded(), point.x(), point.y(), point.z(), point.radius(), packet); @@ -117,14 +106,4 @@ public void sendToAll(PacketBase packet) { PacketDistributor.sendToAllPlayers(packet); } - @Deprecated // TODO: rm in next major - public static class PacketCodecException extends RuntimeException { - public PacketCodecException(String message, Throwable cause) { - super(message, cause); - } - } - - @Deprecated // TODO: rm in next major - public static record TargetPoint(ServerLevel level, double x, double y, double z, double radius, @Nullable ServerPlayer excluded) {} - } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/network/packet/PlayerPositionPacket.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/network/packet/PlayerPositionPacket.java deleted file mode 100644 index 3cd96cc580..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/network/packet/PlayerPositionPacket.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.cyclops.cyclopscore.network.packet; - -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import org.cyclops.cyclopscore.init.ModBaseNeoForge; -import org.cyclops.cyclopscore.network.CodecField; -import org.cyclops.cyclopscore.network.IPacketHandler; -import org.cyclops.cyclopscore.network.PacketCodec; - -import java.util.UUID; - -/** - * An abstract superclass for all packets that contain the position and uuid - * of a player and execute a specific action on the client side that is visible by - * all players in a specific range around the given player. - * - * @author immortaleeb - */ -@Deprecated // TODO: rm in next major -public abstract class PlayerPositionPacket> extends PacketCodec { - - private static final int DEFAULT_RANGE = 3000; - - @CodecField - protected String uuid; - @CodecField - protected Vec3 position = new Vec3(0, 0, 0); - @CodecField - private int range = DEFAULT_RANGE; - - /** - * Creates a packet with no content - */ - public PlayerPositionPacket(Type type) { - super(type); - } - - public PlayerPositionPacket(Type type, Player player) { - this(type, player, DEFAULT_RANGE); - } - - public PlayerPositionPacket(Type type, Player player, int range) { - super(type); - this.uuid = player.getUUID().toString(); - this.position = player.position(); - this.range = range; - } - - @Override - public boolean isAsync() { - return false; - } - - @Override - @OnlyIn(Dist.CLIENT) - public void actionClient(Level level, Player player) { - if (uuid == null) { - getModInstance().log(org.apache.logging.log4j.Level.WARN, "Got PlayerPositionPacket with empty uuid"); - return; - } - - try { - UUID uuid = UUID.fromString(this.uuid); - if (player != null && !player.getUUID().equals(uuid)) { - player = level.getPlayerByUUID(uuid); - } - - if (player == null) { - getModInstance().log(org.apache.logging.log4j.Level.WARN, "Received PlayerPositionPacket for player with uuid '" + uuid + "', but player doesn't exist"); - } else { - performClientAction(level, player); - } - } catch (IllegalArgumentException e) { - // Ignore invalid packets - } - } - - @Override - public void actionServer(Level level, ServerPlayer player) { - getModInstance().getPacketHandler().sendToAllAroundPoint(create(player, range), - IPacketHandler.createTargetPointFromEntity(player, range)); - } - - protected abstract PlayerPositionPacket create(Player player, int range); - - protected abstract ModBaseNeoForge getModInstance(); - - protected abstract void performClientAction(Level level, Player player); -}