Move some stuff out into Mantle.

This commit is contained in:
Sunstrike committed 2013-12-01 12:19:43 +00:00
1 parent ef70d27bee
commit e763bb6363
32 files changed
+32 -544

No files matched your search

@@ -6,7 +6,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.util.IFacingLogic;
import cpw.mods.fml.common.FMLCommonHandler;
import mantle.blocks.abstracts.InventoryLogic;
public abstract class AdaptiveInventoryLogic extends InventoryLogic implements IFacingLogic
{
@@ -6,6 +6,7 @@ import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*;
import net.minecraft.world.World;
import mantle.blocks.abstracts.InventoryLogic;
public abstract class ExpandableInventoryLogic extends InventoryLogic implements IInventory
{
@@ -1,191 +0,0 @@
package tconstruct.library.blocks;
import java.util.Random;
import tconstruct.library.util.IActiveLogic;
import tconstruct.library.util.IFacingLogic;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public abstract class InventoryBlock extends BlockContainer
{
protected Random rand = new Random();
protected InventoryBlock(int id, Material material)
{
super(id, material);
}
/* Logic backend */
public TileEntity createNewTileEntity (World var1)
{
return null;
}
public abstract TileEntity createTileEntity (World world, int metadata);
public abstract Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer);
public abstract Object getModInstance ();
@Override
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int side, float clickX, float clickY, float clickZ)
{
if (player.isSneaking())
return false;
Integer integer = getGui(world, x, y, z, player);
if (integer == null || integer == -1)
{
return false;
}
else
{
if (!world.isRemote)
player.openGui(getModInstance(), integer, world, x, y, z);
return true;
}
}
/* Inventory */
@Override
public void breakBlock (World par1World, int x, int y, int z, int blockID, int meta)
{
TileEntity te = par1World.getBlockTileEntity(x, y, z);
if (te != null && te instanceof InventoryLogic)
{
InventoryLogic logic = (InventoryLogic) te;
logic.removeBlock();
for (int iter = 0; iter < logic.getSizeInventory(); ++iter)
{
ItemStack stack = logic.getStackInSlot(iter);
if (stack != null && logic.canDropInventorySlot(iter))
{
float jumpX = rand.nextFloat() * 0.8F + 0.1F;
float jumpY = rand.nextFloat() * 0.8F + 0.1F;
float jumpZ = rand.nextFloat() * 0.8F + 0.1F;
while (stack.stackSize > 0)
{
int itemSize = rand.nextInt(21) + 10;
if (itemSize > stack.stackSize)
{
itemSize = stack.stackSize;
}
stack.stackSize -= itemSize;
EntityItem entityitem = new EntityItem(par1World, (double) ((float) x + jumpX), (double) ((float) y + jumpY), (double) ((float) z + jumpZ), new ItemStack(stack.itemID,
itemSize, stack.getItemDamage()));
if (stack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
}
float offset = 0.05F;
entityitem.motionX = (double) ((float) rand.nextGaussian() * offset);
entityitem.motionY = (double) ((float) rand.nextGaussian() * offset + 0.2F);
entityitem.motionZ = (double) ((float) rand.nextGaussian() * offset);
par1World.spawnEntityInWorld(entityitem);
}
}
}
}
super.breakBlock(par1World, x, y, z, blockID, meta);
}
/* Placement */
int side = -1;
//This class does not have an actual block placed in the world
@Override
public int onBlockPlaced (World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int meta)
{
this.side = side;
return meta;
}
@Override
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack stack)
{
TileEntity logic = world.getBlockTileEntity(x, y, z);
if (logic instanceof IFacingLogic)
{
IFacingLogic direction = (IFacingLogic) logic;
if (side != -1)
{
direction.setDirection(side);
side = -1;
}
if (entityliving == null)
{
direction.setDirection(0F, 0F, null);
}
else
{
direction.setDirection(entityliving.rotationYaw * 4F, entityliving.rotationPitch, entityliving);
}
}
if (logic instanceof InventoryLogic)
{
InventoryLogic inv = (InventoryLogic) logic;
inv.placeBlock(entityliving, stack);
if (stack.hasDisplayName())
{
inv.setInvName(stack.getDisplayName());
}
}
}
public static boolean isActive (IBlockAccess world, int x, int y, int z)
{
TileEntity logic = world.getBlockTileEntity(x, y, z);
if (logic instanceof IActiveLogic)
{
return ((IActiveLogic) logic).getActive();
}
return false;
}
public int damageDropped (int meta)
{
return meta;
}
/* Textures */
public Icon[] icons;
public abstract String[] getTextureNames ();
@Override
public void registerIcons (IconRegister iconRegister)
{
String[] textureNames = getTextureNames();
this.icons = new Icon[textureNames.length];
for (int i = 0; i < this.icons.length; ++i)
{
this.icons[i] = iconRegister.registerIcon("tinker:" + textureNames[i]);
}
}
}
@@ -1,227 +0,0 @@
package tconstruct.library.blocks;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
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;
/*
* A simple logic class for storing items
* Abstract to avoid instantiation
*/
public abstract class InventoryLogic extends TileEntity implements IInventory
{
protected ItemStack[] inventory;
protected String invName;
protected int stackSizeLimit;
public InventoryLogic(int invSize)
{
this(invSize, 64);
}
public InventoryLogic(int invSize, int maxStackSize)
{
inventory = new ItemStack[invSize];
stackSizeLimit = maxStackSize;
}
/* Inventory management */
@Override
public ItemStack getStackInSlot (int slot)
{
return inventory[slot];
}
public boolean isStackInSlot (int slot)
{
return inventory[slot] != null;
}
@Override
public int getSizeInventory ()
{
return inventory.length;
}
@Override
public int getInventoryStackLimit ()
{
return stackSizeLimit;
}
public boolean canDropInventorySlot (int slot)
{
return true;
}
@Override
public void setInventorySlotContents (int slot, ItemStack itemstack)
{
inventory[slot] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
itemstack.stackSize = getInventoryStackLimit();
}
}
@Override
public ItemStack decrStackSize (int slot, int quantity)
{
if (inventory[slot] != null)
{
if (inventory[slot].stackSize <= quantity)
{
ItemStack stack = inventory[slot];
inventory[slot] = null;
return stack;
}
ItemStack split = inventory[slot].splitStack(quantity);
if (inventory[slot].stackSize == 0)
{
inventory[slot] = null;
}
return split;
}
else
{
return null;
}
}
/* Supporting methods */
@Override
public boolean isUseableByPlayer (EntityPlayer entityplayer)
{
if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
return false;
else
return entityplayer.getDistance((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D;
}
public abstract Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z);
/* NBT */
@Override
public void readFromNBT (NBTTagCompound tags)
{
super.readFromNBT(tags);
readInventoryFromNBT(tags);
}
public void readInventoryFromNBT (NBTTagCompound tags)
{
super.readFromNBT(tags);
this.invName = tags.getString("InvName");
NBTTagList nbttaglist = tags.getTagList("Items");
inventory = new ItemStack[getSizeInventory()];
for (int iter = 0; iter < nbttaglist.tagCount(); iter++)
{
NBTTagCompound tagList = (NBTTagCompound) nbttaglist.tagAt(iter);
byte slotID = tagList.getByte("Slot");
if (slotID >= 0 && slotID < inventory.length)
{
inventory[slotID] = ItemStack.loadItemStackFromNBT(tagList);
}
}
}
@Override
public void writeToNBT (NBTTagCompound tags)
{
super.writeToNBT(tags);
writeInventoryToNBT(tags);
}
public void writeInventoryToNBT (NBTTagCompound tags)
{
if (invName != null)
tags.setString("InvName", invName);
NBTTagList nbttaglist = new NBTTagList();
for (int iter = 0; iter < inventory.length; iter++)
{
if (inventory[iter] != null)
{
NBTTagCompound tagList = new NBTTagCompound();
tagList.setByte("Slot", (byte) iter);
inventory[iter].writeToNBT(tagList);
nbttaglist.appendTag(tagList);
}
}
tags.setTag("Items", nbttaglist);
}
/* Cause of the heisenbug. Do not uncomment! */
/*public void superReadFromNBT (NBTTagCompound tags)
{
super.readFromNBT(tags);
}
public void superWriteToNBT (NBTTagCompound tags)
{
super.writeToNBT(tags);
}*/
/* Default implementations of hardly used methods */
public ItemStack getStackInSlotOnClosing (int slot)
{
return null;
}
public void openChest ()
{
}
public void closeChest ()
{
}
protected abstract String getDefaultName ();
public void setInvName (String name)
{
this.invName = name;
}
public String getInvName ()
{
return this.isInvNameLocalized() ? this.invName : getDefaultName();
}
public boolean isInvNameLocalized ()
{
return this.invName != null && this.invName.length() > 0;
}
@Override
public boolean isItemValidForSlot (int slot, ItemStack itemstack)
{
if (slot < getSizeInventory())
{
if (inventory[slot] == null || itemstack.stackSize + inventory[slot].stackSize <= getInventoryStackLimit())
return true;
}
return false;
}
public void placeBlock (EntityLivingBase entity, ItemStack stack)
{
}
public void removeBlock ()
{
}
}
@@ -1,79 +0,0 @@
package tconstruct.library.blocks;
import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public abstract class InventorySlab extends InventoryBlock
{
public InventorySlab(int id, Material material)
{
super(id, material);
}
/* Rendering */
@Override
public boolean renderAsNormalBlock ()
{
return false;
}
@Override
public boolean isOpaqueCube ()
{
return false;
}
@Override
public boolean shouldSideBeRendered (IBlockAccess world, int x, int y, int z, int side)
{
if (side > 1)
return super.shouldSideBeRendered(world, x, y, z, side);
int meta = world.getBlockMetadata(x, y, z);
boolean top = (meta | 8) == 1;
if ((top && side == 0) || (!top && side == 1))
return true;
return super.shouldSideBeRendered(world, x, y, z, side);
}
@Override
public void addCollisionBoxesToList (World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List arraylist, Entity entity)
{
setBlockBoundsBasedOnState(world, x, y, z);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist, entity);
}
public void setBlockBoundsForItemRender ()
{
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
}
public void setBlockBoundsBasedOnState (IBlockAccess world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z) / 8;
float minY = meta == 1 ? 0.5F : 0.0F;
float maxY = meta == 1 ? 1.0F : 0.5F;
setBlockBounds(0.0F, minY, 0F, 1.0F, maxY, 1.0F);
}
public int onBlockPlaced (World par1World, int blockX, int blockY, int blockZ, int side, float clickX, float clickY, float clickZ, int metadata)
{
if (side == 1)
return metadata;
if (side == 0 || clickY >= 0.5F)
return metadata | 8;
return metadata;
}
public int damageDropped (int meta)
{
return meta % 8;
}
}