Skip to content

Commit

Permalink
CraftingProvider and StorageProvider Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
DaNussi committed Oct 28, 2023
1 parent 3c2e9ff commit d437361
Show file tree
Hide file tree
Showing 29 changed files with 375 additions and 1,145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.nussi.dedicated_applied_energistics.commands.ConfigCommand;
import net.nussi.dedicated_applied_energistics.init.BlockEntityTypeInit;
import net.nussi.dedicated_applied_energistics.init.BlockInit;
import net.nussi.dedicated_applied_energistics.init.CellInit;
import net.nussi.dedicated_applied_energistics.init.ItemInit;
import org.slf4j.Logger;

Expand All @@ -24,17 +22,14 @@ public DedicatedAppliedEnegistics()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

BlockInit.BLOCKS.register(modEventBus);
ItemInit.ITEMS.register(modEventBus);
BlockInit.BLOCKS.register(modEventBus);
BlockEntityTypeInit.BLOCK_ENTITY_TYPES.register(modEventBus);
modEventBus.addListener(DedicatedAppliedEnegistics::commonSetup);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, DedicatedAppliedEnergisticsController.CONFIG_SPEC, "dae2-config.toml");
}


public static void commonSetup(FMLCommonSetupEvent event) {
CellInit.Init();
}
public static void commonSetup(FMLCommonSetupEvent event) { }

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
package net.nussi.dedicated_applied_energistics;

import com.mojang.logging.LogUtils;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.nussi.dedicated_applied_energistics.items.InterDimensionalStorageCell;
import net.nussi.dedicated_applied_energistics.modules.InfluxLogger;
import net.nussi.dedicated_applied_energistics.modules.VirtualInventory;
import net.nussi.dedicated_applied_energistics.providers.InterDimensionalInterfaceStorage;
import org.slf4j.Logger;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Mod.EventBusSubscriber(modid = DedicatedAppliedEnegistics.MODID)
public class DedicatedAppliedEnergisticsController {


private static final Logger LOGGER = LogUtils.getLogger();
public static ForgeConfigSpec.Builder CONFIG_BUILDER = new ForgeConfigSpec.Builder();
public static ForgeConfigSpec CONFIG_SPEC;

Expand All @@ -41,12 +46,18 @@ public class DedicatedAppliedEnergisticsController {

public static boolean IsRunning = false;



public static String Start() {
if(IsRunning) return "DAE2 already started!";

InterDimensionalStorageCell.redisInit();

controllables.forEach(controllable -> {
try {
controllable.externalStart();
} catch (Exception e) {
LOGGER.error(e.getMessage());
e.printStackTrace();
}
});
if(CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY.get()) VirtualInventory.Init();
if(CONFIG_VALUE_BEHAVIOUR_INFLUXDB_LOGGER.get()) InfluxLogger.Init();

Expand All @@ -57,9 +68,10 @@ public static String Start() {
public static String Stop() {
IsRunning = false;

InterDimensionalStorageCell.redisReset();
controllables.forEach(controllable -> controllable.externalStop());
VirtualInventory.Reset();
InfluxLogger.Reset();
if(jedisPool != null) jedisPool.close();

return "OK";
}
Expand All @@ -75,8 +87,13 @@ public static String Reset() {
return status;
}

public static JedisPool jedisPool;
public static Jedis getJedis() {
return new Jedis(CONFIG_VALUE_REDIS_URI.get());
if(jedisPool == null) {
jedisPool = new JedisPool(new JedisPoolConfig(), CONFIG_VALUE_REDIS_URI.get());
}

return jedisPool.getResource();
}


Expand All @@ -86,9 +103,50 @@ public static void onServerStopping(ServerStoppingEvent event) throws Exception
}

@SubscribeEvent
public static void onServerStarting(ServerStartingEvent event) throws IOException {
public static void onServerStarting(ServerStartingEvent event) throws Exception {
if(CONFIG_VALUE_BEHAVIOUR_AUTOSTART.get()) Start();
}

public static List<Controllable> controllables = new ArrayList<>();
public static void addControllable(Controllable controllable) {
controllables.add(controllable);
}

public static abstract class Controllable {
private final List<Jedis> jedisInstances = new ArrayList<>();
private boolean running = false;

public Controllable() {
DedicatedAppliedEnergisticsController.addControllable(this);
if(DedicatedAppliedEnergisticsController.IsRunning) this.externalStart();
}

protected abstract void onStart();
protected abstract void onStop();

protected Jedis getJedis() {
Jedis jedis = DedicatedAppliedEnergisticsController.getJedis();
jedisInstances.add(jedis);
return jedis;
}

protected boolean isRunning() {
return running;
}

public void externalStart() {
this.onStart();
this.running = true;
}

public void externalStop() {
this.running = false;
this.onStop();

jedisInstances.forEach(Jedis::disconnect);
jedisInstances.forEach(Jedis::close);
jedisInstances.clear();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,68 @@
package net.nussi.dedicated_applied_energistics.blockentities;

import appeng.api.crafting.IPatternDetails;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.KeyCounter;
import appeng.api.storage.IStorageMounts;
import appeng.api.storage.IStorageProvider;
import appeng.blockentity.grid.AENetworkBlockEntity;
import com.mojang.logging.LogUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.nussi.dedicated_applied_energistics.init.BlockEntityTypeInit;
import net.nussi.dedicated_applied_energistics.providers.InterDimensionalInterfaceCrafting;
import net.nussi.dedicated_applied_energistics.providers.InterDimensionalInterfaceStorage;
import org.slf4j.Logger;

import java.util.List;
import java.util.Set;

public class InterDimensionalInterfaceBlockEntity extends BlockEntity {

public class InterDimensionalInterfaceBlockEntity extends AENetworkBlockEntity implements IStorageProvider, ICraftingProvider {
private static final Logger LOGGER = LogUtils.getLogger();
private InterDimensionalInterfaceStorage storage;
private InterDimensionalInterfaceCrafting crafting;

public InterDimensionalInterfaceBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypeInit.INTER_DIMENSIONAL_INTERFACE_ENTITY_TYPE.get(), pos, state);

this.getMainNode().addService(IStorageProvider.class, this);
this.storage = new InterDimensionalInterfaceStorage(this);

this.getMainNode().addService(ICraftingProvider.class, this);
this.crafting = new InterDimensionalInterfaceCrafting(this);
}

@Override
public void mountInventories(IStorageMounts storageMounts) {
storage.mountInventories(storageMounts);
}

@Override
public List<IPatternDetails> getAvailablePatterns() {
return crafting.getAvailablePatterns();
}

@Override
public int getPatternPriority() {
return crafting.getPatternPriority();
}

@Override
public boolean pushPattern(IPatternDetails patternDetails, KeyCounter[] inputHolder) {
return crafting.pushPattern(patternDetails, inputHolder);
}

@Override
public boolean isBusy() {
return crafting.isBusy();
}

@Override
public Set<AEKey> getEmitableItems() {
return crafting.getEmitableItems();
}


}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
import net.minecraft.world.item.Item;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import net.nussi.dedicated_applied_energistics.items.InterDimensionalStorageCell;

import static net.nussi.dedicated_applied_energistics.DedicatedAppliedEnegistics.MODID;

public class ItemInit {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);

public static final RegistryObject<InterDimensionalStorageCell> INTER_DIMENSIONAL_STORAGE_CELL_ITEM = ITEMS.register("inter_dimensional_storage_cell", () -> new InterDimensionalStorageCell(new Item.Properties().tab(TabInit.MAIN_TAB).stacksTo(1)));


}

This file was deleted.

This file was deleted.

Loading

0 comments on commit d437361

Please sign in to comment.