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,29 +1,43 @@
package ellpeck.actuallyadditions.tile; package ellpeck.actuallyadditions.tile;
import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import ellpeck.actuallyadditions.util.WorldUtil; import ellpeck.actuallyadditions.util.WorldUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
public class TileEntityPhantomPlayerface extends TileEntityInventoryBase{ public class TileEntityPhantomPlayerface extends TileEntityInventoryBase implements IEnergyReceiver{
public String boundPlayerUUID; public String boundPlayerUUID;
private String boundPlayerBefore; private String boundPlayerBefore;
private EnergyStorage storage = new EnergyStorage(250000);
private boolean hadEnoughBefore;
private final int energyUsePerTick = 1000;
public TileEntityPhantomPlayerface(){ public TileEntityPhantomPlayerface(){
super(0, "phantomPlayerface"); super(0, "phantomPlayerface");
} }
@Override @Override
public void updateEntity(){ public void updateEntity(){
if(!Objects.equals(this.boundPlayerUUID, this.boundPlayerBefore)){ if(!worldObj.isRemote){
if(!Objects.equals(this.boundPlayerUUID, this.boundPlayerBefore) || this.hadEnoughBefore != this.storage.getEnergyStored() >= energyUsePerTick){
this.boundPlayerBefore = this.boundPlayerUUID; this.boundPlayerBefore = this.boundPlayerUUID;
this.hadEnoughBefore = this.storage.getEnergyStored() >= energyUsePerTick;
WorldUtil.updateTileAndTilesAround(this); WorldUtil.updateTileAndTilesAround(this);
} }
if(this.hasEnoughEnergy() && this.hasInventory()){
this.storage.extractEnergy(this.energyUsePerTick, false);
}
}
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -43,45 +57,61 @@ public class TileEntityPhantomPlayerface extends TileEntityInventoryBase{
return this.getInventory() != null; return this.getInventory() != null;
} }
@Override private boolean hasEnoughEnergy(){
public int getInventoryStackLimit(){ return this.storage.getEnergyStored() >= this.energyUsePerTick;
return this.hasInventory() ? this.getInventory().getInventoryStackLimit() : 0;
} }
@Override @Override
public boolean isUseableByPlayer(EntityPlayer player){ public int getInventoryStackLimit(){
return false; if(this.hasInventory() && this.hasEnoughEnergy()){
return this.getInventory().getInventoryStackLimit();
}
return 0;
} }
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack stack){ 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 @Override
public ItemStack getStackInSlotOnClosing(int i){ 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 @Override
public void setInventorySlotContents(int i, ItemStack stack){ public void setInventorySlotContents(int i, ItemStack stack){
if(this.hasInventory()) this.getInventory().setInventorySlotContents(i, stack); if(this.hasInventory() && this.hasEnoughEnergy()){
this.getInventory().setInventorySlotContents(i, stack);
this.markDirty(); this.markDirty();
} }
}
@Override @Override
public int getSizeInventory(){ public int getSizeInventory(){
return this.hasInventory() ? this.getInventory().getSizeInventory() : 0; if(this.hasInventory() && this.hasEnoughEnergy()){
return this.getInventory().getSizeInventory();
}
return 0;
} }
@Override @Override
public ItemStack getStackInSlot(int i){ 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 @Override
public ItemStack decrStackSize(int i, int j){ 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 @Override
@ -91,8 +121,8 @@ public class TileEntityPhantomPlayerface extends TileEntityInventoryBase{
@Override @Override
public int[] getAccessibleSlotsFromSide(int side){ public int[] getAccessibleSlotsFromSide(int side){
if(this.hasInventory()){ if(this.hasInventory() && this.hasEnoughEnergy()){
int[] theInt = new int[this.getSizeInventory()]; int[] theInt = new int[this.getInventory().getSizeInventory()];
for(int i = 0; i < theInt.length; i++){ for(int i = 0; i < theInt.length; i++){
theInt[i] = i; theInt[i] = i;
} }
@ -103,12 +133,31 @@ public class TileEntityPhantomPlayerface extends TileEntityInventoryBase{
@Override @Override
public boolean canInsertItem(int slot, ItemStack stack, int side){ public boolean canInsertItem(int slot, ItemStack stack, int side){
return this.hasInventory(); return this.hasInventory() && this.hasEnoughEnergy();
} }
@Override @Override
public boolean canExtractItem(int slot, ItemStack stack, int side){ 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.WorldPos;
import ellpeck.actuallyadditions.util.WorldUtil; import ellpeck.actuallyadditions.util.WorldUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -359,11 +358,6 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
return this.isBoundThingInRange() ? this.getInventory().getInventoryStackLimit() : 0; return this.isBoundThingInRange() ? this.getInventory().getInventoryStackLimit() : 0;
} }
@Override
public boolean isUseableByPlayer(EntityPlayer player){
return false;
}
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack stack){ public boolean isItemValidForSlot(int i, ItemStack stack){
return this.isBoundThingInRange() && this.getInventory().isItemValidForSlot(i, stack); return this.isBoundThingInRange() && this.getInventory().isItemValidForSlot(i, stack);