A few fixes, need to fix an output issue

This commit is contained in:
Aidan C. Brady 2015-03-04 13:04:32 -05:00
parent 5747c9f904
commit af4c1c6cd7
10 changed files with 157 additions and 69 deletions

View file

@ -7,6 +7,8 @@ import java.util.Random;
import mekanism.api.Coord4D;
import mekanism.api.Range4D;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.client.ClientProxy;
import mekanism.client.render.MekanismRenderer.ICustomBlockIcon;
import mekanism.common.CTMData;
@ -913,6 +915,14 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon
((ItemBlockBasic)ret.getItem()).setTier(ret, tileEntity.tier.getBaseTier());
}
}
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(tileEntity instanceof IStrictEnergyStorage)
{
IEnergizedItem energizedItem = (IEnergizedItem)ret.getItem();
energizedItem.setEnergy(ret, ((IStrictEnergyStorage)tileEntity).getEnergy());
}
return ret;
}
@ -934,7 +944,7 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon
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, getPickBlock(null, world, x, y, z));
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, getPickBlock(null, world, x, y, z, player));
world.spawnEntityInWorld(entityItem);
}
@ -944,7 +954,7 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon
public ItemStack dismantleBlock(World world, int x, int y, int z, boolean returnBlock)
{
ItemStack itemStack = getPickBlock(null, world, x, y, z);
ItemStack itemStack = getPickBlock(null, world, x, y, z, null);
world.setBlockToAir(x, y, z);

View file

@ -8,6 +8,7 @@ import mekanism.api.MekanismConfig.client;
import mekanism.api.MekanismConfig.general;
import mekanism.api.MekanismConfig.usage;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.client.ClientProxy;
import mekanism.common.ItemAttacher;
import mekanism.common.Mekanism;
@ -43,7 +44,6 @@ import mekanism.common.tile.TileEntityCombiner;
import mekanism.common.tile.TileEntityContainerBlock;
import mekanism.common.tile.TileEntityCrusher;
import mekanism.common.tile.TileEntityDigitalMiner;
import mekanism.common.tile.TileEntityElectricBlock;
import mekanism.common.tile.TileEntityElectricChest;
import mekanism.common.tile.TileEntityElectricPump;
import mekanism.common.tile.TileEntityElectrolyticSeparator;
@ -709,7 +709,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
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, getPickBlock(null, world, x, y, z));
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, getPickBlock(null, world, x, y, z, player));
world.spawnEntityInWorld(entityItem);
}
@ -861,7 +861,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player)
{
TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getTileEntity(x, y, z);
ItemStack itemStack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
@ -901,10 +901,10 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
itemStack.stackTagCompound.setInteger("controlType", control.getControlType().ordinal());
}
if(tileEntity instanceof TileEntityElectricBlock)
if(tileEntity instanceof IStrictEnergyStorage)
{
IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem();
energizedItem.setEnergy(itemStack, ((TileEntityElectricBlock)tileEntity).electricityStored);
energizedItem.setEnergy(itemStack, ((IStrictEnergyStorage)tileEntity).getEnergy());
}
if(tileEntity instanceof TileEntityContainerBlock && ((TileEntityContainerBlock)tileEntity).inventory.length > 0)
@ -943,7 +943,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
public ItemStack dismantleBlock(World world, int x, int y, int z, boolean returnBlock)
{
ItemStack itemStack = getPickBlock(null, world, x, y, z);
ItemStack itemStack = getPickBlock(null, world, x, y, z, null);
world.setBlockToAir(x, y, z);

View file

@ -11,20 +11,16 @@ public class MatrixCache extends MultiblockCache<SynchronizedMatrixData>
{
public ItemStack[] inventory = new ItemStack[2];
public double electricityStored;
@Override
public void apply(SynchronizedMatrixData data)
{
data.inventory = inventory;
data.electricityStored = electricityStored;
}
@Override
public void sync(SynchronizedMatrixData data)
{
inventory = data.inventory;
electricityStored = data.electricityStored;
}
@Override
@ -43,8 +39,6 @@ public class MatrixCache extends MultiblockCache<SynchronizedMatrixData>
inventory[slotID] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
electricityStored = nbtTags.getDouble("electricityStored");
}
@Override
@ -64,7 +58,5 @@ public class MatrixCache extends MultiblockCache<SynchronizedMatrixData>
}
nbtTags.setTag("Items", tagList);
nbtTags.setDouble("electricityStored", electricityStored);
}
}

