diff --git a/gradle.properties b/gradle.properties index 18b8f4a..c096217 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=afloydironchest diff --git a/src/main/java/net/brokenmoon/afloydironchest/IronChestMain.java b/src/main/java/net/brokenmoon/afloydironchest/IronChestMain.java new file mode 100644 index 0000000..4248cc5 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/IronChestMain.java @@ -0,0 +1,23 @@ +package net.brokenmoon.afloydironchest; + +import net.brokenmoon.afloydironchest.blocks.IronChest; +import net.fabricmc.api.ModInitializer; +import net.minecraft.src.Block; +import net.minecraft.src.Material; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import turniplabs.halplibe.helper.BlockHelper; + + +public class IronChestMain implements ModInitializer { + public static final String MOD_ID = "ironchest"; + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + + public static Block IronChest = BlockHelper.createBlock(MOD_ID, new IronChest(900, Material.iron), "ironchest", "ironchest.png", Block.soundMetalFootstep, 5, 6, 0); + + @Override + public void onInitialize() { + LOGGER.info("AFloydIronChest initialized."); + System.out.println("e"); + } +} diff --git a/src/main/java/net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerMP.java b/src/main/java/net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerMP.java new file mode 100644 index 0000000..f9ee7e9 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerMP.java @@ -0,0 +1,7 @@ +package net.brokenmoon.afloydironchest.MixinInterfaces; + +import net.minecraft.src.IInventory; + +public interface IEntityPlayerMP { + public void displayGUIIronChest(IInventory iinventory); +} diff --git a/src/main/java/net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerSP.java b/src/main/java/net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerSP.java new file mode 100644 index 0000000..95562c6 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerSP.java @@ -0,0 +1,7 @@ +package net.brokenmoon.afloydironchest.MixinInterfaces; + +import net.minecraft.src.IInventory; + +public interface IEntityPlayerSP { + public void displayGUIIronChest(IInventory iinventory); +} diff --git a/src/main/java/net/brokenmoon/afloydironchest/blocks/IronChest.java b/src/main/java/net/brokenmoon/afloydironchest/blocks/IronChest.java new file mode 100644 index 0000000..334e830 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/blocks/IronChest.java @@ -0,0 +1,36 @@ +package net.brokenmoon.afloydironchest.blocks; + +import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerMP; +import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerSP; +import net.brokenmoon.afloydironchest.tileEntities.TileEntityIronChest; +import net.minecraft.src.*; + +public class IronChest extends BlockContainer { + public IronChest(int id, Material blockMaterial){ + super(id, blockMaterial); + } + + @Override + public boolean blockActivated(World world, int x, int y, int z, EntityPlayer entityplayer) { + IInventory chest = (TileEntityIronChest)world.getBlockTileEntity(x, y, z); + if (!world.isMultiplayerAndNotHost) { + this.displayGui(entityplayer, chest); + } + return true; + } + + @Override + protected TileEntity getBlockEntity() { + return new TileEntityIronChest(); + } + + public static void displayGui(EntityPlayer player, IInventory inventory){ + if(player instanceof EntityPlayerMP) { + //Multiplayer + ((IEntityPlayerMP)player).displayGUIIronChest(inventory); + return; + } + //Singleplayer + ((IEntityPlayerSP)player).displayGUIIronChest(inventory); + } +} diff --git a/src/main/java/net/brokenmoon/afloydironchest/gui/GuiIronChest.java b/src/main/java/net/brokenmoon/afloydironchest/gui/GuiIronChest.java new file mode 100644 index 0000000..31a19cc --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/gui/GuiIronChest.java @@ -0,0 +1,48 @@ +package net.brokenmoon.afloydironchest.gui; + +import net.minecraft.src.ContainerChest; +import net.minecraft.src.GuiContainer; +import net.minecraft.src.IInventory; +import org.lwjgl.opengl.GL11; + +public class GuiIronChest extends GuiContainer { + private IInventory upperChestInventory; + private IInventory lowerChestInventory; + private int inventoryRows; + + public GuiIronChest(IInventory iinventory, IInventory iinventory1) { + super(new ContainerChest(iinventory, iinventory1)); + this.upperChestInventory = iinventory; + this.lowerChestInventory = iinventory1; + this.field_948_f = false; + int c = 222; + int i = c - 108; + this.inventoryRows = iinventory1.getSizeInventory() / 9; + this.ySize = i + this.inventoryRows * 18; + } + + @Override + protected void drawGuiContainerForegroundLayer() { + this.fontRenderer.drawString(this.lowerChestInventory.getInvName(), 8, 6, 0x404040); + this.fontRenderer.drawString(this.upperChestInventory.getInvName(), 8, this.ySize - 96 + 2, 0x404040); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float f) { + int i = this.mc.renderEngine.getTexture("/gui/container.png"); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(i); + int x = (this.width - this.xSize) / 2; + int y = (this.height - this.ySize) / 2; + int h1 = Math.min(this.inventoryRows, 6) * 18 + 17; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, h1); + int rows = this.inventoryRows; + while (rows > 6) { + int h2 = Math.min(rows, 6) * 18; + this.drawTexturedModalRect(x, y + h1, 0, 17, this.xSize, h2); + rows -= 6; + h1 += h2; + } + this.drawTexturedModalRect(x, y + this.inventoryRows * 18 + 17, 0, 126, this.xSize, 96); + } +} diff --git a/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinEntityPlayerMP.java b/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinEntityPlayerMP.java new file mode 100644 index 0000000..8411926 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinEntityPlayerMP.java @@ -0,0 +1,27 @@ +package net.brokenmoon.afloydironchest.mixin; + +import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerMP; +import net.minecraft.src.*; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = EntityPlayerMP.class, remap = false) +public class MixinEntityPlayerMP implements IEntityPlayerMP { + + @Shadow + private void getNextWindowId() {} + + @Shadow + private int currentWindowId; + @Shadow + public NetServerHandler playerNetServerHandler; + + public void displayGUIIronChest(IInventory iinventory) { + this.getNextWindowId(); + NetServerHandler.logger.info(((EntityPlayerMP)(Object)this).username + " interacted with chest at (" + ((EntityPlayerMP)(Object)this).posX + ", " + ((EntityPlayerMP)(Object)this).posY + ", " + ((EntityPlayerMP)(Object)this).posZ + ")"); + this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, 0, iinventory.getInvName(), iinventory.getSizeInventory())); + ((EntityPlayerMP)(Object)this).craftingInventory = new ContainerChest(((EntityPlayerMP)(Object)this).inventory, iinventory); + ((EntityPlayerMP)(Object)this).craftingInventory.windowId = this.currentWindowId; + ((EntityPlayerMP)(Object)this).craftingInventory.onContainerInit(((EntityPlayerMP)(Object)this)); + } +} diff --git a/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinEntityPlayerSP.java b/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinEntityPlayerSP.java new file mode 100644 index 0000000..45f1386 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinEntityPlayerSP.java @@ -0,0 +1,16 @@ +package net.brokenmoon.afloydironchest.mixin; + +import net.brokenmoon.afloydironchest.gui.GuiIronChest; +import net.minecraft.client.Minecraft; +import net.minecraft.src.*; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = EntityPlayerSP.class, remap = false) +public class MixinEntityPlayerSP { + @Shadow + protected Minecraft mc; + public void displayGUIIronChest(IInventory iinventory) { + this.mc.displayGuiScreen(new GuiIronChest(((EntityPlayerSP)(Object)this).inventory, iinventory)); + } +} diff --git a/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinTileEntity.java b/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinTileEntity.java new file mode 100644 index 0000000..500399d --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/mixin/MixinTileEntity.java @@ -0,0 +1,16 @@ +package net.brokenmoon.afloydironchest.mixin; + +import net.brokenmoon.afloydironchest.tileEntities.TileEntityIronChest; +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(TileEntityIronChest.class, "Iron Chest"); + } + +} diff --git a/src/main/java/net/brokenmoon/afloydironchest/tileEntities/TileEntityIronChest.java b/src/main/java/net/brokenmoon/afloydironchest/tileEntities/TileEntityIronChest.java new file mode 100644 index 0000000..f5f7591 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydironchest/tileEntities/TileEntityIronChest.java @@ -0,0 +1,100 @@ +package net.brokenmoon.afloydironchest.tileEntities; + +import net.minecraft.src.*; + +public class TileEntityIronChest extends TileEntity implements IInventory { + private ItemStack[] contents = new ItemStack[54]; + + @Override + public int getSizeInventory() { + return 54; + } + + @Override + public ItemStack getStackInSlot(int i) { + return this.contents[i]; + } + + @Override + public ItemStack decrStackSize(int i, int j) { + if (this.contents[i] != null) { + ItemStack itemstack1; + if (this.contents[i].stackSize <= j) { + itemstack1 = this.contents[i]; + this.contents[i] = null; + this.onInventoryChanged(); + return itemstack1; + } else { + itemstack1 = this.contents[i].splitStack(j); + if (this.contents[i].stackSize == 0) { + this.contents[i] = null; + } + + this.onInventoryChanged(); + return itemstack1; + } + } else { + return null; + } + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemStack) { + this.contents[i] = itemStack; + if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { + itemStack.stackSize = this.getInventoryStackLimit(); + } + + this.onInventoryChanged(); + } + + @Override + public String getInvName() { + return "Iron Chest"; + } + + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); + this.contents = new ItemStack[this.getSizeInventory()]; + + for(int i = 0; i < nbttaglist.tagCount(); ++i) { + NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i); + int j = nbttagcompound1.getByte("Slot") & 255; + if (j >= 0 && j < this.contents.length) { + this.contents[j] = new ItemStack(nbttagcompound1); + } + } + + } + + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + NBTTagList nbttaglist = new NBTTagList(); + + for(int i = 0; i < this.contents.length; ++i) { + if (this.contents[i] != null) { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte)i); + this.contents[i].writeToNBT(nbttagcompound1); + nbttaglist.setTag(nbttagcompound1); + } + } + + nbttagcompound.setTag("Items", nbttaglist); + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public boolean canInteractWith(EntityPlayer entityPlayer) { + if (this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this) { + return false; + } else { + return entityPlayer.getDistanceSq((double)this.xCoord + 0.5, (double)this.yCoord + 0.5, (double)this.zCoord + 0.5) <= 64.0; + } + } +} 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/afloydironchest.mixins.json similarity index 52% rename from src/main/resources/examplemod.mixins.json rename to src/main/resources/afloydironchest.mixins.json index e98223c..291f41c 100644 --- a/src/main/resources/examplemod.mixins.json +++ b/src/main/resources/afloydironchest.mixins.json @@ -1,11 +1,17 @@ { "required": true, "minVersion": "0.8", - "package": "turniplabs.examplemod.mixin", + "package": "net.brokenmoon.afloydironchest.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ + "MixinEntityPlayerMP", + "MixinEntityPlayerSP", + "MixinTileEntity" ], "client": [ + + ], + "server": [ ], "injectors": { "defaultRequire": 1 diff --git a/src/main/resources/assets/ironchest/block/ironchest.png b/src/main/resources/assets/ironchest/block/ironchest.png new file mode 100644 index 0000000..e803cd4 Binary files /dev/null and b/src/main/resources/assets/ironchest/block/ironchest.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c93d2bc..a62f025 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,15 +1,15 @@ { "schemaVersion": 1, - "id": "examplemod", + "id": "afloydironchest", "version": "${version}", - "name": "Example Mod", - "description": "This mod aims to help new BTA modders.", + "name": "Astoria's Iron Chest", + "description": "Simple expanded chests mod.", "authors": [ - "Turnip Labs" + "Astoria" ], "contact": { - "homepage": "", + "homepage": "http://broken-moon.net", "sources": "" }, @@ -18,16 +18,21 @@ "environment": "*", "entrypoints": { "main": [ - "turniplabs.examplemod.ExampleMod" + "net.brokenmoon.afloydironchest.IronChestMain" ] }, "mixins": [ - "examplemod.mixins.json" + "afloydironchest.mixins.json" ], "depends": { "fabricloader": ">=0.13.3" }, "suggests": { + }, + "custom": { + "loom:injected_interfaces": { + "net/minecraft/src/EntityPlayerSP": ["net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerSP"] + } } } diff --git a/src/main/resources/lang/afloydironchest/en_US.lang b/src/main/resources/lang/afloydironchest/en_US.lang new file mode 100644 index 0000000..5625cc9 --- /dev/null +++ b/src/main/resources/lang/afloydironchest/en_US.lang @@ -0,0 +1,2 @@ +tile.ironchest.ironchest.name=Iron Chest +tile.ironchest.ironchest.desc=A larger chest \ 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