Skip to content

Commit

Permalink
Change from Dominion ECS to Ashley ECS for J8 Compat
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWeabo committed Dec 11, 2024
1 parent 0f850a7 commit 6563790
Show file tree
Hide file tree
Showing 35 changed files with 160 additions and 118 deletions.
3 changes: 2 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ dependencies {
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.6.36-GTNH:dev")
api("com.github.GTNewHorizons:GTNHLib:0.5.11:dev")
api("com.github.GTNewHorizons:ModularUI2:2.1.8-1.7.10:dev")
shadowImplementation("dev.dominion.ecs:dominion-ecs-engine:0.9.0") // MIT License
//shadowImplementation("dev.dominion.ecs:dominion-ecs-engine:0.9.0") // MIT License
shadowImplementation("com.badlogicgames.ashley:ashley:1.7.4") // Apache 2.0 License
api("com.github.GTNewHorizons:waila:1.8.1:dev")
//api("com.github.GTNewHorizons:Angelica:1.0.0-beta6:dev")
//implementation("com.github.GTNewHorizons:Galacticraft:3.2.4-GTNH:dev")
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
1 change: 1 addition & 0 deletions repositories.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

repositories {
mavenLocal()
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.25'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.30'
}
44 changes: 17 additions & 27 deletions src/main/java/com/gtnewhorizons/mutecore/MuTECore.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.badlogic.ashley.core.Component;
import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray;
import com.cleanroommc.modularui.factory.GuiManager;
import com.gtnewhorizons.mutecore.api.data.Coordinates;
import com.gtnewhorizons.mutecore.api.data.GUIEvent;
import com.gtnewhorizons.mutecore.api.data.WorldStateValidator;
import com.gtnewhorizons.mutecore.api.event.PlayerInteractionEvent;
import com.gtnewhorizons.mutecore.api.gui.GUISystem;
import com.gtnewhorizons.mutecore.api.gui.MultiTileEntityGuiFactory;
import com.gtnewhorizons.mutecore.api.registry.EventRegistry;
import com.gtnewhorizons.mutecore.api.registry.MultiTileContainer.FakeEntity;
Expand All @@ -25,13 +31,10 @@
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.registry.GameRegistry;
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,14 +52,14 @@ public class MuTECore {
clientSide = "com.gtnewhorizons.mutecore.ClientProxy",
serverSide = "com.gtnewhorizons.mutecore.CommonProxy")
public static CommonProxy proxy;
public static Dominion ENGINE;
public static Engine ENGINE;
public static boolean ENABLE_TESTS;

public MuTECore() {}

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
ENGINE = Dominion.create("MuTE");
ENGINE = new Engine();
ENABLE_TESTS = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
if (ENABLE_TESTS) {
new TestRegistry().run();
Expand All @@ -71,23 +74,7 @@ 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);
}
});
SystemRegistrator.registerSystem(new GUISystem());
}

@Mod.EventHandler
Expand All @@ -98,18 +85,21 @@ public void postInit(FMLPostInitializationEvent event) {
.register(new SystemRegistrator());
}

@Mod.EventHandler
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
MultiTileEntityRegistry.registerForSave();
}

@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event) {
proxy.serverStarting(event);
MultiTileEntityRegistry.registerForSave();
}

