mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-10 18:49:08 +01:00
Atomic Reconstructor RF usage
This commit is contained in:
parent
b977909092
commit
8409d10f74
2 changed files with 68 additions and 23 deletions
|
@ -19,9 +19,11 @@ import net.minecraft.block.BlockPistonBase;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -94,4 +96,16 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IAct
|
|||
int rotation = BlockPistonBase.determineOrientation(world, x, y, z, player);
|
||||
world.setBlockMetadataWithNotify(x, y, z, rotation, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
|
||||
if(!world.isRemote){
|
||||
TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor)world.getTileEntity(x, y, z);
|
||||
if(reconstructor != null){
|
||||
player.addChatComponentMessage(new ChatComponentText(reconstructor.storage.getEnergyStored()+"/"+reconstructor.storage.getMaxEnergyStored()+" RF"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
package ellpeck.actuallyadditions.tile;
|
||||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import ellpeck.actuallyadditions.recipe.AtomicReconstructorRecipeHandler;
|
||||
import ellpeck.actuallyadditions.util.WorldPos;
|
||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||
|
@ -23,7 +25,9 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TileEntityAtomicReconstructor extends TileEntityBase{
|
||||
public class TileEntityAtomicReconstructor extends TileEntityBase implements IEnergyReceiver{
|
||||
|
||||
public EnergyStorage storage = new EnergyStorage(300000);
|
||||
|
||||
private int currentTime;
|
||||
|
||||
|
@ -31,7 +35,8 @@ public class TileEntityAtomicReconstructor extends TileEntityBase{
|
|||
@SuppressWarnings("unchecked")
|
||||
public void updateEntity(){
|
||||
if(!this.worldObj.isRemote){
|
||||
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
||||
int usePerBlock = 1200; //TODO Config
|
||||
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) && this.storage.getEnergyStored() >= usePerBlock){
|
||||
if(this.currentTime > 0){
|
||||
this.currentTime--;
|
||||
if(this.currentTime <= 0){
|
||||
|
@ -47,6 +52,7 @@ public class TileEntityAtomicReconstructor extends TileEntityBase{
|
|||
for(int reachX = -range; reachX < range+1; reachX++){
|
||||
for(int reachZ = -range; reachZ < range+1; reachZ++){
|
||||
for(int reachY = -range; reachY < range+1; reachY++){
|
||||
if(this.storage.getEnergyStored() >= usePerBlock){
|
||||
WorldPos pos = new WorldPos(worldObj, coordsBlock.getX()+reachX, coordsBlock.getY()+reachY, coordsBlock.getZ()+reachZ);
|
||||
AtomicReconstructorRecipeHandler.Recipe recipe = AtomicReconstructorRecipeHandler.getRecipe(new ItemStack(pos.getBlock(), pos.getMetadata()));
|
||||
if(recipe != null){
|
||||
|
@ -60,6 +66,8 @@ public class TileEntityAtomicReconstructor extends TileEntityBase{
|
|||
EntityItem item = new EntityItem(worldObj, pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, output.copy());
|
||||
worldObj.spawnEntityInWorld(item);
|
||||
}
|
||||
this.storage.extractEnergy(usePerBlock, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +77,7 @@ public class TileEntityAtomicReconstructor extends TileEntityBase{
|
|||
//Converting the Items
|
||||
ArrayList<EntityItem> items = (ArrayList<EntityItem>)worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(coordsBlock.getX()-range, coordsBlock.getY()-range, coordsBlock.getZ()-range, coordsBlock.getX()+range, coordsBlock.getY()+range, coordsBlock.getZ()+range));
|
||||
for(EntityItem item : items){
|
||||
if(this.storage.getEnergyStored() >= usePerBlock){
|
||||
ItemStack stack = item.getEntityItem();
|
||||
if(stack != null){
|
||||
AtomicReconstructorRecipeHandler.Recipe recipe = AtomicReconstructorRecipeHandler.getRecipe(stack);
|
||||
|
@ -78,6 +87,9 @@ public class TileEntityAtomicReconstructor extends TileEntityBase{
|
|||
ItemStack outputCopy = output.copy();
|
||||
outputCopy.stackSize = stack.stackSize;
|
||||
item.setEntityItemStack(outputCopy);
|
||||
|
||||
this.storage.extractEnergy(usePerBlock, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,4 +120,23 @@ public class TileEntityAtomicReconstructor extends TileEntityBase{
|
|||
this.currentTime = compound.getInteger("CurrentTime");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate){
|
||||
return this.storage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from){
|
||||
return this.storage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from){
|
||||
return this.storage.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue