BloodMagic/src/main/java/WayofTime/bloodmagic/tile/TilePhantomBlock.java

47 lines
1.3 KiB
Java
Raw Normal View History

2015-12-27 19:38:12 -05:00
package WayofTime.bloodmagic.tile;
2018-08-18 03:14:41 +02:00
import WayofTime.bloodmagic.item.sigil.ItemSigilPhantomBridge;
import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.tile.base.TileTicking;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT;
2015-12-27 19:38:12 -05:00
2017-08-15 21:30:48 -07:00
public class TilePhantomBlock extends TileTicking {
private int ticksRemaining = 10;
2015-12-27 19:38:12 -05:00
public TilePhantomBlock() {
}
2017-08-15 21:30:48 -07:00
public TilePhantomBlock(int ticksRemaining) {
this.ticksRemaining = ticksRemaining;
2015-12-27 19:38:12 -05:00
}
@Override
public void deserialize(CompoundNBT tagCompound) {
2019-09-23 09:51:22 -07:00
this.ticksRemaining = tagCompound.getInt(Constants.NBT.TICKS_REMAINING);
2015-12-27 19:38:12 -05:00
}
@Override
public CompoundNBT serialize(CompoundNBT tagCompound) {
2019-09-23 09:51:22 -07:00
tagCompound.putInt(Constants.NBT.TICKS_REMAINING, ticksRemaining);
return tagCompound;
2015-12-27 19:38:12 -05:00
}
@Override
2017-08-15 21:30:48 -07:00
public void onUpdate() {
if (!world.isRemote) {
PlayerEntity player = world.getClosestPlayer(getPos().getX(), getPos().getY(), getPos().getZ(), 10.0D, ItemSigilPhantomBridge.IS_PHANTOM_ACTIVE);
2018-08-18 03:14:41 +02:00
if (player != null && !player.isSneaking())
return;
ticksRemaining--;
}
2015-12-27 19:38:12 -05:00
2017-08-15 21:30:48 -07:00
if (ticksRemaining <= 0) {
2018-08-18 03:14:41 +02:00
world.setBlockToAir(getPos());
world.removeTileEntity(getPos());
2015-12-27 19:38:12 -05:00
}
2018-08-18 03:14:41 +02:00
2015-12-27 19:38:12 -05:00
}
}