Updating 1.7.2 repo
This commit is contained in:
parent
c9a38c4c10
commit
9dc8a57a2d
76 changed files with 1789 additions and 184 deletions
|
@ -0,0 +1,142 @@
|
|||
package WayofTime.alchemicalWizardry.common.tileEntity;
|
||||
|
||||
import WayofTime.alchemicalWizardry.ModBlocks;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TESpectralContainer extends TileEntity
|
||||
{
|
||||
private ItemStack[] inv;
|
||||
|
||||
private int ticksRemaining;
|
||||
|
||||
public TESpectralContainer()
|
||||
{
|
||||
this.inv = new ItemStack[1];
|
||||
|
||||
ticksRemaining = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.readFromNBT(par1NBTTagCompound);
|
||||
NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory");
|
||||
|
||||
for (int i = 0; i < tagList.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
|
||||
int slot = tag.getByte("Slot");
|
||||
|
||||
if (slot >= 0 && slot < inv.length)
|
||||
{
|
||||
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
|
||||
}
|
||||
}
|
||||
|
||||
ticksRemaining = par1NBTTagCompound.getInteger("ticksRemaining");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.writeToNBT(par1NBTTagCompound);
|
||||
NBTTagList itemList = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < inv.length; i++)
|
||||
{
|
||||
ItemStack stack = inv[i];
|
||||
|
||||
if (inv[i] != null)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setByte("Slot", (byte) i);
|
||||
inv[i].writeToNBT(tag);
|
||||
itemList.appendTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
par1NBTTagCompound.setTag("Inventory", itemList);
|
||||
par1NBTTagCompound.setInteger("ticksRemaining", ticksRemaining);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
this.ticksRemaining--;
|
||||
|
||||
if(this.ticksRemaining<=0)
|
||||
{
|
||||
this.returnContainedBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean createSpectralBlockAtLocation(World world, int x, int y, int z, int duration)
|
||||
{
|
||||
if(world.getBlockTileEntity(x, y, z)==null)
|
||||
{
|
||||
Block block = Block.blocksList[world.getBlockId(x, y, z)];
|
||||
|
||||
if(block==null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
ItemStack item = new ItemStack(block, 1, meta);
|
||||
|
||||
world.setBlock(x, y, z, ModBlocks.blockSpectralContainer.blockID);
|
||||
TileEntity tile = world.getBlockTileEntity(x, y, z);
|
||||
if(tile instanceof TESpectralContainer)
|
||||
{
|
||||
((TESpectralContainer) tile).setContainedItem(item);
|
||||
((TESpectralContainer) tile).setDuration(duration);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setDuration(int dur)
|
||||
{
|
||||
this.ticksRemaining = dur;
|
||||
}
|
||||
|
||||
public void resetDuration(int dur)
|
||||
{
|
||||
if(this.ticksRemaining<dur)
|
||||
{
|
||||
this.ticksRemaining = dur;
|
||||
}
|
||||
}
|
||||
|
||||
public void setContainedItem(ItemStack item)
|
||||
{
|
||||
this.inv[0] = item;
|
||||
}
|
||||
|
||||
public void returnContainedBlock()
|
||||
{
|
||||
ItemStack item = this.inv[0];
|
||||
if(item!=null)
|
||||
{
|
||||
Block block = Block.blocksList[item.itemID];
|
||||
int meta = item.getItemDamage();
|
||||
|
||||
if(block != null)
|
||||
{
|
||||
this.worldObj.setBlock(xCoord, yCoord, zCoord, item.itemID, meta, 6);
|
||||
}
|
||||
}else
|
||||
{
|
||||
this.worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue