Remove unnecessary tile entity from upper thorn blocks, and reminder to do the same for statue blocks

This commit is contained in:
Electroblob77
2020-06-19 16:37:03 +01:00
parent a87eca3bd8
commit c842fef2f7
4 changed files with 18 additions and 19 deletions
@@ -123,27 +123,25 @@ public class BlockThorns extends BlockBush implements ITileEntityProvider {
@Override @Override
public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity){ public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity){
if(!world.isRemote){ if(applyThornDamage(world, pos, state, entity)){
if(applyThornDamage(world, pos, entity)){ entity.setInWeb(); // Needs to be called client-side for players (and besides, all of this is common code)
entity.setInWeb();
}
} }
} }
private static boolean applyThornDamage(World world, BlockPos pos, Entity target){ private static boolean applyThornDamage(World world, BlockPos pos, IBlockState state, Entity target){
DamageSource source = DamageSource.CACTUS; DamageSource source = DamageSource.CACTUS;
TileEntity tileentity = world.getTileEntity(pos); TileEntity tileentity = world.getTileEntity(state.getValue(HALF) == EnumBlockHalf.UPPER ? pos.down() : pos);
if(tileentity instanceof TileEntityPlayerSaveTimed){ if(tileentity instanceof TileEntityPlayerSaveTimed){
EntityLivingBase caster = ((TileEntityPlayerSaveTimed)tileentity).getCaster(); EntityLivingBase caster = ((TileEntityPlayerSaveTimed)tileentity).getCaster();
if(caster != null && AllyDesignationSystem.isValidTarget(caster, target)){ if(!AllyDesignationSystem.isValidTarget(caster, target)) return false; // Don't attack or slow allies of the caster
if(caster != null){
source = MagicDamage.causeDirectMagicDamage(caster, MagicDamage.DamageType.MAGIC); source = MagicDamage.causeDirectMagicDamage(caster, MagicDamage.DamageType.MAGIC);
}else{
return false; // Don't attack or slow allies of the caster
} }
} }
@@ -159,12 +157,12 @@ public class BlockThorns extends BlockBush implements ITileEntityProvider {
@Override @Override
public TileEntity createNewTileEntity(World world, int metadata){ public TileEntity createNewTileEntity(World world, int metadata){
return new TileEntityPlayerSaveTimed(600); return new TileEntityPlayerSaveTimed();
} }
@Override @Override
public boolean hasTileEntity(IBlockState state){ public boolean hasTileEntity(IBlockState state){
return true; return state.getValue(HALF) == EnumBlockHalf.LOWER;
} }
@Override public boolean isReplaceable(IBlockAccess world, BlockPos pos){ return false; } @Override public boolean isReplaceable(IBlockAccess world, BlockPos pos){ return false; }
@@ -175,7 +173,7 @@ public class BlockThorns extends BlockBush implements ITileEntityProvider {
@SubscribeEvent @SubscribeEvent
public static void onLeftClickBlockEvent(PlayerInteractEvent.LeftClickBlock event){ public static void onLeftClickBlockEvent(PlayerInteractEvent.LeftClickBlock event){
if(!event.getWorld().isRemote && event.getWorld().getBlockState(event.getPos()).getBlock() == WizardryBlocks.thorns){ if(!event.getWorld().isRemote && event.getWorld().getBlockState(event.getPos()).getBlock() == WizardryBlocks.thorns){
applyThornDamage(event.getWorld(), event.getPos(), event.getEntity()); applyThornDamage(event.getWorld(), event.getPos(), event.getWorld().getBlockState(event.getPos()), event.getEntity());
} }
} }
@@ -82,9 +82,9 @@ public class ForestOfThorns extends Spell {
((BlockThorns)WizardryBlocks.thorns).placeAt(world, pos, 3); ((BlockThorns)WizardryBlocks.thorns).placeAt(world, pos, 3);
for(int i=0; i<2; i++){ // for(int i=0; i<2; i++){
TileEntity tileentity = world.getTileEntity(pos.up(i)); TileEntity tileentity = world.getTileEntity(pos);
if(tileentity instanceof TileEntityPlayerSaveTimed){ if(tileentity instanceof TileEntityPlayerSaveTimed){
((TileEntityPlayerSaveTimed)tileentity).setLifetime((int)(getProperty(DURATION).floatValue() ((TileEntityPlayerSaveTimed)tileentity).setLifetime((int)(getProperty(DURATION).floatValue()
@@ -92,9 +92,9 @@ public class ForestOfThorns extends Spell {
if(caster != null){ if(caster != null){
((TileEntityPlayerSaveTimed)tileentity).setCaster(caster); ((TileEntityPlayerSaveTimed)tileentity).setCaster(caster);
} }
((TileEntityPlayerSaveTimed)tileentity).sync(); // ((TileEntityPlayerSaveTimed)tileentity).sync();
} }
} // }
} }
} }
@@ -9,8 +9,8 @@ public class TileEntityPlayerSaveTimed extends TileEntityPlayerSave implements I
public int timer = 0; public int timer = 0;
public int maxTimer; public int maxTimer;
public TileEntityPlayerSaveTimed(int maxTimer){ public TileEntityPlayerSaveTimed(){
this.maxTimer = maxTimer; this.maxTimer = 600;
} }
@Override @Override
@@ -24,6 +24,7 @@ public class TileEntityPlayerSaveTimed extends TileEntityPlayerSave implements I
if(timer % 2 == 0 && world.getBlockState(pos).getValue(BlockThorns.AGE) < BlockThorns.GROWTH_STAGES - 1){ 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, 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);
} }
} }
@@ -46,7 +46,7 @@ public class TileEntityStatue extends TileEntity implements ITickable {
/** /**
* The position within the petrified creature this particular tileentity holds. 1 is at the bottom. * The position within the petrified creature this particular tileentity holds. 1 is at the bottom.
*/ */
public int position = 1; public int position = 1; // TODO: Remove this, there is no need for more than 1 TE per statue
public void setCreatureAndPart(EntityLiving entity, int position, int parts){ public void setCreatureAndPart(EntityLiving entity, int position, int parts){
this.creature = entity; this.creature = entity;