View file

@ -83,8 +83,6 @@ public class MatrixUpdateProtocol extends UpdateProtocol<SynchronizedMatrixData>
{
structureFound.cells.add(coord);
structureFound.storageCap += ((TileEntityInductionCell)tile).tier.MAX_ELECTRICITY;
structureFound.electricityStored += ((TileEntityInductionCell)tile).getEnergy();
((TileEntityInductionCell)tile).setEnergy(0);
}
else if(tile instanceof TileEntityInductionProvider)
{
@ -93,30 +91,4 @@ public class MatrixUpdateProtocol extends UpdateProtocol<SynchronizedMatrixData>
}
}
}
@Override
protected void onStructureDestroyed(SynchronizedMatrixData structure)
{
if(structure.electricityStored <= 0)
{
return;
}
for(Coord4D coord : structure.cells)
{
if(coord.getTileEntity(pointer.getWorldObj()) instanceof TileEntityInductionCell)
{
TileEntityInductionCell cell = (TileEntityInductionCell)coord.getTileEntity(pointer.getWorldObj());
double toAdd = Math.min(cell.getMaxEnergy()-cell.getEnergy(), structure.electricityStored);
cell.setEnergy(cell.getEnergy()+toAdd);
structure.electricityStored -= toAdd;
}
if(structure.electricityStored <= 0)
{
break;
}
}
}
}

View file

@ -5,14 +5,15 @@ import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.common.multiblock.SynchronizedData;
import mekanism.common.tile.TileEntityInductionCell;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class SynchronizedMatrixData extends SynchronizedData<SynchronizedMatrixData>
{
public ItemStack[] inventory = new ItemStack[2];
public double electricityStored;
public Set<Coord4D> cells = new HashSet<Coord4D>();
public Set<Coord4D> providers = new HashSet<Coord4D>();
@ -20,6 +21,7 @@ public class SynchronizedMatrixData extends SynchronizedData<SynchronizedMatrixD
public double remainingOutput;
public double lastOutput;
public double clientEnergy;
public double storageCap;
public double outputCap;
@ -28,4 +30,43 @@ public class SynchronizedMatrixData extends SynchronizedData<SynchronizedMatrixD
{
return inventory;
}
public double getEnergy(World world)
{
double ret = 0;
for(Coord4D coord : cells)
{
TileEntity tile = coord.getTileEntity(world);
if(tile instanceof TileEntityInductionCell)
{
ret += ((TileEntityInductionCell)tile).getEnergy();
}
}
return ret;
}
public void setEnergy(World world, double energy)
{
for(Coord4D coord : cells)
{
if(energy <= 0)
{
return;
}
TileEntity tile = coord.getTileEntity(world);
if(tile instanceof TileEntityInductionCell)
{
TileEntityInductionCell cell = (TileEntityInductionCell)tile;
double toAdd = Math.min(cell.getMaxEnergy(), energy);
cell.setEnergy(toAdd);
energy -= toAdd;
}
}
}
}

View file

@ -6,6 +6,8 @@ import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.Range4D;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.Tier.BaseTier;
@ -16,11 +18,13 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityBin;
import mekanism.common.tile.TileEntityInductionCell;
import mekanism.common.tile.TileEntityInductionProvider;
import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
@ -52,7 +56,7 @@ import cpw.mods.fml.relauncher.SideOnly;
* @author AidanBrady
*
*/
public class ItemBlockBasic extends ItemBlock
public class ItemBlockBasic extends ItemBlock implements IEnergizedItem
{
public Block metaBlock;
@ -83,20 +87,6 @@ public class ItemBlockBasic extends ItemBlock
itemstack.stackTagCompound.setInteger("tier", tier.ordinal());
}
@Override
public int getItemStackLimit(ItemStack stack)
{
if(Block.getBlockFromItem(this) == MekanismBlocks.BasicBlock)
{
if(stack.getItemDamage() == 6)
{
return 1;
}
}
return 64;
}
@Override
public int getMetadata(int i)
{
@ -126,6 +116,11 @@ public class ItemBlockBasic extends ItemBlock
list.add(EnumColor.DARK_RED + "Empty");
}
}
if(getMaxEnergy(itemstack) > 0)
{
list.add(EnumColor.BRIGHT_GREEN + MekanismUtils.localize("tooltip.storedEnergy") + ": " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergy(itemstack)));
}
}
@Override
@ -215,6 +210,13 @@ public class ItemBlockBasic extends ItemBlock
}
}
}
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(tileEntity instanceof IStrictEnergyStorage)
{
((IStrictEnergyStorage)tileEntity).setEnergy(getEnergy(stack));
}
}
return place;
@ -306,4 +308,69 @@ public class ItemBlockBasic extends ItemBlock
return getUnlocalizedName() + "." + name;
}
@Override
public double getEnergy(ItemStack itemStack)
{
if(Block.getBlockFromItem(this) == MekanismBlocks.BasicBlock2 && itemStack.getItemDamage() == 3)
{
if(itemStack.stackTagCompound == null)
{
return 0;
}
return itemStack.stackTagCompound.getDouble("energyStored");
}
return 0;
}
@Override
public void setEnergy(ItemStack itemStack, double amount)
{
if(Block.getBlockFromItem(this) == MekanismBlocks.BasicBlock2 && itemStack.getItemDamage() == 3)
{
if(itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.stackTagCompound.setDouble("energyStored", Math.max(Math.min(amount, getMaxEnergy(itemStack)), 0));
}
}
@Override
public double getMaxEnergy(ItemStack itemStack)
{
if(Block.getBlockFromItem(this) == MekanismBlocks.BasicBlock2 && itemStack.getItemDamage() == 3)
{
return InductionCellTier.values()[getTier(itemStack).ordinal()].MAX_ELECTRICITY;
}
return 0;
}
@Override
public double getMaxTransfer(ItemStack itemStack)
{
return 0;
}
@Override
public boolean canReceive(ItemStack itemStack)
{
return false;
}
@Override
public boolean canSend(ItemStack itemStack)
{
return false;
}
@Override
public boolean isMetadataSpecific(ItemStack itemStack)
{
return true;
}
}

View file

@ -187,6 +187,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
if(hasTank(itemstack) && type != MachineType.PORTABLE_TANK)
{
FluidStack fluidStack = getFluidStack(itemstack);
if(fluidStack != null)
{
list.add(EnumColor.PINK + LangUtils.localizeFluidStack(fluidStack) + ": " + EnumColor.GREY + getFluidStack(itemstack).amount + "mB");

View file

@ -369,7 +369,7 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
protected void onStructureCreated(T structure, int origX, int origY, int origZ, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax) {}
protected void onStructureDestroyed(T structure) {}
public void onStructureDestroyed(T structure) {}
/**
* Runs the protocol and updates all nodes that make a part of the multiblock.

View file

@ -54,7 +54,7 @@ public class TileEntityInductionCasing extends TileEntityMultiblock<Synchronized
if(structure != null)
{
data.add(structure.electricityStored);
data.add(structure.getEnergy(worldObj));
data.add(structure.storageCap);
data.add(structure.outputCap);
data.add(structure.lastOutput);
@ -77,7 +77,7 @@ public class TileEntityInductionCasing extends TileEntityMultiblock<Synchronized
if(clientHasStructure)
{
structure.electricityStored = dataStream.readDouble();
structure.clientEnergy = dataStream.readDouble();
structure.storageCap = dataStream.readDouble();
structure.outputCap = dataStream.readDouble();
structure.lastOutput = dataStream.readDouble();
@ -123,7 +123,13 @@ public class TileEntityInductionCasing extends TileEntityMultiblock<Synchronized
@Override
public double getEnergy()
{
return structure != null ? structure.electricityStored : 0;
if(!worldObj.isRemote)
{
return structure != null ? structure.getEnergy(worldObj) : 0;
}
else {
return structure.clientEnergy;
}
}
@Override
@ -131,7 +137,7 @@ public class TileEntityInductionCasing extends TileEntityMultiblock<Synchronized
{
if(structure != null)
{
structure.electricityStored = Math.max(Math.min(energy, getMaxEnergy()), 0);
structure.setEnergy(worldObj, Math.max(Math.min(energy, getMaxEnergy()), 0));
MekanismUtils.saveChunk(this);
}
}

View file

@ -1,5 +1,7 @@
package mekanism.common.tile;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import mekanism.api.Coord4D;
@ -10,7 +12,6 @@ import mekanism.common.multiblock.MultiblockManager;
import mekanism.common.multiblock.SynchronizedData;
import mekanism.common.multiblock.UpdateProtocol;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
@ -18,8 +19,6 @@ import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extends TileEntityContainerBlock implements IMultiblock<T>
{
/** The multiblock data for this structure. */