Skip to content

Commit

Permalink
Resolve minor TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Dec 25, 2024
1 parent 43ea84e commit b4e7b53
Show file tree
Hide file tree
Showing 46 changed files with 103 additions and 1,299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static <M extends IModBase> void register(@Nullable BiFunction<BlockConfi
}

@Override
public void onRegisterForgeFilled(BlockConfigCommon<M> eConfig) {
public void onRegistriesFilled(BlockConfigCommon<M> eConfig) {
// Register block and set creative tab.
register(eConfig.getItemConstructor(), eConfig, () -> {
eConfig.onForgeRegistered(); // Manually call after item has been registered
Expand All @@ -74,7 +74,7 @@ public static void handleDynamicBlockModel(BlockConfigCommon extendedConfig) {

protected void polish(BlockConfigCommon<M> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class CapabilityAction<T, M extends IModBase> extends ConfigurableTypeAct
public CapabilityAction() {}

@Override
public void onRegisterForge(CapabilityConfigCommon<T, M> config) {
super.onRegisterForge(config);
public void onRegistriesCreated(CapabilityConfigCommon<T, M> config) {
super.onRegistriesCreated(config);
config.getRegistrar().apply(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ConfigurableTypeActionRegistry<C extends ExtendedConfigRegistry<C,
extends ConfigurableTypeActionCommon<C, I, M> {

@Override
public void onRegisterForgeFilled(C eConfig) {
public void onRegistriesFilled(C eConfig) {
register(eConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class EntityActionCommon<M extends IModBase, T extends Entity> extends ConfigurableTypeActionRegistry<EntityConfigCommon<M, T>, EntityType<T>, M> {

@Override
public void onRegisterForgeFilled(EntityConfigCommon<M, T> eConfig) {
public void onRegistriesFilled(EntityConfigCommon<M, T> eConfig) {
// Register item and set creative tab.
register(eConfig, () -> {
this.polish(eConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ItemAction<M extends IModBase> extends ConfigurableTypeActionRegist
protected static final List<ItemConfigCommon<?>> MODEL_ENTRIES = Lists.newArrayList();

@Override
public void onRegisterForgeFilled(ItemConfigCommon<M> eConfig) {
public void onRegistriesFilled(ItemConfigCommon<M> eConfig) {
// Register item and set creative tab.
register(eConfig, () -> {
this.polish(eConfig);
Expand All @@ -37,7 +37,7 @@ public static <M extends IModBase> void handleItemModel(ItemConfigCommon<M> exte

protected void polish(ItemConfigCommon<M> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ public ConfigurableTypeCommon getConfigurableType() {
return ConfigurableTypeCommon.BLOCK;
}

public Collection<ItemStack> getDefaultCreativeTabEntriesPublic() { // TODO: rm in next major, and make other method public
return this.defaultCreativeTabEntries();
}

protected Collection<ItemStack> defaultCreativeTabEntries() {
public Collection<ItemStack> getDefaultCreativeTabEntries() {
return Collections.singleton(new ItemStack(getInstance()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <M> The mod type
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ public ConfigurableTypeCommon getConfigurableType() {
return ConfigurableTypeCommon.ITEM;
}

public Collection<ItemStack> getDefaultCreativeTabEntriesPublic() { // TODO: rm in next major, and make other method public
return this.getDefaultCreativeTabEntries();
}

protected Collection<ItemStack> getDefaultCreativeTabEntries() {
public Collection<ItemStack> getDefaultCreativeTabEntries() {
return Collections.singleton(new ItemStack(getInstance()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,34 +16,10 @@
*/
public abstract class PacketCodec<T extends PacketCodec<T>> extends PacketBase<T> {

@Deprecated // TODO: rm in next major
public static final int READ_STRING_MAX_LENGTH = 32767;

public PacketCodec(Type<T> 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<Void, List<Field>> fieldCache = new SingleCache<Void, List<Field>>(
new SingleCache.ICacheUpdater<Void, List<Field>>() {

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 <T> 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> T read(RegistryFriendlyByteBuf packetBuffer, Class<T> clazz) {
return PacketCodecs.read(packetBuffer, clazz);
}

public static interface ICodecAction {

/**
Expand All @@ -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);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
public class ConditionActionFabric<T extends ResourceCondition> extends ConfigurableTypeActionCommon<ConditionConfigFabric<T>, ResourceConditionType<T>, ModBaseFabric<?>> {

@Override
public void onRegisterForge(ConditionConfigFabric<T> eConfig) {
super.onRegisterForge(eConfig);
public void onRegistriesCreated(ConditionConfigFabric<T> eConfig) {
super.onRegistriesCreated(eConfig);
ResourceConditions.register(eConfig.getInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,12 +31,6 @@ protected void polish(BlockConfigCommon<M> 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);
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit b4e7b53

Please sign in to comment.