From f4949dadcc18c3bbc0c43b1fa03b62853cb2e7dd Mon Sep 17 00:00:00 2001 From: Astoria Date: Thu, 16 Mar 2023 23:39:34 -0500 Subject: [PATCH] Initial Version --- gradle.properties | 4 +- .../afloydironchest/IronChestMain.java | 23 ++++ .../MixinInterfaces/IEntityPlayerMP.java | 7 ++ .../MixinInterfaces/IEntityPlayerSP.java | 7 ++ .../afloydironchest/blocks/IronChest.java | 36 +++++++ .../afloydironchest/gui/GuiIronChest.java | 48 +++++++++ .../mixin/MixinEntityPlayerMP.java | 27 +++++ .../mixin/MixinEntityPlayerSP.java | 16 +++ .../mixin/MixinTileEntity.java | 16 +++ .../tileEntities/TileEntityIronChest.java | 100 ++++++++++++++++++ .../turniplabs/examplemod/ExampleMod.java | 16 --- ...ixins.json => afloydironchest.mixins.json} | 8 +- .../assets/ironchest/block/ironchest.png | Bin 0 -> 1204 bytes src/main/resources/fabric.mod.json | 19 ++-- .../resources/lang/afloydironchest/en_US.lang | 2 + src/main/resources/lang/examplemod/en_US.lang | 0 16 files changed, 303 insertions(+), 26 deletions(-) create mode 100644 src/main/java/net/brokenmoon/afloydironchest/IronChestMain.java create mode 100644 src/main/java/net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerMP.java create mode 100644 src/main/java/net/brokenmoon/afloydironchest/MixinInterfaces/IEntityPlayerSP.java create mode 100644 src/main/java/net/brokenmoon/afloydironchest/blocks/IronChest.java create mode 100644 src/main/java/net/brokenmoon/afloydironchest/gui/GuiIronChest.java create mode 100644 src/main/java/net/brokenmoon/afloydironchest/mixin/MixinEntityPlayerMP.java create mode 100644 src/main/java/net/brokenmoon/afloydironchest/mixin/MixinEntityPlayerSP.java create mode 100644 src/main/java/net/brokenmoon/afloydironchest/mixin/MixinTileEntity.java create mode 100644 src/main/java/net/brokenmoon/afloydironchest/tileEntities/TileEntityIronChest.java delete mode 100644 src/main/java/turniplabs/examplemod/ExampleMod.java rename src/main/resources/{examplemod.mixins.json => afloydironchest.mixins.json} (52%) create mode 100644 src/main/resources/assets/ironchest/block/ironchest.png create mode 100644 src/main/resources/lang/afloydironchest/en_US.lang delete mode 100644 src/main/resources/lang/examplemod/en_US.lang 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 0000000000000000000000000000000000000000..e803cd48df5dd75fdbe75902edc94af716c116dc GIT binary patch literal 1204 zcmV;l1WWsgP)EX>4Tx04R}tkv&MmKpe$iQ^lec2Rn#3WT-A$5EXIMDionYs1;guFuC*#nlvOS zE{=k0!NHHks)LKOt`4q(Aou~|=;Wm6A|?JWDYS_3;J6>}?mh0_0YbgZG^=AA&~)2O zCE{WxyDE0Qq6Z;F5XGp>EMrcRlJFg0_XzOyF2=L`&;2=i)ttqEfJi*c4AUmwAfDc| z4bJ<-5muB{;&b9LlP*a7$aTfzH_io@1)do()2Vsl2(egbW2KE*(bR~ih@+~eQ@)V# zSmnIMSu0mr^Pc>L;hes*%ypVWNMI35kRU=q6(y8mBSx!EiiH&I$9?>Ru3sXTLaq`R zITlcX2HEw4|H1EWt^DMKmlTczoiC2_F${F=0*#vEd>=bb;{*sk16O*>U#SB#pQP7X zTJ#9$+XgPKTbi;5T000McNliru<_icEI~DZpOTGXA02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{00N9jL_t(I%RQ6LZWCt|hM(_$W^5!Nqi%jm`Q<|=hTBcvt~kP;bek0&0_e7{{pp0hfOqxby0&k=wA@q0NrIbj$E>bgcL z#o=%u=gfY;r)e6RrlIe9y!RMm@ZOVBV!2$RbIu$N2TCb;@439W#ahexlO@hMLI`;8 zi7~QREb!i=l)_p|&KYTp!5Bkb*Ia-8N>x?7dj1VLXR4|~Yt1;0R8@ud9snsNQpyJb zDJ3Z-hGC$T!o{=4SZk*>VvJMqFburA`p8||Q&knl7_<-qYb`NGgb;Y|30Y9rHQsx) z)*NfD{`-P+ju;~;B{rK4dK^beDKt&P#q+1E*K3+aA%vi+Dnbb4oVmGM6JzA(AD$wm z%*YRPs1(?=KDItWQZCl>H{0?g^LI}>z&hXwNPft&A&QVI? z-`f?X6do-aj4{mTb5cr#5YSrl*ZU7xYgw&Zx~>C2_kB+(g`*qZdrB#ET}ONAF$R^*EQB! zW{QVIZn zzrSWapY!Y6ABi#IoMW+A(6%i~DY~vh=A6-5_7KoB+Cb_IS#VmM)jehw-IE&So=8DTEMk&Q09cbz2OnC);MT*@V1vj{gA~GkrhP Sn%Wfr0000=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