Main chests, lots of duplicated code. Fix later!
parent
f4949dadcc
commit
7959ee8afb
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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…
Reference in New Issue