Main chests, lots of duplicated code. Fix later!

main
Astoria 2 years ago
parent f4949dadcc
commit 7959ee8afb

@ -1,6 +1,9 @@
package net.brokenmoon.afloydironchest;
import net.brokenmoon.afloydironchest.blocks.DiamondChest;
import net.brokenmoon.afloydironchest.blocks.IronChest;
import net.brokenmoon.afloydironchest.blocks.GoldChest;
import net.brokenmoon.afloydironchest.blocks.SteelChest;
import net.fabricmc.api.ModInitializer;
import net.minecraft.src.Block;
import net.minecraft.src.Material;
@ -14,6 +17,9 @@ public class IronChestMain implements ModInitializer {
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);
public static Block GoldChest = BlockHelper.createBlock(MOD_ID, new GoldChest(901, Material.iron), "goldchest", "ironchest.png", Block.soundMetalFootstep, 5, 6, 0);
public static Block DiamondChest = BlockHelper.createBlock(MOD_ID, new DiamondChest(902, Material.iron), "diamondchest", "ironchest.png", Block.soundMetalFootstep, 5, 6, 0);
public static Block SteelChest = BlockHelper.createBlock(MOD_ID, new SteelChest(903, Material.iron), "steelchest", "ironchest.png", Block.soundMetalFootstep, 5, 6, 0);
@Override
public void onInitialize() {

@ -0,0 +1,66 @@
package net.brokenmoon.afloydironchest.blocks;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerMP;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerSP;
import net.brokenmoon.afloydironchest.tileEntities.TileEntityDiamondChest;
import net.minecraft.src.*;
import java.util.Random;
public class DiamondChest extends BlockContainer{
Random random = new Random();
public DiamondChest(int id, Material blockMaterial){
super(id, blockMaterial);
}
@Override
public void onBlockRemoval(World world, int i, int j, int k) {
TileEntityDiamondChest te = (TileEntityDiamondChest)world.getBlockTileEntity(i, j, k);
for (int l = 0; l < te.getSizeInventory(); ++l) {
ItemStack itemstack = te.getStackInSlot(l);
if (itemstack == null) continue;
float f = this.random.nextFloat() * 0.8f + 0.1f;
float f1 = this.random.nextFloat() * 0.8f + 0.1f;
float f2 = this.random.nextFloat() * 0.8f + 0.1f;
while (itemstack.stackSize > 0) {
int i1 = this.random.nextInt(21) + 10;
if (i1 > itemstack.stackSize) {
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float)i + f, (float)j + f1, (float)k + f2, new ItemStack(itemstack.itemID, i1, itemstack.getMetadata()));
float f3 = 0.05f;
entityitem.motionX = (float)this.random.nextGaussian() * f3;
entityitem.motionY = (float)this.random.nextGaussian() * f3 + 0.2f;
entityitem.motionZ = (float)this.random.nextGaussian() * f3;
world.entityJoinedWorld(entityitem);
}
}
super.onBlockRemoval(world, i, j, k);
}
@Override
public boolean blockActivated(World world, int x, int y, int z, EntityPlayer entityplayer) {
IInventory chest = (TileEntityDiamondChest)world.getBlockTileEntity(x, y, z);
if (!world.isMultiplayerAndNotHost) {
this.displayGui(entityplayer, chest);
}
return true;
}
@Override
protected TileEntity getBlockEntity() {
return new TileEntityDiamondChest();
}
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,66 @@
package net.brokenmoon.afloydironchest.blocks;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerMP;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerSP;
import net.brokenmoon.afloydironchest.tileEntities.TileEntityGoldChest;
import net.minecraft.src.*;
import java.util.Random;
public class GoldChest extends BlockContainer{
Random random = new Random();
public GoldChest(int id, Material blockMaterial){
super(id, blockMaterial);
}
@Override
public void onBlockRemoval(World world, int i, int j, int k) {
TileEntityGoldChest te = (TileEntityGoldChest)world.getBlockTileEntity(i, j, k);
for (int l = 0; l < te.getSizeInventory(); ++l) {
ItemStack itemstack = te.getStackInSlot(l);
if (itemstack == null) continue;
float f = this.random.nextFloat() * 0.8f + 0.1f;
float f1 = this.random.nextFloat() * 0.8f + 0.1f;
float f2 = this.random.nextFloat() * 0.8f + 0.1f;
while (itemstack.stackSize > 0) {
int i1 = this.random.nextInt(21) + 10;
if (i1 > itemstack.stackSize) {
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float)i + f, (float)j + f1, (float)k + f2, new ItemStack(itemstack.itemID, i1, itemstack.getMetadata()));
float f3 = 0.05f;
entityitem.motionX = (float)this.random.nextGaussian() * f3;
entityitem.motionY = (float)this.random.nextGaussian() * f3 + 0.2f;
entityitem.motionZ = (float)this.random.nextGaussian() * f3;
world.entityJoinedWorld(entityitem);
}
}
super.onBlockRemoval(world, i, j, k);
}
@Override
public boolean blockActivated(World world, int x, int y, int z, EntityPlayer entityplayer) {
IInventory chest = (TileEntityGoldChest)world.getBlockTileEntity(x, y, z);
if (!world.isMultiplayerAndNotHost) {
this.displayGui(entityplayer, chest);
}
return true;
}
@Override
protected TileEntity getBlockEntity() {
return new TileEntityGoldChest();
}
public static void displayGui(EntityPlayer player, IInventory inventory){
if(player instanceof EntityPlayerMP) {
//Multiplayer
((IEntityPlayerMP)player).displayGUIIronChest(inventory);
return;
}
//Singleplayer
((IEntityPlayerSP)player).displayGUIIronChest(inventory);
}
}

