All of teh power for Playerfaces!

This commit is contained in:
Ellpeck 2015-08-11 16:20:01 +02:00
parent a9bcf90fec
commit fbd85af4f0
2 changed files with 69 additions and 26 deletions

View file

@ -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;
}
}

View file

@ -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);