Skip to content

Commit

Permalink
Remove some unneeded data saved to nbt
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWeabo committed Jun 24, 2024
1 parent 0ed3fd3 commit 23f94af
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/main/java/com/blueweabo/mutecore/MuTECore.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.blueweabo.mutecore;

import net.minecraft.launchwrapper.Launch;
import net.minecraft.nbt.NBTTagCompound;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.blueweabo.mutecore.api.data.Coordinates;
import com.blueweabo.mutecore.api.data.GUIEvent;
import com.blueweabo.mutecore.api.data.WorldStateValidator;
import com.blueweabo.mutecore.api.gui.MultiTileEntityGuiFactory;
import com.blueweabo.mutecore.api.registry.EventRegistry;
import com.blueweabo.mutecore.api.registry.PlayerInteractionEvent;
import com.blueweabo.mutecore.api.registry.MultiTileContainer.FakeEntity;
import com.blueweabo.mutecore.api.registry.MultiTileContainer.Id;
import com.blueweabo.mutecore.api.tile.MultiTileEntity;
import com.blueweabo.mutecore.api.utils.PlayerHelper;
import com.blueweabo.mutecore.test.TestRegistry;
import com.cleanroommc.modularui.factory.GuiManager;

Expand All @@ -23,6 +31,7 @@
import dev.dominion.ecs.api.Dominion;
import dev.dominion.ecs.api.Entity;
import dev.dominion.ecs.api.Results;
import dev.dominion.ecs.engine.IntEntity;

@Mod(
modid = MuTECore.MODID,
Expand All @@ -49,17 +58,34 @@ public void preInit(FMLPreInitializationEvent event) {
ENABLE_TESTS = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
if (ENABLE_TESTS) {
new TestRegistry().run();
SystemRegistrator.registerProcessingSystem();
SystemRegistrator.registerOtherSystem();
}
GameRegistry.registerTileEntity(MultiTileEntity.class, "multitileentity");
GuiManager.registerFactory(MultiTileEntityGuiFactory.INSTANCE);
proxy.preInit(event);
}

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
proxy.init(event);
public void init(FMLInitializationEvent initEvent) {
proxy.init(initEvent);
EventRegistry.registerPlayerInteractionEvent(
new PlayerInteractionEvent(0, (p, e) -> PlayerHelper.isRealPlayer(p) ? new GUIEvent(p) : null));
SystemRegistrator.registerSystem(() -> {
Results<Results.With1<GUIEvent>> results = MuTECore.ENGINE.findEntitiesWith(GUIEvent.class);
for (Results.With1<GUIEvent> result : results) {
Entity entity = result.entity();
GUIEvent event = entity.get(GUIEvent.class);
Coordinates coords = entity.get(Coordinates.class);
NBTTagCompound nbt = new NBTTagCompound();
Object[] components = ((IntEntity) entity).getComponentArray();
for (Object component : components) {
if (component instanceof WorldStateValidator validator) {
validator.save(nbt);
}
}
MultiTileEntityGuiFactory.open(event.getPlayer(), coords.getX(), coords.getY(), coords.getZ(), nbt);
entity.removeType(GUIEvent.class);
}
});
}

@Mod.EventHandler
Expand Down

0 comments on commit 23f94af

Please sign in to comment.