From 11b5d14ccd8598eadc48f2039196e46807ead9fb Mon Sep 17 00:00:00 2001 From: Astoria Date: Fri, 31 Mar 2023 08:58:59 -0500 Subject: [PATCH] Version Alpha One --- gradle.properties | 4 +- .../net/brokenmoon/afloydwiremod/WireMod.java | 33 +++++ .../afloydwiremod/api/IWireConnectable.java | 6 + .../afloydwiremod/api/WireConnection.java | 49 +++++++ .../afloydwiremod/gui/GuiButtonExtended.java | 20 +++ .../afloydwiremod/gui/GuiProgrammer.java | 33 +++++ .../afloydwiremod/gui/GuiWiring.java | 71 +++++++++ .../afloydwiremod/gui/WiringButton.java | 43 ++++++ .../afloydwiremod/item/ToolProgrammer.java | 10 ++ .../afloydwiremod/item/ToolWiring.java | 23 +++ .../mixin/MixinEntityPlayerSP.java | 25 ++++ .../afloydwiremod/mixin/MixinTileEntity.java | 18 +++ .../mixinInterfaces/IEntityPlayer.java | 10 ++ .../afloydwiremod/tile/ChipTile.java | 62 ++++++++ .../afloydwiremod/tile/RedstoneLinkTile.java | 95 ++++++++++++ .../tileentity/ChipTileEntity.java | 135 ++++++++++++++++++ .../tileentity/RedstoneLinkTileEntity.java | 52 +++++++ .../turniplabs/examplemod/ExampleMod.java | 16 --- ....mixins.json => afloydwiremod.mixins.json} | 4 +- .../afloydwiremod/block/testTexture.png | Bin 0 -> 579 bytes .../assets/afloydwiremod/item/testTexture.png | Bin 0 -> 579 bytes src/main/resources/fabric.mod.json | 18 ++- .../resources/lang/afloydwiremod/en_US.lang | 4 + src/main/resources/lang/examplemod/en_US.lang | 0 24 files changed, 706 insertions(+), 25 deletions(-) create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/WireMod.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/api/IWireConnectable.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/gui/WiringButton.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/item/ToolProgrammer.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinTileEntity.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/tile/ChipTile.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java delete mode 100644 src/main/java/turniplabs/examplemod/ExampleMod.java rename src/main/resources/{examplemod.mixins.json => afloydwiremod.mixins.json} (62%) create mode 100644 src/main/resources/assets/afloydwiremod/block/testTexture.png create mode 100644 src/main/resources/assets/afloydwiremod/item/testTexture.png create mode 100644 src/main/resources/lang/afloydwiremod/en_US.lang delete mode 100644 src/main/resources/lang/examplemod/en_US.lang diff --git a/gradle.properties b/gradle.properties index 18b8f4a..00c9f43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,5 @@ halplibe_version=1.0.9 # Mod mod_version=1.0.0 -mod_group=turniplabs -mod_name=examplemod +mod_group=net.brokenmoon +mod_name=afloydwiremod diff --git a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java new file mode 100644 index 0000000..0f60847 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java @@ -0,0 +1,33 @@ +package net.brokenmoon.afloydwiremod; + +import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.tile.ChipTile; +import net.brokenmoon.afloydwiremod.item.ToolProgrammer; +import net.brokenmoon.afloydwiremod.tile.RedstoneLinkTile; +import net.fabricmc.api.ModInitializer; +import net.minecraft.src.Block; +import net.minecraft.src.Item; +import net.minecraft.src.Material; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import turniplabs.halplibe.helper.BlockHelper; +import turniplabs.halplibe.helper.ItemHelper; + + +public class WireMod implements ModInitializer { + public static final String MOD_ID = "afloydwiremod"; + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + + public static Block ChipTile = BlockHelper.createBlock(MOD_ID, new ChipTile(905, Material.iron), "chipTile", "testTexture.png", Block.soundMetalFootstep,5, 5, 0 ); + + public static Item ToolProgrammer = ItemHelper.createItem(MOD_ID, new ToolProgrammer(906), "toolProgrammer", "testTexture.png"); + public static Item ToolWiring = ItemHelper.createItem(MOD_ID, new ToolWiring(907), "toolWiring", "testTexture.png"); + + public static Block LinkTileInactive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(908, Material.iron, false), "linkTile", "testTexture.png", Block.soundStoneFootstep, 5, 5, 0); + public static Block LinkTileActive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(909, Material.iron, true), "linkTile", "testTexture.png", Block.soundStoneFootstep, 5, 5, 0); + + @Override + public void onInitialize() { + LOGGER.info("WireMod initialized."); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/IWireConnectable.java b/src/main/java/net/brokenmoon/afloydwiremod/api/IWireConnectable.java new file mode 100644 index 0000000..a4617ef --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/IWireConnectable.java @@ -0,0 +1,6 @@ +package net.brokenmoon.afloydwiremod.api; + +import java.util.ArrayList; + +public interface IWireConnectable { +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java new file mode 100644 index 0000000..c5888c7 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java @@ -0,0 +1,49 @@ +package net.brokenmoon.afloydwiremod.api; + +import net.brokenmoon.afloydwiremod.gui.WiringButton; +import net.minecraft.src.NBTTagCompound; + +public class WireConnection { + public int x; + public int y; + public int z; + public int thisslot; + public int thatslot; + + public WireConnection(){ + + } + public WireConnection(int x, int y, int z, int thisslot){ + this.x = x; + this.y = y; + this.z = z; + this.thisslot = thisslot; + } + + public WireConnection(int x, int y, int z, int thisslot, int thatslot){ + this.x = x; + this.y = y; + this.z = z; + this.thisslot = thisslot; + this.thatslot = thatslot; + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { + nbttagcompound.setInteger("wx", this.x); + nbttagcompound.setInteger("wy", this.y); + nbttagcompound.setInteger("wz", this.z); + nbttagcompound.setInteger("wthisslot", thisslot); + nbttagcompound.setInteger("wthatslot", thatslot); + System.out.println("Writing wires to nbt"); + return nbttagcompound; + } + + public void readFromNBT(NBTTagCompound nbttagcompound) { + this.x = nbttagcompound.getInteger("wx"); + this.y = nbttagcompound.getInteger("wy"); + this.z = nbttagcompound.getInteger("wz"); + this.thisslot = nbttagcompound.getInteger("wthisslot"); + this.thatslot = nbttagcompound.getInteger("wthatslot"); + System.out.println("Loading wires from nbt"); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java new file mode 100644 index 0000000..7cb0bc7 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java @@ -0,0 +1,20 @@ +package net.brokenmoon.afloydwiremod.gui; + +import net.minecraft.src.GuiButton; + +public class GuiButtonExtended extends GuiButton { + + public String type; + public int slot; + public GuiButtonExtended(int xPosition, int yPosition, String s, String extra, int slot) { + super(0, xPosition, yPosition, s); + this.type = extra; + this.slot = slot; + } + + public GuiButtonExtended(int xPosition, int yPosition, int width, int height, String s, String extra, int slot) { + super(0, xPosition, yPosition, width, height, s); + this.type = extra; + this.slot = slot; + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java new file mode 100644 index 0000000..e9f34af --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -0,0 +1,33 @@ +package net.brokenmoon.afloydwiremod.gui; + +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.minecraft.src.*; + +public class GuiProgrammer extends GuiScreen { + + private ChipTileEntity chip; + + @Override + public void initGui() { + //this.height - 240 is top + //This.width / 2 + this.controlList.add(new GuiButton(1, this.width / 2 - 214, this.height - 240, "Constant")); + this.controlList.add(new GuiButton(2, this.width / 2 - 214, this.height - 220, "Count")); + } + + public GuiProgrammer(EntityPlayer player, ChipTileEntity chip) { + super.initGui(); + this.chip = chip; + } + + @Override + protected void actionPerformed(GuiButton guibutton) { + if (guibutton.id == 1) { + chip.setMode("constant"); + } else if(guibutton.id == 2){ + chip.setMode("count"); + } + this.mc.displayGuiScreen(null); + } + +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java new file mode 100644 index 0000000..b473fc9 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java @@ -0,0 +1,71 @@ +package net.brokenmoon.afloydwiremod.gui; + +import net.brokenmoon.afloydwiremod.api.WireConnection; +import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.GuiButton; +import net.minecraft.src.GuiScreen; +import net.minecraft.src.TileEntity; + +public class GuiWiring extends GuiScreen { + private ToolWiring tool; + + private int x; + private int y; + private int z; + private ChipTileEntity chip; + @Override + public void initGui() { + //this.height - 240 is top + //This.width / 2 - 214 is left + //Inputs + if(chip.inputs != null && this.tool.type.equals("output")) { + for (int i = 0; i < chip.inputs.length; i++) { + this.controlList.add(new GuiButtonExtended(this.width / 2 - chip.inputs[i].x, this.height - chip.inputs[i].y, chip.inputs[i].buttonString, "Input", chip.inputs[i].slot)); + } + } + //Outputs + if(chip.outputs != null && !this.tool.type.equals("output")) { + for (int i = 0; i < chip.outputs.length; i++) { + this.controlList.add(new GuiButtonExtended(this.width / 2 - chip.outputs[i].x, this.height - chip.outputs[i].y, chip.outputs[i].buttonString, "Output", chip.outputs[i].slot)); + } + } + } + + public GuiWiring(EntityPlayer player, ToolWiring tool, ChipTileEntity chip, int x, int y, int z) { + super.initGui(); + this.tool = tool; + this.x = x; + this.y = y; + this.z = z; + this.chip = chip; + } + + @Override + protected void actionPerformed(GuiButton guiButton){ + this.actionPerformed((GuiButtonExtended)guiButton); + } + protected void actionPerformed(GuiButtonExtended guibutton) { + if(this.tool.type.equals("unpaired")) { + if (guibutton.type.equals("Input")) { + this.tool.type = "input"; + this.tool.slot = guibutton.slot; + this.tool.x = x; + this.tool.y = y; + this.tool.z = z; + } else if (guibutton.type.equals("Output")) { + this.tool.type = "output"; + this.tool.slot = guibutton.slot; + this.tool.x = x; + this.tool.y = y; + this.tool.z = z; + } + } else if(this.tool.type.equals("output")) { + this.chip.inputs[guibutton.slot].wire = new WireConnection(tool.x, tool.y, tool.z, guibutton.slot, tool.slot); + System.out.print(guibutton.slot + " " + tool.slot); + tool.type = "unpaired"; + } + this.mc.displayGuiScreen(null); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/WiringButton.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/WiringButton.java new file mode 100644 index 0000000..4eb4c85 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/WiringButton.java @@ -0,0 +1,43 @@ +package net.brokenmoon.afloydwiremod.gui; +import net.brokenmoon.afloydwiremod.api.WireConnection; +import net.minecraft.src.NBTTagCompound; + +public class WiringButton { + public int x; + public int y; + public String buttonString; + public int slot; + public float floatvalue; + public String stringvalue = ""; + public WireConnection wire = new WireConnection(); + public WiringButton(){ + + } + public WiringButton(int x, int y, String buttonString, int slot){ + this.x = x; + this.y = y; + this.buttonString = buttonString; + this.slot = slot; + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { + nbttagcompound.setInteger("bx", this.x); + nbttagcompound.setInteger("by", this.y); + nbttagcompound.setString("bbuttonString", buttonString); + nbttagcompound.setInteger("bslot", slot); + nbttagcompound.setFloat("bfloatvalue", floatvalue); + nbttagcompound.setString("bstringvalue", stringvalue); + wire.writeToNBT(nbttagcompound); + return nbttagcompound; + } + + public void readFromNBT(NBTTagCompound nbttagcompound) { + this.x = nbttagcompound.getInteger("bx"); + this.y = nbttagcompound.getInteger("by"); + this.buttonString = nbttagcompound.getString("bbuttonString"); + this.slot = nbttagcompound.getInteger("bslot"); + this.floatvalue = nbttagcompound.getFloat("bfloatvalue"); + this.stringvalue = nbttagcompound.getString("bstringvalue"); + wire.readFromNBT(nbttagcompound); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/item/ToolProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/item/ToolProgrammer.java new file mode 100644 index 0000000..a0f5853 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/item/ToolProgrammer.java @@ -0,0 +1,10 @@ +package net.brokenmoon.afloydwiremod.item; + +import net.minecraft.src.Item; + +public class ToolProgrammer extends Item { + public ToolProgrammer(int i) { + super(i); + this.maxStackSize = 1; + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java new file mode 100644 index 0000000..2f98bad --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java @@ -0,0 +1,23 @@ +package net.brokenmoon.afloydwiremod.item; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; +import net.minecraft.src.World; + +public class ToolWiring extends Item { + + public int x = 0; + public int y = 0; + public int z = 0; + public String type = "unpaired"; + public int slot; + public ToolWiring(int i) { + super(i); + this.maxStackSize = 1; + } + + public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l, double heightPlaced) { + return false; + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java new file mode 100644 index 0000000..89d2493 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java @@ -0,0 +1,25 @@ +package net.brokenmoon.afloydwiremod.mixin; + +import net.brokenmoon.afloydwiremod.gui.GuiProgrammer; +import net.brokenmoon.afloydwiremod.gui.GuiWiring; +import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.minecraft.client.Minecraft; +import net.minecraft.src.EntityPlayerSP; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = EntityPlayerSP.class, remap = false) +public class MixinEntityPlayerSP implements IEntityPlayer { + @Shadow + protected Minecraft mc; + public void displayGuiProgrammer(ChipTileEntity chip) { + this.mc.displayGuiScreen(new GuiProgrammer(((EntityPlayerSP)(Object)this), chip)); + } + + @Override + public void displayGuiWiring(ToolWiring tool, ChipTileEntity chip, int x, int y, int z) { + this.mc.displayGuiScreen(new GuiWiring(((EntityPlayerSP)(Object)this), tool, chip, x, y, z)); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinTileEntity.java new file mode 100644 index 0000000..917f287 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinTileEntity.java @@ -0,0 +1,18 @@ +package net.brokenmoon.afloydwiremod.mixin; + +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.brokenmoon.afloydwiremod.tileentity.RedstoneLinkTileEntity; +import net.minecraft.src.TileEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = TileEntity.class, remap = false) +public class MixinTileEntity { + @Shadow + private static void addMapping(Class class1, String s) {} + + static { + addMapping(ChipTileEntity.class, "Chip"); + addMapping(RedstoneLinkTileEntity.class, "Link"); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java new file mode 100644 index 0000000..0e00a3b --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java @@ -0,0 +1,10 @@ +package net.brokenmoon.afloydwiremod.mixinInterfaces; + +import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; + +public interface IEntityPlayer { + public void displayGuiProgrammer(ChipTileEntity chip); + + public void displayGuiWiring(ToolWiring tool, ChipTileEntity chip, int x, int y, int z); +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tile/ChipTile.java b/src/main/java/net/brokenmoon/afloydwiremod/tile/ChipTile.java new file mode 100644 index 0000000..1667103 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/tile/ChipTile.java @@ -0,0 +1,62 @@ +package net.brokenmoon.afloydwiremod.tile; + +import net.brokenmoon.afloydwiremod.WireMod; +import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.brokenmoon.afloydwiremod.tileentity.RedstoneLinkTileEntity; +import net.minecraft.src.*; + +public class ChipTile extends BlockContainer { + public ChipTile(int i, Material material) { + super(i, material); + } + + @Override + public void onBlockRemoval(World world, int i, int j, int k) { + super.onBlockRemoval(world, i, j, k); + } + @Override + public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player){ + ChipTileEntity chip = (ChipTileEntity)world.getBlockTileEntity(x, y, z); + if (!world.isMultiplayerAndNotHost) { + if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().itemID == WireMod.ToolProgrammer.itemID && chip.mode.equals("none")) { + this.displayProgrammingGui(player, chip); + return true; + } else if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().itemID == WireMod.ToolWiring.itemID && !chip.mode.equals("none")) { + ToolWiring tool = ((ToolWiring)player.inventory.getCurrentItem().getItem()); + this.displayWiringGui(player, chip, tool, x, y, z); + return true; + } + if(chip instanceof RedstoneLinkTileEntity) + System.out.println(((RedstoneLinkTileEntity)chip).inputs[0].wire.x); + } + return false; + } + + private void displayWiringGui(EntityPlayer player, ChipTileEntity chip, ToolWiring tool, int x, int y, int z) { + if(player instanceof EntityPlayerMP) { + //Multiplayer + ((IEntityPlayer)player).displayGuiWiring(tool, chip, x, y, z); + return; + } + //Singleplayer + ((IEntityPlayer)player).displayGuiWiring(tool, chip, x, y, z); + } + + public static void displayProgrammingGui(EntityPlayer player, ChipTileEntity chip){ + if(player instanceof EntityPlayerMP) { + //Multiplayer + ((IEntityPlayer)player).displayGuiProgrammer(chip); + return; + } + //Singleplayer + ((IEntityPlayer)player).displayGuiProgrammer(chip); + + } + + @Override + protected TileEntity getBlockEntity() { + return new ChipTileEntity(); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java b/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java new file mode 100644 index 0000000..c6ffb9a --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java @@ -0,0 +1,95 @@ +package net.brokenmoon.afloydwiremod.tile; + +import net.brokenmoon.afloydwiremod.WireMod; +import net.brokenmoon.afloydwiremod.tileentity.RedstoneLinkTileEntity; +import net.minecraft.src.*; + +import java.util.Random; + +public class RedstoneLinkTile extends ChipTile { + + public RedstoneLinkTile(int i, Material material, boolean isActive) { + super(i, material); + this.isActive = isActive; + this.setTickOnLoad(true); + } + boolean isActive; + + @Override + public boolean renderAsNormalBlock(){ + return false; + } + public static void updateLinkBlockState(boolean flag, World world, int x, int y, int z) { + if (flag) { + world.setBlockAndMetadataWithNotify(x, y, z, WireMod.LinkTileActive.blockID, 1); + System.out.println("activating"); + } + if (!flag) { + world.setBlockAndMetadataWithNotify(x, y, z, WireMod.LinkTileInactive.blockID, 1); + System.out.println("deactivating"); + } + } + + @Override + public int tickRate() { + return 2; + } + + @Override + public void onBlockAdded(World world, int x, int y, int z) { + if(world.getBlockMetadata(x, y, z) == 0){ + world.setBlockTileEntity(x, y, z, new RedstoneLinkTileEntity()); + } + } + + @Override + public void onBlockRemoval(World world, int x, int y, int z) { + if(world.getBlockTileEntity(x, y, z) != null && !((RedstoneLinkTileEntity)world.getBlockTileEntity(x, y, z)).shouldnotremove) + super.onBlockRemoval(world, x, y, z); + } + + @Override + public void updateTick(World world, int i, int j, int k, Random random) { + RedstoneLinkTileEntity link = (RedstoneLinkTileEntity)world.getBlockTileEntity(i, j, k); + if (world.isBlockGettingPowered(i, j, k)) { + link.outputs[0].floatvalue = 1.0f; + } else { + link.outputs[0].floatvalue = 0.0f; + } + } + + @Override + public boolean canProvidePower() { + return true; + } + + @Override + public boolean isPoweringTo(IBlockAccess iblockaccess, int i, int j, int k, int l) { + return this.isActive; + } + + @Override + public boolean isIndirectlyPoweringTo(World world, int i, int j, int k, int l) { + return this.isPoweringTo(world, i, j, k, l); + } + + @Override + protected TileEntity getBlockEntity() { + return new RedstoneLinkTileEntity(); + } + + @Override + public void onNeighborBlockChange(World world, int i, int j, int k, int l) { + world.scheduleBlockUpdate(i, j, k, this.blockID, this.tickRate()); + } + + @Override + public int idDropped(int i, Random random) { + return WireMod.LinkTileInactive.blockID; + } + + @Override + protected int damageDropped(int i) { + return i; + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java new file mode 100644 index 0000000..b8af53d --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -0,0 +1,135 @@ +package net.brokenmoon.afloydwiremod.tileentity; + +import net.brokenmoon.afloydwiremod.api.IWireConnectable; +import net.brokenmoon.afloydwiremod.api.WireConnection; +import net.brokenmoon.afloydwiremod.gui.WiringButton; +import net.minecraft.client.Minecraft; +import net.minecraft.src.*; + +import java.util.ArrayList; + +public class ChipTileEntity extends TileEntity implements IWireConnectable { + + public WiringButton[] inputs = null; + public WiringButton[] outputs = null; + public String mode = "none"; + + @Override + public void updateEntity() { + updateIO(); + switch(mode){ + case "count": + doIncrement(); + break; + } + } + + private boolean shouldIncrement = true; + public void doIncrement(){ + if(this.inputs[2].floatvalue > 0){ + this.outputs[0].floatvalue = 0; + return; + } + if(this.inputs[1].floatvalue > 0 && shouldIncrement){ + this.outputs[0].floatvalue = this.outputs[0].floatvalue + this.inputs[0].floatvalue; + shouldIncrement = false; + System.out.println("Incrementing to " + this.outputs[0].floatvalue); + } else if(this.inputs[1].floatvalue == 0.0 && !shouldIncrement){ + shouldIncrement = true; + } + } + + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + this.mode = nbttagcompound.getString("mode"); + if(nbttagcompound.getBoolean("inputExists")){ + this.inputs = new WiringButton[nbttagcompound.getInteger("inputLength")]; + NBTTagList nbttaglistInputs = nbttagcompound.getTagList("Inputs"); + for (int i = 0; i < nbttaglistInputs.tagCount(); ++i) { + NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglistInputs.tagAt(i); + this.inputs[i] = new WiringButton(); + this.inputs[i].readFromNBT(nbttagcompound1); + } + } + if(nbttagcompound.getBoolean("outputExists")){ + this.outputs = new WiringButton[nbttagcompound.getInteger("outputLength")]; + NBTTagList nbttaglistOutputs = nbttagcompound.getTagList("Outputs"); + for (int i = 0; i < nbttaglistOutputs.tagCount(); ++i) { + NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglistOutputs.tagAt(i); + this.outputs[i] = new WiringButton(); + this.outputs[i].readFromNBT(nbttagcompound1); + } + } + } + + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + nbttagcompound.setString("mode", mode); + if(inputs != null){ + nbttagcompound.setBoolean("inputExists", true); + nbttagcompound.setInteger("inputLength", inputs.length); + NBTTagList nbttaglistInputs = new NBTTagList(); + for(int i = 0; i < this.inputs.length; ++i){ + NBTTagCompound nbttagInput = new NBTTagCompound(); + this.inputs[i].writeToNBT(nbttagInput); + nbttaglistInputs.setTag(nbttagInput); + } + nbttagcompound.setTag("Inputs", nbttaglistInputs); + } else { + nbttagcompound.setBoolean("inputExists", false); + } + if(outputs != null){ + nbttagcompound.setBoolean("outputExists", true); + nbttagcompound.setInteger("outputLength", outputs.length); + NBTTagList nbttaglistOutputs = new NBTTagList(); + for(int i = 0; i < this.outputs.length; ++i){ + NBTTagCompound nbttagOutput = new NBTTagCompound(); + this.outputs[i].writeToNBT(nbttagOutput); + nbttaglistOutputs.setTag(nbttagOutput); + } + nbttagcompound.setTag("Outputs", nbttaglistOutputs); + } else { + nbttagcompound.setBoolean("outputExists", false); + } + } + + public void setMode(String string){ + if(mode.equals("none")) { + if(string.equals("constant")) { + System.out.println(string); + mode = string; + this.inputs = new WiringButton[0]; + this.outputs = new WiringButton[1]; + } else if(string.equals("count")){ + System.out.println(string); + mode = string; + this.inputs = new WiringButton[3]; + this.outputs = new WiringButton[1]; + this.outputs[0] = new WiringButton(214, 240, "Output", 0); + this.inputs[0] = new WiringButton(214, 220, "Source", 0); + this.inputs[1] = new WiringButton(214, 200, "Clock", 1); + this.inputs[2] = new WiringButton(214, 180, "Reset", 2); + System.out.println("ae"); + } + } + } + + public void updateIO(){ + if(inputs != null) { + for (int i = 0; i < inputs.length; ++i) { + if (inputs[i].wire != null && inputs[i].wire.thisslot > -1) { + WireConnection wire = inputs[i].wire; + ChipTileEntity otherChip = (ChipTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); + if(otherChip == null) break; + if(otherChip.outputs == null) break; + if(inputs[i].floatvalue != otherChip.outputs[wire.thatslot].floatvalue) { + inputs[i].floatvalue = otherChip.outputs[wire.thatslot].floatvalue; + } + if(!inputs[i].stringvalue.equals(otherChip.outputs[wire.thatslot].stringvalue)) { + inputs[i].stringvalue = otherChip.outputs[wire.thatslot].stringvalue; + } + } + } + } + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java new file mode 100644 index 0000000..2780d61 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java @@ -0,0 +1,52 @@ +package net.brokenmoon.afloydwiremod.tileentity; + +import net.brokenmoon.afloydwiremod.WireMod; +import net.brokenmoon.afloydwiremod.api.IWireConnectable; +import net.brokenmoon.afloydwiremod.api.WireConnection; +import net.brokenmoon.afloydwiremod.gui.WiringButton; +import net.brokenmoon.afloydwiremod.tile.RedstoneLinkTile; +import net.minecraft.src.BlockSensor; +import net.minecraft.src.NBTTagCompound; +import net.minecraft.src.NBTTagList; +import net.minecraft.src.TileEntity; + +public class RedstoneLinkTileEntity extends ChipTileEntity { + + public boolean isActive = false; + public boolean shouldnotremove = false; + public RedstoneLinkTileEntity(){ + super(); + this.mode = "rslink"; + inputs = new WiringButton[1]; + outputs = new WiringButton[1]; + outputs[0] = new WiringButton(214, 240, "Output", 0); + inputs[0] = new WiringButton(214, 220, "Input", 0); + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + this.isActive = nbttagcompound.getBoolean("activity"); + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + nbttagcompound.setBoolean("activity", this.isActive); + } + @Override + public void updateEntity() { + updateIO(); + if(inputs[0].floatvalue > 0 && !this.isActive && worldObj.blockExists(xCoord, yCoord, zCoord) && worldObj.getBlockId(xCoord, yCoord, zCoord) == WireMod.LinkTileInactive.blockID){ + this.shouldnotremove = true; + RedstoneLinkTile.updateLinkBlockState(true, this.worldObj, this.xCoord, this.yCoord, this.zCoord); + this.shouldnotremove = false; + this.isActive = true; + } else if(inputs[0].floatvalue == 0 && this.isActive && worldObj.blockExists(xCoord, yCoord, zCoord) && worldObj.getBlockId(xCoord, yCoord, zCoord) == WireMod.LinkTileActive.blockID){ + this.shouldnotremove = true; + RedstoneLinkTile.updateLinkBlockState(false, this.worldObj, this.xCoord, this.yCoord, this.zCoord); + this.shouldnotremove = false; + this.isActive = false; + } + } +} diff --git a/src/main/java/turniplabs/examplemod/ExampleMod.java b/src/main/java/turniplabs/examplemod/ExampleMod.java deleted file mode 100644 index eb07098..0000000 --- a/src/main/java/turniplabs/examplemod/ExampleMod.java +++ /dev/null @@ -1,16 +0,0 @@ -package turniplabs.examplemod; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class ExampleMod implements ModInitializer { - public static final String MOD_ID = "examplemod"; - public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); - - @Override - public void onInitialize() { - LOGGER.info("ExampleMod initialized."); - } -} diff --git a/src/main/resources/examplemod.mixins.json b/src/main/resources/afloydwiremod.mixins.json similarity index 62% rename from src/main/resources/examplemod.mixins.json rename to src/main/resources/afloydwiremod.mixins.json index e98223c..4a1cfc6 100644 --- a/src/main/resources/examplemod.mixins.json +++ b/src/main/resources/afloydwiremod.mixins.json @@ -1,9 +1,11 @@ { "required": true, "minVersion": "0.8", - "package": "turniplabs.examplemod.mixin", + "package": "net.brokenmoon.afloydwiremod.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ + "MixinTileEntity", + "MixinEntityPlayerSP" ], "client": [ ], diff --git a/src/main/resources/assets/afloydwiremod/block/testTexture.png b/src/main/resources/assets/afloydwiremod/block/testTexture.png new file mode 100644 index 0000000000000000000000000000000000000000..1488d632adeb6ec79530c8828162f976f093ae40 GIT binary patch literal 579 zcmV-J0=)f+P)EX>4Tx04R}tkv&MmKpe$iQ$>-AgGE#nGE^tKsEA{&LJ=y2TA@`3lS{v#Nkfw2 z;wZQl9Q;_UI=DFN>fkB}f*&BRE>4OrQsV!TLW>v=j{EWM-sA2aAk@oDvpQmcrrTyJ z5f?MrRk7<8K@0&Hz^KeDV@{Hi@Eu?G2=MhT%Cr2>{W*HooW+2ENE~B^X%lY{&urQT z=Y8TZE6OVIIq`%^7bJe2k0~gmVP1yr3cYwhsLpEhs3eptvdEotwz9|dz-vT{rUT@8PoIU_)>MD5y92^4U z1GB02m*lH+J&?000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}0000k zNklXw`Y?e322|4z!`ZiI+F})FVjvOFUIPm;?nV|LgnnQgjfX+u2LMgj7$rji R3Ml{p002ovPDHLkV1m}K>w5qI literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/afloydwiremod/item/testTexture.png b/src/main/resources/assets/afloydwiremod/item/testTexture.png new file mode 100644 index 0000000000000000000000000000000000000000..1488d632adeb6ec79530c8828162f976f093ae40 GIT binary patch literal 579 zcmV-J0=)f+P)EX>4Tx04R}tkv&MmKpe$iQ$>-AgGE#nGE^tKsEA{&LJ=y2TA@`3lS{v#Nkfw2 z;wZQl9Q;_UI=DFN>fkB}f*&BRE>4OrQsV!TLW>v=j{EWM-sA2aAk@oDvpQmcrrTyJ z5f?MrRk7<8K@0&Hz^KeDV@{Hi@Eu?G2=MhT%Cr2>{W*HooW+2ENE~B^X%lY{&urQT z=Y8TZE6OVIIq`%^7bJe2k0~gmVP1yr3cYwhsLpEhs3eptvdEotwz9|dz-vT{rUT@8PoIU_)>MD5y92^4U z1GB02m*lH+J&?000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}0000k zNklXw`Y?e322|4z!`ZiI+F})FVjvOFUIPm;?nV|LgnnQgjfX+u2LMgj7$rji R3Ml{p002ovPDHLkV1m}K>w5qI literal 0 HcmV?d00001 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c93d2bc..61bdcd9 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,12 +1,12 @@ { "schemaVersion": 1, - "id": "examplemod", + "id": "afloydwiremod", "version": "${version}", - "name": "Example Mod", - "description": "This mod aims to help new BTA modders.", + "name": "Wire Mod", + "description": "A mod inspired by the gmod WireMod.", "authors": [ - "Turnip Labs" + "Astoria" ], "contact": { "homepage": "", @@ -18,16 +18,22 @@ "environment": "*", "entrypoints": { "main": [ - "turniplabs.examplemod.ExampleMod" + "net.brokenmoon.afloydwiremod.WireMod" ] }, "mixins": [ - "examplemod.mixins.json" + "afloydwiremod.mixins.json" ], "depends": { "fabricloader": ">=0.13.3" }, "suggests": { + }, + "custom": { + "loom:injected_interfaces": { + "net/minecraft/src/EntityPlayerSP": ["net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer"], + "net/minecraft/src/EntityPlayerMP": ["net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer"] + } } } diff --git a/src/main/resources/lang/afloydwiremod/en_US.lang b/src/main/resources/lang/afloydwiremod/en_US.lang new file mode 100644 index 0000000..8f8ba75 --- /dev/null +++ b/src/main/resources/lang/afloydwiremod/en_US.lang @@ -0,0 +1,4 @@ +item.afloydwiremod.toolProgrammer.name=Programming Tool +item.afloydwiremod.toolProgrammer.disc=Used to program chips. +tile.afloydwiremod.chipTile.name=Chip +tile.afloydwiremod.chipTile.disc=Used to preform mathematical calculations. \ No newline at end of file diff --git a/src/main/resources/lang/examplemod/en_US.lang b/src/main/resources/lang/examplemod/en_US.lang deleted file mode 100644 index e69de29..0000000