@ -5,11 +5,41 @@ import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerSP;
import net.brokenmoon.afloydironchest.tileEntities.TileEntityIronChest;
import net.minecraft.src.*;
import java.util.Random;
public class IronChest extends BlockContainer {
Random random = new Random();
public IronChest(int id, Material blockMaterial){
super(id, blockMaterial);
}
@Override
public void onBlockRemoval(World world, int i, int j, int k) {
TileEntityIronChest te = (TileEntityIronChest)world.getBlockTileEntity(i, j, k);
for (int l = 0; l < te.getSizeInventory(); ++l) {
ItemStack itemstack = te.getStackInSlot(l);
if (itemstack == null) continue;
float f = this.random.nextFloat() * 0.8f + 0.1f;
float f1 = this.random.nextFloat() * 0.8f + 0.1f;
float f2 = this.random.nextFloat() * 0.8f + 0.1f;
while (itemstack.stackSize > 0) {
int i1 = this.random.nextInt(21) + 10;
if (i1 > itemstack.stackSize) {
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float)i + f, (float)j + f1, (float)k + f2, new ItemStack(itemstack.itemID, i1, itemstack.getMetadata()));
float f3 = 0.05f;
entityitem.motionX = (float)this.random.nextGaussian() * f3;
entityitem.motionY = (float)this.random.nextGaussian() * f3 + 0.2f;
entityitem.motionZ = (float)this.random.nextGaussian() * f3;
world.entityJoinedWorld(entityitem);
}
}
super.onBlockRemoval(world, i, j, k);
}
@Override
public boolean blockActivated(World world, int x, int y, int z, EntityPlayer entityplayer) {
IInventory chest = (TileEntityIronChest)world.getBlockTileEntity(x, y, z);

@ -0,0 +1,66 @@
package net.brokenmoon.afloydironchest.blocks;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerMP;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerSP;
import net.brokenmoon.afloydironchest.tileEntities.TileEntitySteelChest;
import net.minecraft.src.*;
import java.util.Random;
public class SteelChest extends BlockContainer{
Random random = new Random();
public SteelChest(int id, Material blockMaterial){
super(id, blockMaterial);
}
@Override
public void onBlockRemoval(World world, int i, int j, int k) {
TileEntitySteelChest te = (TileEntitySteelChest)world.getBlockTileEntity(i, j, k);
for (int l = 0; l < te.getSizeInventory(); ++l) {
ItemStack itemstack = te.getStackInSlot(l);
if (itemstack == null) continue;
float f = this.random.nextFloat() * 0.8f + 0.1f;
float f1 = this.random.nextFloat() * 0.8f + 0.1f;
float f2 = this.random.nextFloat() * 0.8f + 0.1f;
while (itemstack.stackSize > 0) {
int i1 = this.random.nextInt(21) + 10;
if (i1 > itemstack.stackSize) {
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float)i + f, (float)j + f1, (float)k + f2, new ItemStack(itemstack.itemID, i1, itemstack.getMetadata()));
float f3 = 0.05f;
entityitem.motionX = (float)this.random.nextGaussian() * f3;
entityitem.motionY = (float)this.random.nextGaussian() * f3 + 0.2f;
entityitem.motionZ = (float)this.random.nextGaussian() * f3;
world.entityJoinedWorld(entityitem);
}
}
super.onBlockRemoval(world, i, j, k);
}
@Override
public boolean blockActivated(World world, int x, int y, int z, EntityPlayer entityplayer) {
IInventory chest = (TileEntitySteelChest)world.getBlockTileEntity(x, y, z);
if (!world.isMultiplayerAndNotHost) {
this.displayGui(entityplayer, chest);
}
return true;
}
@Override
protected TileEntity getBlockEntity() {
return new TileEntitySteelChest();
}
public static void displayGui(EntityPlayer player, IInventory inventory){
if(player instanceof EntityPlayerMP) {
//Multiplayer
((IEntityPlayerMP)player).displayGUIIronChest(inventory);
return;
}
//Singleplayer
((IEntityPlayerSP)player).displayGUIIronChest(inventory);
}
}

@ -1,6 +1,9 @@
package net.brokenmoon.afloydironchest.mixin;
import net.brokenmoon.afloydironchest.tileEntities.TileEntityDiamondChest;
import net.brokenmoon.afloydironchest.tileEntities.TileEntityGoldChest;
import net.brokenmoon.afloydironchest.tileEntities.TileEntityIronChest;
import net.brokenmoon.afloydironchest.tileEntities.TileEntitySteelChest;
import net.minecraft.src.TileEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -11,6 +14,9 @@ public class MixinTileEntity {
static {
addMapping(TileEntityIronChest.class, "Iron Chest");
addMapping(TileEntityGoldChest.class, "Gold Chest");
addMapping(TileEntityDiamondChest.class, "Diamond Chest");
addMapping(TileEntitySteelChest.class, "Steel Chest");
}
}

@ -0,0 +1,100 @@
package net.brokenmoon.afloydironchest.tileEntities;
import net.minecraft.src.*;
public class TileEntityDiamondChest extends TileEntity implements IInventory {
private ItemStack[] contents = new ItemStack[108];
@Override
public int getSizeInventory() {
return 108;
}
@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 "Diamond 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;
}
}
}

@ -0,0 +1,100 @@
package net.brokenmoon.afloydironchest.tileEntities;
import net.minecraft.src.*;
public class TileEntityGoldChest extends TileEntity implements IInventory {
private ItemStack[] contents = new ItemStack[81];
@Override
public int getSizeInventory() {
return 81;
}
@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 "Gold 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;
}
}
}

@ -0,0 +1,100 @@
package net.brokenmoon.afloydironchest.tileEntities;
import net.minecraft.src.*;
public class TileEntitySteelChest extends TileEntity implements IInventory {
private ItemStack[] contents = new ItemStack[108];
@Override
public int getSizeInventory() {
return 108;
}
@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 "Steel 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,2 +1,8 @@
tile.ironchest.ironchest.name=Iron Chest
tile.ironchest.ironchest.desc=A larger chest
tile.ironchest.ironchest.desc=A large chest.
tile.ironchest.goldchest.name=Gold Chest
tile.ironchest.goldchest.desc=An extra-large chest.
tile.ironchest.diamondchest.name=Diamond Chest
tile.ironchest.diamondchest.desc=An extremely large chest.
tile.ironchest.steelchest.name=Steel Chest
tile.ironchest.steelchest.desc=An extremely large chest.
Loading…
Cancel
Save