From 8f0cc2247271676d9857135ddcb6f6c2e7edb774 Mon Sep 17 00:00:00 2001 From: Ourten Date: Thu, 15 Dec 2016 14:35:37 +0100 Subject: [PATCH] Add activation state change to DragonEggSiphoner + Add convenient energy add method --- .../generator/TileDragonEggSiphoner.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/techreborn/tiles/generator/TileDragonEggSiphoner.java b/src/main/java/techreborn/tiles/generator/TileDragonEggSiphoner.java index b4bea25c8..61f98fdad 100644 --- a/src/main/java/techreborn/tiles/generator/TileDragonEggSiphoner.java +++ b/src/main/java/techreborn/tiles/generator/TileDragonEggSiphoner.java @@ -8,6 +8,7 @@ import net.minecraft.util.math.BlockPos; import reborncore.api.power.EnumPowerTier; import reborncore.api.tile.IInventoryProvider; import reborncore.common.IWrenchable; +import reborncore.common.blocks.BlockMachineBase; import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.util.Inventory; import techreborn.config.ConfigTechReborn; @@ -22,17 +23,42 @@ public class TileDragonEggSiphoner extends TilePowerAcceptor implements IWrencha super(2); } + private long lastOutput = 0; + @Override public void updateEntity() { super.updateEntity(); if (!world.isRemote) { if (world.getBlockState(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ())) - .getBlock() == Blocks.DRAGON_EGG) { - addEnergy(euTick); + .getBlock() == Blocks.DRAGON_EGG) { + if(tryAddingEnergy(euTick)) + this.lastOutput = this.world.getTotalWorldTime(); } + + if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive()) + this.world.setBlockState(this.getPos(), + this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true)); + else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && this.isActive()) + this.world.setBlockState(this.getPos(), + this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false)); } } + + private boolean tryAddingEnergy(int amount) + { + if(this.getMaxPower() - this.getEnergy() >= amount) + { + addEnergy(amount); + return true; + } + else if(this.getMaxPower() - this.getEnergy() > 0) + { + addEnergy(this.getMaxPower() - this.getEnergy()); + return true; + } + return false; + } @Override public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {