From fbd85af4f0dec56d4740c98fa8157c5228d22e37 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 11 Aug 2015 16:20:01 +0200 Subject: [PATCH] All of teh power for Playerfaces! --- .../tile/TileEntityPhantomPlayerface.java | 89 ++++++++++++++----- .../tile/TileEntityPhantomface.java | 6 -- 2 files changed, 69 insertions(+), 26 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomPlayerface.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomPlayerface.java index 71ce243df..d4e736de8 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomPlayerface.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomPlayerface.java @@ -1,28 +1,42 @@ package ellpeck.actuallyadditions.tile; +import cofh.api.energy.EnergyStorage; +import cofh.api.energy.IEnergyReceiver; import ellpeck.actuallyadditions.util.WorldUtil; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; +import net.minecraftforge.common.util.ForgeDirection; import java.util.List; import java.util.Objects; -public class TileEntityPhantomPlayerface extends TileEntityInventoryBase{ +public class TileEntityPhantomPlayerface extends TileEntityInventoryBase implements IEnergyReceiver{ public String boundPlayerUUID; private String boundPlayerBefore; + private EnergyStorage storage = new EnergyStorage(250000); + private boolean hadEnoughBefore; + private final int energyUsePerTick = 1000; + public TileEntityPhantomPlayerface(){ super(0, "phantomPlayerface"); } @Override public void updateEntity(){ - if(!Objects.equals(this.boundPlayerUUID, this.boundPlayerBefore)){ - this.boundPlayerBefore = this.boundPlayerUUID; - WorldUtil.updateTileAndTilesAround(this); + if(!worldObj.isRemote){ + if(!Objects.equals(this.boundPlayerUUID, this.boundPlayerBefore) || this.hadEnoughBefore != this.storage.getEnergyStored() >= energyUsePerTick){ + this.boundPlayerBefore = this.boundPlayerUUID; + this.hadEnoughBefore = this.storage.getEnergyStored() >= energyUsePerTick; + WorldUtil.updateTileAndTilesAround(this); + } + + if(this.hasEnoughEnergy() && this.hasInventory()){ + this.storage.extractEnergy(this.energyUsePerTick, false); + } } } @@ -43,45 +57,61 @@ public class TileEntityPhantomPlayerface extends TileEntityInventoryBase{ return this.getInventory() != null; } - @Override - public int getInventoryStackLimit(){ - return this.hasInventory() ? this.getInventory().getInventoryStackLimit() : 0; + private boolean hasEnoughEnergy(){ + return this.storage.getEnergyStored() >= this.energyUsePerTick; } @Override - public boolean isUseableByPlayer(EntityPlayer player){ - return false; + public int getInventoryStackLimit(){ + if(this.hasInventory() && this.hasEnoughEnergy()){ + return this.getInventory().getInventoryStackLimit(); + } + return 0; } @Override public boolean isItemValidForSlot(int i, ItemStack stack){ - return this.hasInventory() && this.getInventory().isItemValidForSlot(i, stack); + return this.hasInventory() && this.hasEnoughEnergy() && this.getInventory().isItemValidForSlot(i, stack); } @Override public ItemStack getStackInSlotOnClosing(int i){ - return this.hasInventory() ? this.getInventory().getStackInSlotOnClosing(i) : null; + if(this.hasInventory() && this.hasEnoughEnergy()){ + return this.getInventory().getStackInSlotOnClosing(i); + } + return null; } @Override public void setInventorySlotContents(int i, ItemStack stack){ - if(this.hasInventory()) this.getInventory().setInventorySlotContents(i, stack); - this.markDirty(); + if(this.hasInventory() && this.hasEnoughEnergy()){ + this.getInventory().setInventorySlotContents(i, stack); + this.markDirty(); + } } @Override public int getSizeInventory(){ - return this.hasInventory() ? this.getInventory().getSizeInventory() : 0; + if(this.hasInventory() && this.hasEnoughEnergy()){ + return this.getInventory().getSizeInventory(); + } + return 0; } @Override public ItemStack getStackInSlot(int i){ - return this.hasInventory() ? this.getInventory().getStackInSlot(i) : null; + if(this.hasInventory() && this.hasEnoughEnergy()){ + return this.getInventory().getStackInSlot(i); + } + return null; } @Override public ItemStack decrStackSize(int i, int j){ - return this.hasInventory() ? this.getInventory().decrStackSize(i, j) : null; + if(this.hasInventory() && this.hasEnoughEnergy()){ + return this.getInventory().decrStackSize(i, j); + } + return null; } @Override @@ -91,8 +121,8 @@ public class TileEntityPhantomPlayerface extends TileEntityInventoryBase{ @Override public int[] getAccessibleSlotsFromSide(int side){ - if(this.hasInventory()){ - int[] theInt = new int[this.getSizeInventory()]; + if(this.hasInventory() && this.hasEnoughEnergy()){ + int[] theInt = new int[this.getInventory().getSizeInventory()]; for(int i = 0; i < theInt.length; i++){ theInt[i] = i; } @@ -103,12 +133,31 @@ public class TileEntityPhantomPlayerface extends TileEntityInventoryBase{ @Override public boolean canInsertItem(int slot, ItemStack stack, int side){ - return this.hasInventory(); + return this.hasInventory() && this.hasEnoughEnergy(); } @Override public boolean canExtractItem(int slot, ItemStack stack, int side){ - return this.hasInventory(); + return this.hasInventory() && this.hasEnoughEnergy(); } + @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; + } } diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java index 25c82908c..7aed2cd11 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java @@ -9,7 +9,6 @@ import ellpeck.actuallyadditions.config.values.ConfigIntValues; import ellpeck.actuallyadditions.util.WorldPos; import ellpeck.actuallyadditions.util.WorldUtil; import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -359,11 +358,6 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP return this.isBoundThingInRange() ? this.getInventory().getInventoryStackLimit() : 0; } - @Override - public boolean isUseableByPlayer(EntityPlayer player){ - return false; - } - @Override public boolean isItemValidForSlot(int i, ItemStack stack){ return this.isBoundThingInRange() && this.getInventory().isItemValidForSlot(i, stack);