Stop setting the block each tick to make thorns grow and do it properly in the tile entity and getActualState
Also fixes ownerless thorns not dealing damage and removes knockback
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
package electroblob.wizardry.tileentity;
|
||||
|
||||
import electroblob.wizardry.block.BlockThorns;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ITickable;
|
||||
|
||||
public class TileEntityPlayerSaveTimed extends TileEntityPlayerSave implements ITickable {
|
||||
|
||||
public int timer = 0;
|
||||
public int maxTimer;
|
||||
|
||||
public TileEntityPlayerSaveTimed(){
|
||||
this.maxTimer = 600;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
timer++;
|
||||
|
||||
if(timer > maxTimer && !this.world.isRemote){
|
||||
this.world.destroyBlock(pos, false);
|
||||
}
|
||||
|
||||
if(timer % 2 == 0 && world.getBlockState(pos).getValue(BlockThorns.AGE) < BlockThorns.GROWTH_STAGES - 1){
|
||||
world.setBlockState(pos, world.getBlockState(pos).withProperty(BlockThorns.AGE, world.getBlockState(pos).getValue(BlockThorns.AGE) + 1), 2);
|
||||
world.setBlockState(pos.up(), world.getBlockState(pos.up()).withProperty(BlockThorns.AGE, world.getBlockState(pos.up()).getValue(BlockThorns.AGE) + 1), 2);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLifetime(int lifetime){
|
||||
this.maxTimer = lifetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
super.readFromNBT(tagCompound);
|
||||
timer = tagCompound.getInteger("timer");
|
||||
maxTimer = tagCompound.getInteger("maxTimer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setInteger("timer", timer);
|
||||
tagCompound.setInteger("maxTimer", maxTimer);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package electroblob.wizardry.tileentity;
|
||||
|
||||
import electroblob.wizardry.block.BlockThorns;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ITickable;
|
||||
|
||||
public class TileEntityThorns extends TileEntityPlayerSave implements ITickable {
|
||||
|
||||
private int ticksExisted = 0;
|
||||
private int lifetime;
|
||||
private int age;
|
||||
|
||||
public TileEntityThorns(){
|
||||
this.lifetime = 600;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
ticksExisted++;
|
||||
|
||||
if(ticksExisted > lifetime && !this.world.isRemote){
|
||||
this.world.destroyBlock(pos, false);
|
||||
}
|
||||
|
||||
if(ticksExisted % BlockThorns.GROWTH_STAGE_DURATION == 0 && age < BlockThorns.GROWTH_STAGES - 1){
|
||||
age++;
|
||||
sync(); // Update displayed block
|
||||
}
|
||||
}
|
||||
|
||||
public int getAge(){
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setLifetime(int lifetime){
|
||||
this.lifetime = lifetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
super.readFromNBT(tagCompound);
|
||||
ticksExisted = tagCompound.getInteger("timer");
|
||||
lifetime = tagCompound.getInteger("maxTimer"); // Left as maxTimer for backwards compatibility
|
||||
age = tagCompound.getInteger("age");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setInteger("timer", ticksExisted);
|
||||
tagCompound.setInteger("maxTimer", lifetime);
|
||||
tagCompound.setInteger("age", age);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user