Initial Version

main
Astoria 2 years ago
parent 11b5f4a564
commit f4949dadcc

@ -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

@ -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");
}
}

@ -0,0 +1,7 @@
package net.brokenmoon.afloydironchest.MixinInterfaces;
import net.minecraft.src.IInventory;
public interface IEntityPlayerMP {
public void displayGUIIronChest(IInventory iinventory);
}

@ -0,0 +1,7 @@
package net.brokenmoon.afloydironchest.MixinInterfaces;
import net.minecraft.src.IInventory;
public interface IEntityPlayerSP {
public void displayGUIIronChest(IInventory iinventory);
}

@ -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);
}
}

@ -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);
}
}

@ -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));
}
}

@ -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));
}
}

@ -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");
}
}

@ -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;
}
}
}

@ -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.");
}
}

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -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"]
}
}
}

@ -0,0 +1,2 @@
tile.ironchest.ironchest.name=Iron Chest
tile.ironchest.ironchest.desc=A larger chest
Loading…
Cancel
Save