Item ejecting! Still have a minor bug to fix.
This commit is contained in:
parent
ab262c9b54
commit
a00acf06b5
3 changed files with 51 additions and 12 deletions
|
@ -11,7 +11,7 @@ public class ListUtil
|
|||
{
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
for(int i = list.size(); i >= 0; i--)
|
||||
for(int i = list.size()-1; i >= 0; i--)
|
||||
{
|
||||
toReturn.add((V)list.get(i));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -27,12 +28,8 @@ public class BatteryUpdateProtocol
|
|||
{
|
||||
pointer = tileEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively loops through each node connected to the given TileEntity.
|
||||
* @param tile - the TileEntity to loop over
|
||||
*/
|
||||
public void loopThrough(TileEntity tile)
|
||||
|
||||
private void loopThrough(TileEntity tile)
|
||||
{
|
||||
if(structureFound == null)
|
||||
{
|
||||
|
@ -202,7 +199,7 @@ public class BatteryUpdateProtocol
|
|||
return false;
|
||||
}
|
||||
|
||||
public void disperseCells()
|
||||
private void disperseCells()
|
||||
{
|
||||
SynchronizedBatteryData oldStructure = null;
|
||||
|
||||
|
@ -219,8 +216,8 @@ public class BatteryUpdateProtocol
|
|||
{
|
||||
int maxCells = iteratedNodes.size()*BatteryManager.CELLS_PER_BATTERY;
|
||||
|
||||
//TODO eject these
|
||||
List<ItemStack> rejected = ListUtil.capRemains(oldStructure.inventory, maxCells);
|
||||
ejectItems(rejected, new Vector3(pointer));
|
||||
|
||||
ArrayList<List<ItemStack>> inventories = ListUtil.split(ListUtil.cap(oldStructure.inventory, maxCells), iteratedNodes.size());
|
||||
List<TileEntityBattery> iterList = ListUtil.asList(iteratedNodes);
|
||||
|
@ -241,9 +238,21 @@ public class BatteryUpdateProtocol
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the protocol and updates all batteries that make a part of the multiblock battery.
|
||||
*/
|
||||
private void ejectItems(List<ItemStack> items, Vector3 vec)
|
||||
{
|
||||
for(ItemStack itemStack : items)
|
||||
{
|
||||
float motion = 0.7F;
|
||||
double motionX = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
double motionY = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
double motionZ = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
|
||||
EntityItem entityItem = new EntityItem(pointer.worldObj, vec.x + motionX, vec.y + motionY, vec.z + motionZ, itemStack);
|
||||
|
||||
pointer.worldObj.spawnEntityInWorld(entityItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBatteries()
|
||||
{
|
||||
loopThrough(pointer);
|
||||
|
@ -274,6 +283,9 @@ public class BatteryUpdateProtocol
|
|||
tileEntity.structure = structureFound;
|
||||
}
|
||||
|
||||
List<ItemStack> rejected = ListUtil.capRemains(structureFound.inventory, structureFound.getMaxCells());
|
||||
ejectItems(rejected, new Vector3(pointer));
|
||||
|
||||
structureFound.inventory = ListUtil.cap(structureFound.inventory, structureFound.getMaxCells());
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -5,6 +5,7 @@ package resonantinduction.battery;
|
|||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
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.tileentity.TileEntity;
|
||||
|
@ -141,6 +142,32 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z)
|
||||
{
|
||||
if(!world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
|
||||
{
|
||||
TileEntityBattery tileEntity = (TileEntityBattery)world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if(!tileEntity.structure.isMultiblock)
|
||||
{
|
||||
for(ItemStack itemStack : tileEntity.structure.inventory)
|
||||
{
|
||||
float motion = 0.7F;
|
||||
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
|
||||
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, itemStack);
|
||||
|
||||
world.spawnEntityInWorld(entityItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.removeBlockByPlayer(world, player, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
|
Loading…
Reference in a new issue