Skip to content

Commit

Permalink
Revert "1.20 Scripting Backport (#618)"
Browse files Browse the repository at this point in the history
This reverts commit cb57bff.
  • Loading branch information
Caltinor committed Dec 4, 2024
1 parent 7a4c1a2 commit 6ecb157
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 756 deletions.
206 changes: 89 additions & 117 deletions src/main/java/harmonised/pmmo/api/APIUtils.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ public record LocationData(
List<ResourceLocation> veinBlacklist,
Map<String, Integer> travelReq,
Map<ResourceLocation, Map<String, Double>> mobModifiers) implements DataSource<LocationData>{

public LocationData(boolean override) {
this(override, new HashSet<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(),
new ArrayList<>(), new HashMap<>(), new ArrayList<>(), new HashMap<>());
}

public LocationData() {this(
false, new HashSet<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(),
new ArrayList<>(), new HashMap<>(), new HashMap<>());}
Expand Down
39 changes: 15 additions & 24 deletions src/main/java/harmonised/pmmo/config/readers/CoreLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import harmonised.pmmo.config.scripting.Scripting;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import harmonised.pmmo.api.enums.ModifierDataType;
Expand Down Expand Up @@ -44,12 +38,11 @@ public class CoreLoader {
@SubscribeEvent
public static void onTagLoad(TagsUpdatedEvent event) {
Core core = Core.get(event.getUpdateCause() == UpdateCause.CLIENT_PACKET_RECEIVED ? LogicalSide.CLIENT : LogicalSide.SERVER);
core.getLoader().ITEM_LOADER.postProcess(event.getRegistryAccess());
core.getLoader().BLOCK_LOADER.postProcess(event.getRegistryAccess());
core.getLoader().ENTITY_LOADER.postProcess(event.getRegistryAccess());
//Until dimensions are stored as a client registry, this must remain commented.
//core.getLoader().DIMENSION_LOADER.postProcess(event.getRegistryAccess());
core.getLoader().BIOME_LOADER.postProcess(event.getRegistryAccess());
core.getLoader().ITEM_LOADER.postProcess();
core.getLoader().BLOCK_LOADER.postProcess();
core.getLoader().ENTITY_LOADER.postProcess();
//core.getLoader().DIMENSION_LOADER.postProcess();
core.getLoader().BIOME_LOADER.postProcess();
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -87,12 +80,10 @@ public <T extends DataSource<T>> void applyData(ObjectType type, Map<ResourceLoc
case BIOME -> BIOME_LOADER;
default -> null;};
}

public ExecutableListener RELOADER;
public static final Consumer<RegistryAccess> RELOADER_FUNCTION = access -> {

public static final ExecutableListener RELOADER = new ExecutableListener(() -> {
Core.get(LogicalSide.SERVER).getLoader().resetData();
Scripting.readFiles(access);
};
});

public void resetData() {
ITEM_LOADER.clearData();
Expand All @@ -106,21 +97,21 @@ public void resetData() {
}

public final MergeableCodecDataManager<ObjectData, Item> ITEM_LOADER = new MergeableCodecDataManager<>(
"pmmo/items", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, Registries.ITEM);
"pmmo/items", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, ForgeRegistries.ITEMS);
public final MergeableCodecDataManager<ObjectData, Block> BLOCK_LOADER = new MergeableCodecDataManager<>(
"pmmo/blocks", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, Registries.BLOCK);
"pmmo/blocks", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, ForgeRegistries.BLOCKS);
public final MergeableCodecDataManager<ObjectData, EntityType<?>> ENTITY_LOADER = new MergeableCodecDataManager<>(
"pmmo/entities", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, Registries.ENTITY_TYPE);
"pmmo/entities", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, ForgeRegistries.ENTITY_TYPES);
public final MergeableCodecDataManager<LocationData, Biome> BIOME_LOADER = new MergeableCodecDataManager<>(
"pmmo/biomes", DATA_LOGGER, LocationData.CODEC, this::mergeLoaderData, this::printData, LocationData::new, Registries.BIOME);
"pmmo/biomes", DATA_LOGGER, LocationData.CODEC, this::mergeLoaderData, this::printData, LocationData::new, ForgeRegistries.BIOMES);
public final MergeableCodecDataManager<LocationData, Level> DIMENSION_LOADER = new MergeableCodecDataManager<>(
"pmmo/dimensions", DATA_LOGGER, LocationData.CODEC, this::mergeLoaderData, this::printData, LocationData::new, Registries.DIMENSION);
"pmmo/dimensions", DATA_LOGGER, LocationData.CODEC, this::mergeLoaderData, this::printData, LocationData::new, null);
public final MergeableCodecDataManager<PlayerData, Player> PLAYER_LOADER = new MergeableCodecDataManager<>(
"pmmo/players", DATA_LOGGER, PlayerData.CODEC, this::mergeLoaderData, this::printData, PlayerData::new, null);
public final MergeableCodecDataManager<EnhancementsData, Enchantment> ENCHANTMENT_LOADER = new MergeableCodecDataManager<>(
"pmmo/enchantments", DATA_LOGGER, EnhancementsData.CODEC, this::mergeLoaderData, this::printData, EnhancementsData::new, Registries.ENCHANTMENT);
"pmmo/enchantments", DATA_LOGGER, EnhancementsData.CODEC, this::mergeLoaderData, this::printData, EnhancementsData::new, ForgeRegistries.ENCHANTMENTS);
public final MergeableCodecDataManager<EnhancementsData, MobEffect> EFFECT_LOADER = new MergeableCodecDataManager<>(
"pmmo/effects", DATA_LOGGER, EnhancementsData.CODEC, this::mergeLoaderData, this::printData, EnhancementsData::new, Registries.MOB_EFFECT);
"pmmo/effects", DATA_LOGGER, EnhancementsData.CODEC, this::mergeLoaderData, this::printData, EnhancementsData::new, ForgeRegistries.MOB_EFFECTS);


private <T extends DataSource<T>> T mergeLoaderData(final List<T> raws) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

import net.minecraft.core.RegistryAccess;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
Expand All @@ -15,11 +14,9 @@
import net.minecraftforge.network.simple.SimpleChannel;

public class ExecutableListener extends SimplePreparableReloadListener<Boolean> {
private final Consumer<RegistryAccess> executor;
private final RegistryAccess access;

public ExecutableListener(RegistryAccess access, Consumer<RegistryAccess> executor) {
this.access = access;
private Runnable executor;

public ExecutableListener(Runnable executor) {
this.executor = executor;
}

Expand All @@ -28,7 +25,7 @@ public ExecutableListener(RegistryAccess access, Consumer<RegistryAccess> execut

@Override
protected void apply(Boolean pObject, ResourceManager pResourceManager, ProfilerFiller pProfiler) {
executor.accept(access);
executor.run();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ public MergeableCodecDataManager(final String folderName, final Logger logger, C

public Map<ResourceLocation, T> getData() {return data;}

public void clearData() {
this.data.clear();
this.overrideSettings.clear();
this.defaultSettings.clear();
}
public void clearData() {this.data = new HashMap<>();}

public T getData(ResourceLocation id) {
return data.computeIfAbsent(id, res -> getGenericTypeInstance());
Expand All @@ -171,7 +167,7 @@ public T getData(ResourceLocation id) {
*/
@SuppressWarnings("unchecked")
public void registerDefault(ResourceLocation id, DataSource<?> data) {
defaultSettings.merge(id, (T) data, DataSource::combine);
defaultSettings.merge(id, (T) data, (currID, currData) -> currData.combine((T) data));
}

/**Adds override data to the loader. This data is applied on
Expand All @@ -189,7 +185,7 @@ public void registerDefault(ResourceLocation id, DataSource<?> data) {
*/
@SuppressWarnings("unchecked")
public void registerOverride(ResourceLocation id, DataSource<?> data) {
overrideSettings.merge(id, (T) data, DataSource::combine);
overrideSettings.merge(id, (T) data, (currID, currData) -> currData.combine((T) data));
}

/** Off-thread processing (can include reading files from hard drive) **/
Expand Down
100 changes: 0 additions & 100 deletions src/main/java/harmonised/pmmo/config/scripting/Expression.java

This file was deleted.

Loading

0 comments on commit 6ecb157

Please sign in to comment.