@Mod.EventHandler
public void serverStopping(FMLServerStoppingEvent event) {
Results<Entity> results = ENGINE.findAllEntities();
ImmutableArray<Entity> results = ENGINE.getEntities();
for (Entity entity : results) {
if (entity.has(FakeEntity.class)) continue;
ENGINE.deleteEntity(entity);
ENGINE.removeEntity(entity);
}
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/gtnewhorizons/mutecore/MuTENetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import org.jetbrains.annotations.Nullable;

import com.badlogic.ashley.core.Component;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.utils.ImmutableArray;
import com.cleanroommc.modularui.network.IPacket;
import com.gtnewhorizons.mutecore.api.block.MultiTileEntityBlock;
import com.gtnewhorizons.mutecore.api.data.Coordinates;
Expand All @@ -30,8 +33,6 @@
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import dev.dominion.ecs.api.Entity;
import dev.dominion.ecs.engine.IntEntity;

public class MuTENetwork {

Expand Down Expand Up @@ -122,9 +123,9 @@ public void read(PacketBuffer buf) throws IOException {
Entity entity = container.createNewEntity();
entity.add(coords);
entity.add(new WorldContainer(Minecraft.getMinecraft().theWorld));
Object[] components = ((IntEntity) entity).getComponentArray();
for (int i = 0; i < components.length; i++) {
if (!(components[i] instanceof WorldStateValidator validator)) continue;
ImmutableArray<Component> components = entity.getComponents();
for (int i = 0; i < components.size(); i++) {
if (!(components.get(i) instanceof WorldStateValidator validator)) continue;
validator.load(data);
}
mute.setEntity(entity);
Expand Down
34 changes: 8 additions & 26 deletions src/main/java/com/gtnewhorizons/mutecore/SystemRegistrator.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,31 @@
package com.gtnewhorizons.mutecore;

import com.badlogic.ashley.core.EntitySystem;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import dev.dominion.ecs.api.Scheduler;

public class SystemRegistrator {

private static final Scheduler SYSTEMS = MuTECore.ENGINE.createScheduler();

/**
* Register a single system. It will be ran after the last registered system
*/
public static void registerSystem(Runnable system) {
SYSTEMS.schedule(system);
public static void registerSystem(EntitySystem system) {
MuTECore.ENGINE.addSystem(system);
}

/**
* Register any amount of systems. The systems will be scheduled one after another.
*/
public static void registerSystems(Runnable... systems) {
for (Runnable system : systems) {
SYSTEMS.schedule(system);
}
}

/**
* Register any amount of systems. The systems registered this way will be ran in parallel
*/
public static void registerSystemsParallel(Runnable... systems) {
int processors = Runtime.getRuntime()
.availableProcessors();
Runnable[] parallel = new Runnable[processors];
int count = 0;
for (Runnable system : systems) {
parallel[count++] = system;
if (count >= processors) {
SYSTEMS.parallelSchedule(parallel);
count = 0;
parallel = new Runnable[processors];
}
public static void registerSystems(EntitySystem... systems) {
for (EntitySystem system : systems) {
MuTECore.ENGINE.addSystem(system);
}
}

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
SYSTEMS.tick();
MuTECore.ENGINE.update(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import org.jetbrains.annotations.ApiStatus.Internal;

import com.badlogic.ashley.core.Component;
import com.badlogic.ashley.core.Entity;
import com.gtnewhorizons.mutecore.MuTECore;
import com.gtnewhorizons.mutecore.MuTENetwork;
import com.gtnewhorizons.mutecore.MuTENetwork.MuTEPacket;
Expand All @@ -35,8 +37,6 @@
import com.gtnewhorizons.mutecore.api.tile.MultiTileEntity;
import com.gtnewhorizons.mutecore.client.MultiTileBlockRenderer;

import dev.dominion.ecs.api.Entity;

public class MultiTileEntityBlock extends BlockContainer {

MultiTileEntityRegistry registry;
Expand All @@ -59,7 +59,7 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
Entity entity = ((MultiTileEntity) world.getTileEntity(x, y, z)).getEntity();
return registry.getItemStack(
entity.get(Id.class)
entity.getComponent(Id.class)
.getId());
}

Expand Down Expand Up @@ -98,14 +98,14 @@ public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer
packet.setComponentData(nbt);
MuTENetwork.sendToPlayer(packet, playermp);
}
Object eventComponent = null;
Component eventComponent = null;
for (PlayerInteractionEvent preEvent : EventRegistry.PLAYER_INTERACTION_EVENTS) {
eventComponent = preEvent.generate(player, mute.getEntity());
if (eventComponent != null) break;
}
if (eventComponent == null) return false;
if (mute.getEntity()
.has(eventComponent.getClass())) return false;
.getComponent(eventComponent.getClass()) != null) return false;
mute.getEntity()
.add(eventComponent);
return true;
Expand All @@ -119,7 +119,7 @@ public void breakBlock(World worldIn, int x, int y, int z, Block blockBroken, in
for (BlockBreakEvent preEvent : EventRegistry.BLOCK_BREAK_EVENTS) {
preEvent.call(entity);
}
MuTECore.ENGINE.deleteEntity(entity);
MuTECore.ENGINE.removeEntity(entity);
super.breakBlock(worldIn, x, y, z, blockBroken, meta);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.gtnewhorizons.mutecore.api.data;

import com.badlogic.ashley.core.Component;

import net.minecraft.nbt.NBTTagCompound;

public class Coordinates implements WorldStateValidator {
public class Coordinates implements Component, WorldStateValidator {

private int x;
private int y;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.gtnewhorizons.mutecore.api.data;

import com.badlogic.ashley.core.Component;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;

public class Direction implements WorldStateValidator {
public class Direction implements Component, WorldStateValidator {

private ForgeDirection direction;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.gtnewhorizons.mutecore.api.data;

public class FirstTickEvent {
import com.badlogic.ashley.core.Component;

public class FirstTickEvent implements Component {
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.gtnewhorizons.mutecore.api.data;

import com.badlogic.ashley.core.Component;

import net.minecraft.entity.player.EntityPlayer;

public class GUIEvent {
public class GUIEvent implements Component {

private EntityPlayer player;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.util.UUID;

import com.badlogic.ashley.core.Component;

import net.minecraft.nbt.NBTTagCompound;

public class PlayerUUID implements WorldStateValidator {
public class PlayerUUID implements Component, WorldStateValidator {

private UUID playerUUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.gtnewhorizons.mutecore.api.data;

import com.badlogic.ashley.core.Component;

import net.minecraft.world.World;

public class WorldContainer {
public class WorldContainer implements Component {

private World world;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import javax.annotation.Nonnull;

import dev.dominion.ecs.api.Entity;
import com.badlogic.ashley.core.Entity;


public class BlockBreakEvent implements Comparable<BlockBreakEvent> {

Expand Down
Loading

0 comments on commit 6563790

Please sign in to comment.