move more block logic to mantle

This commit is contained in:
Progwml6 committed 2013-12-06 13:33:55 -05:00
1 parent d19d4d4a0c
commit bbec72109a
19 files changed
+35 -590

No files matched your search

@@ -1,102 +0,0 @@
package tconstruct.library.blocks;
import java.util.Random;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import mantle.blocks.iface.IFacingLogic;
import mantle.blocks.abstracts.InventoryLogic;
public abstract class AdaptiveInventoryLogic extends InventoryLogic implements IFacingLogic
{
Random random = new Random();
protected int inventorySize;
public AdaptiveInventoryLogic()
{
super(0);
}
protected void adjustInventory (int size, boolean forceAdjust)
{
if (size != inventorySize || forceAdjust)
{
inventorySize = size;
ItemStack[] tempInv = inventory;
inventory = new ItemStack[size];
int invLength = tempInv.length > inventory.length ? inventory.length : tempInv.length;
System.arraycopy(tempInv, 0, inventory, 0, invLength);
if (tempInv.length > inventory.length)
{
for (int i = inventory.length; i < tempInv.length; i++)
{
ItemStack stack = tempInv[i];
if (stack != null)
{
float jumpX = random.nextFloat() * 0.8F + 0.1F;
float jumpY = random.nextFloat() * 0.8F + 0.1F;
float jumpZ = random.nextFloat() * 0.8F + 0.1F;
int offsetX = 0;
int offsetY = 0;
int offsetZ = 0;
switch (getTossDirection())
{
case 0: // -y
offsetY--;
break;
case 1: // +y
offsetY++;
break;
case 2: // +z
offsetZ--;
break;
case 3: // -z
offsetZ++;
break;
case 4: // +x
offsetX--;
break;
case 5: // -x
offsetX++;
break;
}
while (stack.stackSize > 0)
{
int itemSize = random.nextInt(21) + 10;
if (itemSize > stack.stackSize)
{
itemSize = stack.stackSize;
}
stack.stackSize -= itemSize;
EntityItem entityitem = new EntityItem(worldObj, (double) ((float) xCoord + jumpX + offsetX), (double) ((float) yCoord + jumpY),
(double) ((float) zCoord + jumpZ + offsetZ), 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) random.nextGaussian() * offset);
entityitem.motionY = (double) ((float) random.nextGaussian() * offset + 0.2F);
entityitem.motionZ = (double) ((float) random.nextGaussian() * offset);
worldObj.spawnEntityInWorld(entityitem);
}
}
}
}
}
}
public int getTossDirection ()
{
return getRenderDirection();
}
}
@@ -1,218 +0,0 @@
package tconstruct.library.blocks;
import java.util.*;
import net.minecraft.entity.player.*;
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
{
public ExpandableInventoryLogic()
{
super(0);
}
protected ArrayList<ItemStack> inventory = new ArrayList<ItemStack>();
protected String invName;
@Override
public ItemStack getStackInSlot (int slot)
{
return slot < inventory.size() ? inventory.get(slot) : null;
}
public boolean isStackInSlot (int slot)
{
return slot < inventory.size() && inventory.get(slot) != null;
}
@Override
public int getSizeInventory ()
{
return inventory.size();
}
public int getMaxSize ()
{
return 64;
}
@Override
public int getInventoryStackLimit ()
{
return 64;
}
public boolean canDropInventorySlot (int slot)
{
return true;
}
@Override
public void setInventorySlotContents (int slot, ItemStack itemstack)
{
if (slot < inventory.size())
{
inventory.set(slot, itemstack);
}
else if (slot == inventory.size())
{
inventory.add(itemstack);
}
else if (slot < getMaxSize())
{
inventory.ensureCapacity(slot);
inventory.set(slot, itemstack);
}
else
{
return;
}
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
itemstack.stackSize = getInventoryStackLimit();
}
}
@Override
public ItemStack decrStackSize (int slot, int quantity)
{
if (slot < inventory.size() && inventory.get(slot) != null)
{
if (inventory.get(slot).stackSize <= quantity)
{
ItemStack stack = inventory.get(slot);
inventory.set(slot, null);
return stack;
}
ItemStack split = inventory.get(slot).splitStack(quantity);
if (inventory.get(slot).stackSize == 0)
{
inventory.set(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);
this.invName = tags.getString("InvName");
NBTTagList nbttaglist = tags.getTagList("Items");
inventory = new ArrayList<ItemStack>();
inventory.ensureCapacity(nbttaglist.tagCount() > getMaxSize() ? getMaxSize() : nbttaglist.tagCount());
for (int iter = 0; iter < nbttaglist.tagCount(); iter++)
{
NBTTagCompound tagList = (NBTTagCompound) nbttaglist.tagAt(iter);
byte slotID = tagList.getByte("Slot");
if (slotID >= 0 && slotID < inventory.size())
{
inventory.set(slotID, ItemStack.loadItemStackFromNBT(tagList));
}
}
}
@Override
public void writeToNBT (NBTTagCompound tags)
{
super.writeToNBT(tags);
if (invName != null)
tags.setString("InvName", invName);
NBTTagList nbttaglist = new NBTTagList();
for (int iter = 0; iter < inventory.size(); iter++)
{
if (inventory.get(iter) != null)
{
NBTTagCompound tagList = new NBTTagCompound();
tagList.setByte("Slot", (byte) iter);
inventory.get(iter).writeToNBT(tagList);
nbttaglist.appendTag(tagList);
}
}
tags.setTag("Items", nbttaglist);
}
/* 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;
}
public void cleanInventory ()
{
Iterator<ItemStack> i1 = inventory.iterator();
while (i1.hasNext())
{
if (i1.next() == null)
{
i1.remove();
}
}
}
@Override
public boolean isItemValidForSlot (int slot, ItemStack itemstack)
{
if (slot < getSizeInventory())
{
if (inventory.get(slot) == null || itemstack.stackSize + inventory.get(slot).stackSize <= getInventoryStackLimit())
return true;
}
else
{
return slot < getMaxSize();
}
return false;
}
}
@@ -6,10 +6,11 @@ import net.minecraft.block.Block;
import net.minecraft.nbt.*;
import net.minecraft.tileentity.TileEntity;
import tconstruct.TConstruct;
import tconstruct.library.util.IMasterLogic;
import tconstruct.library.util.IServantLogic;
import mantle.world.*;
import mantle.blocks.iface.IFacingLogic;
import mantle.blocks.iface.IMasterLogic;
import mantle.blocks.iface.IServantLogic;
public class TankLayerScan extends LogicComponent
{
@@ -1,12 +0,0 @@
package tconstruct.library.util;
public interface IMasterLogic
{
/** Called when servants change their state
*
* @param x Servant X
* @param y Servant Y
* @param z Servant Z
*/
public void notifyChange (IServantLogic servant, int x, int y, int z);
}
@@ -1,8 +0,0 @@
package tconstruct.library.util;
public interface IMasterNode extends IMasterLogic, IServantLogic
{
public boolean isCurrentlyMaster ();
public boolean isEquivalentMaster (IMasterLogic master);
}
@@ -1,44 +0,0 @@
package tconstruct.library.util;
import mantle.world.CoordTuple;
import net.minecraft.world.World;
public interface IServantLogic
{
public CoordTuple getMasterPosition ();
/** The block should already have a valid master */
public void notifyMasterOfChange ();
/** Checks if this block can be tied to this master
*
* @param master
* @param x xCoord of master
* @param y yCoord of master
* @param z zCoord of master
* @return whether the servant can be tied to this master
*/
public boolean setPotentialMaster (IMasterLogic master, World world, int xMaster, int yMaster, int zMaster);
/** Used to set and verify that this is the block's master
*
* @param master
* @param x xCoord of master
* @param y yCoord of master
* @param z zCoord of master
* @return Is this block tied to this master?
*/
public boolean verifyMaster (IMasterLogic master, World world, int xMaster, int yMaster, int zMaster);
/** Exactly what it says on the tin
*
* @param master
* @param x xCoord of master
* @param y yCoord of master
* @param z zCoord of master
*/
public void invalidateMaster (IMasterLogic master, World world, int xMaster, int yMaster, int zMaster);
}