From dda3151b735477176719382e941bfcf99a9778af Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sun, 17 Jan 2016 17:30:01 -0600 Subject: [PATCH] Fix piston lens not working properly. Serverside some of the other lenses where safe --- .../java/vazkii/botania/common/item/lens/LensDamage.java | 4 +++- .../vazkii/botania/common/item/lens/LensExplosive.java | 4 ++-- .../java/vazkii/botania/common/item/lens/LensFire.java | 4 +++- .../vazkii/botania/common/item/lens/LensFirework.java | 4 ++-- .../vazkii/botania/common/item/lens/LensInfluence.java | 4 ++-- .../java/vazkii/botania/common/item/lens/LensMine.java | 2 +- .../java/vazkii/botania/common/item/lens/LensPaint.java | 7 +++---- .../java/vazkii/botania/common/item/lens/LensPiston.java | 8 ++++---- .../java/vazkii/botania/common/item/lens/LensStorm.java | 4 ++-- .../java/vazkii/botania/common/item/lens/LensWeight.java | 5 ++--- 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/java/vazkii/botania/common/item/lens/LensDamage.java b/src/main/java/vazkii/botania/common/item/lens/LensDamage.java index 56a6f4980..742da7a8f 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensDamage.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensDamage.java @@ -24,6 +24,8 @@ public class LensDamage extends Lens { @Override public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { + if (entity.worldObj.isRemote) + return; AxisAlignedBB axis = new AxisAlignedBB(entity.posX, entity.posY, entity.posZ, entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ).expand(1, 1, 1); List entities = entity.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis); for(EntityLivingBase living : entities) { @@ -34,7 +36,7 @@ public class LensDamage extends Lens { int mana = burst.getMana(); if(mana >= 16) { burst.setMana(mana - 16); - if(!burst.isFake() && !entity.worldObj.isRemote) + if(!burst.isFake()) living.attackEntityFrom(DamageSource.magic, 8); break; } diff --git a/src/main/java/vazkii/botania/common/item/lens/LensExplosive.java b/src/main/java/vazkii/botania/common/item/lens/LensExplosive.java index 4d1073fab..a78e785e8 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensExplosive.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensExplosive.java @@ -21,9 +21,9 @@ public class LensExplosive extends Lens { @Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { - if(!burst.isFake()) { + if(!entity.worldObj.isRemote && !burst.isFake()) { BlockPos coords = burst.getBurstSourceBlockPos(); - if(!entity.worldObj.isRemote && pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !coords.equals(pos.getBlockPos()))) + if(pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !coords.equals(pos.getBlockPos()))) entity.worldObj.createExplosion(entity, entity.posX, entity.posY, entity.posZ, burst.getMana() / 50F, true); } else dead = false; diff --git a/src/main/java/vazkii/botania/common/item/lens/LensFire.java b/src/main/java/vazkii/botania/common/item/lens/LensFire.java index 3bbd70caf..25b1954e1 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensFire.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensFire.java @@ -18,6 +18,7 @@ import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.MovingObjectPosition; import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.api.internal.VanillaPacketDispatcher; import vazkii.botania.common.block.ModBlocks; import vazkii.botania.common.block.tile.TileIncensePlate; @@ -26,7 +27,7 @@ public class LensFire extends Lens { @Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { BlockPos coords = burst.getBurstSourceBlockPos(); - if(pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock) { + if(!entity.worldObj.isRemote && pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock) { EnumFacing dir = pos.sideHit; BlockPos pos_ = pos.getBlockPos().offset(dir); @@ -39,6 +40,7 @@ public class LensFire extends Lens { else if(blockAt == ModBlocks.incensePlate) { TileIncensePlate plate = (TileIncensePlate) entity.worldObj.getTileEntity(pos.getBlockPos()); plate.ignite(); + VanillaPacketDispatcher.dispatchTEToNearbyPlayers(plate); } else if(blockAt_.isAir(entity.worldObj, pos_)) entity.worldObj.setBlockState(pos_, Blocks.fire.getDefaultState()); } diff --git a/src/main/java/vazkii/botania/common/item/lens/LensFirework.java b/src/main/java/vazkii/botania/common/item/lens/LensFirework.java index b70af9f32..85f642b34 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensFirework.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensFirework.java @@ -25,9 +25,9 @@ public class LensFirework extends Lens { @Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { - if(!burst.isFake()) { + if(!entity.worldObj.isRemote && !burst.isFake()) { BlockPos coords = burst.getBurstSourceBlockPos(); - if(!entity.worldObj.isRemote && pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !pos.getBlockPos().equals(coords))) { + if(pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !pos.getBlockPos().equals(coords))) { ItemStack fireworkStack = generateFirework(burst.getColor()); EntityFireworkRocket rocket = new EntityFireworkRocket(entity.worldObj, entity.posX, entity.posY, entity.posZ, fireworkStack); diff --git a/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java b/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java index c2730607c..5d23b7e6f 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java @@ -30,13 +30,13 @@ public class LensInfluence extends Lens { public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { if(!burst.isFake()) { double range = 3.5; - List movables = entity.worldObj.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range)); + List movables = entity.worldObj.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range)); movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityArrow.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityFallingBlock.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); movables.addAll(entity.worldObj.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range), Predicates.instanceOf(IManaBurst.class))); - for(Entity movable : ((List) movables)) { + for(Entity movable : movables) { if(movable == burst) continue; diff --git a/src/main/java/vazkii/botania/common/item/lens/LensMine.java b/src/main/java/vazkii/botania/common/item/lens/LensMine.java index 05da5ad08..97343ee5d 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensMine.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensMine.java @@ -36,7 +36,7 @@ public class LensMine extends Lens { World world = entity.worldObj; BlockPos pos_ = pos.getBlockPos(); - if (pos_ == null) + if (world.isRemote || pos_ == null) return false; Block block = world.getBlockState(pos_).getBlock(); diff --git a/src/main/java/vazkii/botania/common/item/lens/LensPaint.java b/src/main/java/vazkii/botania/common/item/lens/LensPaint.java index 299398df9..4c284ed28 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensPaint.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensPaint.java @@ -32,7 +32,7 @@ public class LensPaint extends Lens { @Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { int storedColor = ItemLens.getStoredColor(stack); - if(!burst.isFake() && storedColor > -1 && storedColor < 17) { + if(!entity.worldObj.isRemote && !burst.isFake() && storedColor > -1 && storedColor < 17) { if(pos.entityHit != null && pos.entityHit instanceof EntitySheep) { int r = 20; EnumDyeColor sheepColor = ((EntitySheep) pos.entityHit).getFleeceColor(); @@ -72,14 +72,13 @@ public class LensPaint extends Lens { IBlockState stateThere = entity.worldObj.getBlockState(coords); if(stateThere.getValue(BotaniaAPI.paintableBlocks.get(block)) != placeColor) { - if(!entity.worldObj.isRemote) - entity.worldObj.setBlockState(coords, stateThere.withProperty(BotaniaAPI.paintableBlocks.get(block), placeColor), 2); + entity.worldObj.setBlockState(coords, stateThere.withProperty(BotaniaAPI.paintableBlocks.get(block), placeColor), 2); int hex = placeColor.getMapColor().colorValue; int r = (hex & 0xFF0000) >> 16; int g = (hex & 0xFF00) >> 8; int b = (hex & 0xFF); for(int i = 0; i < 4; i++) - Botania.proxy.sparkleFX(entity.worldObj, coords.getX() + (float) Math.random(), coords.getY() + (float) Math.random(), coords.getZ() + (float) Math.random(), r / 255F, g / 255F, b / 255F, 0.6F + (float) Math.random() * 0.3F, 5); + Botania.proxy.sparkleFX(entity.worldObj, coords.getX() + (float) Math.random(), coords.getY() + (float) Math.random(), coords.getZ() + (float) Math.random(), r / 255F, g / 255F, b / 255F, 0.6F + (float) Math.random() * 0.3F, 5); // todo 1.8 noop right now due to serversiding } } diff --git a/src/main/java/vazkii/botania/common/item/lens/LensPiston.java b/src/main/java/vazkii/botania/common/item/lens/LensPiston.java index 29f838325..7f7ecf35e 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensPiston.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensPiston.java @@ -24,12 +24,12 @@ public class LensPiston extends Lens { @Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { BlockPos coords = burst.getBurstSourceBlockPos(); - if(pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock && !entity.worldObj.isRemote) { - BlockPos pos_ = pos.getBlockPos().offset(pos.sideHit); + if(!entity.worldObj.isRemote && pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock) { + BlockPos pos_ = pos.getBlockPos().offset(pos.sideHit.getOpposite()); if(entity.worldObj.isAirBlock(pos_) || entity.worldObj.getBlockState(pos_).getBlock().isReplaceable(entity.worldObj, pos_)) { - IBlockState state = entity.worldObj.getBlockState(pos_); - TileEntity tile = entity.worldObj.getTileEntity(pos_); + IBlockState state = entity.worldObj.getBlockState(pos.getBlockPos()); + TileEntity tile = entity.worldObj.getTileEntity(pos.getBlockPos()); if(state.getBlock().getMobilityFlag() == 0 && state.getBlock() != Blocks.obsidian && state.getBlock().getBlockHardness(entity.worldObj, pos_) >= 0 && tile == null) { entity.worldObj.destroyBlock(pos.getBlockPos(), false); diff --git a/src/main/java/vazkii/botania/common/item/lens/LensStorm.java b/src/main/java/vazkii/botania/common/item/lens/LensStorm.java index a821278b6..0b30f2933 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensStorm.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensStorm.java @@ -20,9 +20,9 @@ public class LensStorm extends Lens { @Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { - if(!burst.isFake()) { + if(!entity.worldObj.isRemote && !burst.isFake()) { BlockPos coords = burst.getBurstSourceBlockPos(); - if(!entity.worldObj.isRemote && pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !coords.equals(pos.getBlockPos()))) + if(pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !coords.equals(pos.getBlockPos()))) entity.worldObj.createExplosion(entity, entity.posX, entity.posY, entity.posZ, 5F, true); } else dead = false; diff --git a/src/main/java/vazkii/botania/common/item/lens/LensWeight.java b/src/main/java/vazkii/botania/common/item/lens/LensWeight.java index a544e11ae..5b7b61e04 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensWeight.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensWeight.java @@ -23,7 +23,7 @@ public class LensWeight extends Lens { @Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { - if(!burst.isFake() && pos.getBlockPos() != null) { + if(!entity.worldObj.isRemote && !burst.isFake() && pos.getBlockPos() != null) { int harvestLevel = ConfigHandler.harvestLevelWeight; Block block = entity.worldObj.getBlockState(pos.getBlockPos()).getBlock(); @@ -33,8 +33,7 @@ public class LensWeight extends Lens { if(blockBelow.isAir(entity.worldObj, pos.getBlockPos().down()) && block.getBlockHardness(entity.worldObj, pos.getBlockPos()) != -1 && neededHarvestLevel <= harvestLevel && entity.worldObj.getTileEntity(pos.getBlockPos()) == null && block.canSilkHarvest(entity.worldObj, pos.getBlockPos(), entity.worldObj.getBlockState(pos.getBlockPos()), null)) { EntityFallingBlock falling = new EntityFallingBlock(entity.worldObj, pos.getBlockPos().getX() + 0.5, pos.getBlockPos().getY() + 0.5, pos.getBlockPos().getZ() + 0.5, state); - if(!entity.worldObj.isRemote) - entity.worldObj.spawnEntityInWorld(falling); + entity.worldObj.spawnEntityInWorld(falling); } }