From f27f142d1a7d37919a591ec3a873c71bab26ae81 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Fri, 17 Apr 2020 12:52:09 -0400 Subject: [Initial] Verison 0.0.1 --- .../java/net/corechg/sparkt/BlockRegister.java | 31 +++++++ src/main/java/net/corechg/sparkt/SparktInit.java | 19 ++++ .../net/corechg/sparkt/block/DriverMechanical.java | 9 ++ .../net/corechg/sparkt/block/MachineBlock.java | 12 +++ .../net/corechg/sparkt/block/MachineFurnace.java | 9 ++ .../net/corechg/sparkt/block/MachineGrinder.java | 9 ++ src/main/java/net/corechg/sparkt/block/Wire.java | 11 +++ .../sparkt/block/entity/MachineFurnaceEntity.java | 102 +++++++++++++++++++++ 8 files changed, 202 insertions(+) create mode 100644 src/main/java/net/corechg/sparkt/BlockRegister.java create mode 100644 src/main/java/net/corechg/sparkt/SparktInit.java create mode 100644 src/main/java/net/corechg/sparkt/block/DriverMechanical.java create mode 100644 src/main/java/net/corechg/sparkt/block/MachineBlock.java create mode 100644 src/main/java/net/corechg/sparkt/block/MachineFurnace.java create mode 100644 src/main/java/net/corechg/sparkt/block/MachineGrinder.java create mode 100644 src/main/java/net/corechg/sparkt/block/Wire.java create mode 100644 src/main/java/net/corechg/sparkt/block/entity/MachineFurnaceEntity.java (limited to 'src/main/java/net/corechg') diff --git a/src/main/java/net/corechg/sparkt/BlockRegister.java b/src/main/java/net/corechg/sparkt/BlockRegister.java new file mode 100644 index 0000000..5833055 --- /dev/null +++ b/src/main/java/net/corechg/sparkt/BlockRegister.java @@ -0,0 +1,31 @@ +package net.corechg.sparkt; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import net.corechg.sparkt.block.*; + +public class BlockRegister { + + public static final Block MACHINE_BLOCK = new MachineBlock(); + public static final Block MACHINE_FURNACE = new MachineFurnace(); + public static final Block DRIVER_MECHANICAL = new DriverMechanical(); + public static final Block MACHINE_GRINDER = new MachineGrinder(); + //public static final Block + + public static void register(String modid) { + Registry.register(Registry.BLOCK, new Identifier(modid, "machine_block"), MACHINE_BLOCK); + Registry.register(Registry.ITEM, new Identifier(modid, "machine_block"), new BlockItem(MACHINE_BLOCK, new Item.Settings())); + + Registry.register(Registry.BLOCK, new Identifier(modid, "machine_furnace"), MACHINE_FURNACE); + Registry.register(Registry.ITEM, new Identifier(modid, "machine_furnace"), new BlockItem(MACHINE_FURNACE, new Item.Settings())); + + Registry.register(Registry.BLOCK, new Identifier(modid, "driver_mechanical"), DRIVER_MECHANICAL); + Registry.register(Registry.ITEM, new Identifier(modid, "driver_mechanical"), new BlockItem(DRIVER_MECHANICAL, new Item.Settings())); + + Registry.register(Registry.BLOCK, new Identifier(modid, "machine_grinder"), MACHINE_GRINDER); + Registry.register(Registry.ITEM, new Identifier(modid, "machine_grinder"), new BlockItem(MACHINE_GRINDER, new Item.Settings())); + } +} \ No newline at end of file diff --git a/src/main/java/net/corechg/sparkt/SparktInit.java b/src/main/java/net/corechg/sparkt/SparktInit.java new file mode 100644 index 0000000..2d2d557 --- /dev/null +++ b/src/main/java/net/corechg/sparkt/SparktInit.java @@ -0,0 +1,19 @@ +package net.corechg.sparkt; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import net.fabricmc.api.ModInitializer; + +public class SparktInit implements ModInitializer { + + public static final Logger LOG = LogManager.getFormatterLogger("Sparkt|Init"); + public static final String MODID = "sparkt"; + + @Override + public void onInitialize() { + LOG.info("Preparing to spark a reaction!"); + BlockRegister.register(MODID); + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/sparkt/block/DriverMechanical.java b/src/main/java/net/corechg/sparkt/block/DriverMechanical.java new file mode 100644 index 0000000..3198120 --- /dev/null +++ b/src/main/java/net/corechg/sparkt/block/DriverMechanical.java @@ -0,0 +1,9 @@ +package net.corechg.sparkt.block; + +public class DriverMechanical extends MachineBlock{ + + public DriverMechanical() { + super(); + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/sparkt/block/MachineBlock.java b/src/main/java/net/corechg/sparkt/block/MachineBlock.java new file mode 100644 index 0000000..7e0c7bb --- /dev/null +++ b/src/main/java/net/corechg/sparkt/block/MachineBlock.java @@ -0,0 +1,12 @@ +package net.corechg.sparkt.block; + +import net.minecraft.block.Block; +import net.minecraft.block.Material; + +public class MachineBlock extends Block{ + + public MachineBlock() { + super(Settings.of(Material.METAL)); + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/sparkt/block/MachineFurnace.java b/src/main/java/net/corechg/sparkt/block/MachineFurnace.java new file mode 100644 index 0000000..f7556ca --- /dev/null +++ b/src/main/java/net/corechg/sparkt/block/MachineFurnace.java @@ -0,0 +1,9 @@ +package net.corechg.sparkt.block; + +public class MachineFurnace extends MachineBlock{ + + public MachineFurnace() { + super(); + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/sparkt/block/MachineGrinder.java b/src/main/java/net/corechg/sparkt/block/MachineGrinder.java new file mode 100644 index 0000000..49c877d --- /dev/null +++ b/src/main/java/net/corechg/sparkt/block/MachineGrinder.java @@ -0,0 +1,9 @@ +package net.corechg.sparkt.block; + +public class MachineGrinder extends MachineBlock{ + + public MachineGrinder() { + super(); + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/sparkt/block/Wire.java b/src/main/java/net/corechg/sparkt/block/Wire.java new file mode 100644 index 0000000..51f9178 --- /dev/null +++ b/src/main/java/net/corechg/sparkt/block/Wire.java @@ -0,0 +1,11 @@ +package net.corechg.sparkt.block; + +import net.minecraft.block.Block; + +public class Wire extends Block{ + + public Wire(Settings settings) { + super(settings); + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/sparkt/block/entity/MachineFurnaceEntity.java b/src/main/java/net/corechg/sparkt/block/entity/MachineFurnaceEntity.java new file mode 100644 index 0000000..edde32b --- /dev/null +++ b/src/main/java/net/corechg/sparkt/block/entity/MachineFurnaceEntity.java @@ -0,0 +1,102 @@ +package net.corechg.sparkt.block.entity; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.Tickable; + +import java.util.ArrayList; + +import net.corechg.transit.network.packet.IStaticPacket; +import net.corechg.transit.network.system.INode; +import net.corechg.transit.network.system.ISystem; +import net.corechg.transit.network.system.swap.IAcceptorNode; + +public class MachineFurnaceEntity extends BlockEntity implements IAcceptorNode, Tickable { + + private static final String[] GROUPS = { "ENERGY" }; + private int energyCap = 20000; + private int energyStored = 0; + private ArrayList connected = new ArrayList(0); + + public MachineFurnaceEntity(BlockEntityType type) { + super(type); + } + + @Override + public String[] groupsProvided() { + return GROUPS; + } + + @Override + public ISystem getSystem() { + return null; + } + + @Override + public Object getData(String groupID) { + if (groupID == "ENERGY") { + return energyStored; + } + return null; + } + + @Override + public void setData(Object dat, String groupID) { + if (groupID == "ENERGY") { + int tmp = (int) dat; + + energyStored = tmp > energyCap ? energyCap : tmp; + } + + } + + @Override + public INode[] getConnections() { + return (INode[]) connected.toArray(); + } + + @Override + public void tick() { + + } + + @Override + public boolean linkProvider(INode requester, String group) { + if (group == "ENERGY") { + connected.add(requester); + } + return false; + } + + @Override + public boolean unlinkProvider(INode toUnlink) { + for(int i = 0; i < connected.size(); i++) { + if(toUnlink.equals(connected.get(i))) { + connected.remove(i); + return true; + } + } + return false; + } + + @Override + public INode[] getProviders() { + return getConnections(); + } + + @Override + public boolean accept(IStaticPacket packet, String group) { + if (group == "ENERGY") { + int add = (int) packet.getType().toBase(packet, group); + if(add + energyStored > energyCap) { + return false; + } + else { + energyStored += add; + return true; + } + } + return false; + } + +} \ No newline at end of file -- cgit v1.2.3