From b8a1e0190b873ea2cf5116ff68892a166e8a03a4 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Tue, 22 Jul 2014 13:53:12 +0100 Subject: [PATCH] Lots of Shard of Laputa fixes. Closes #177, #178, #179, #180, #183. --- .../botania/api/internal/IManaBurst.java | 2 + MODSRC/vazkii/botania/api/package-info.java | 2 +- .../common/entity/EntityManaBurst.java | 42 +++++++++++++++---- .../botania/common/item/ItemLaputaShard.java | 40 +++++++++--------- 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/MODSRC/vazkii/botania/api/internal/IManaBurst.java b/MODSRC/vazkii/botania/api/internal/IManaBurst.java index bf8291e17..c19634508 100644 --- a/MODSRC/vazkii/botania/api/internal/IManaBurst.java +++ b/MODSRC/vazkii/botania/api/internal/IManaBurst.java @@ -56,5 +56,7 @@ public interface IManaBurst { public void setSourceLens(ItemStack lens); public boolean hasAlreadyCollidedAt(int x, int y, int z); + + public int getTicksExisted(); } diff --git a/MODSRC/vazkii/botania/api/package-info.java b/MODSRC/vazkii/botania/api/package-info.java index e6d0f8969..3194a0dd6 100644 --- a/MODSRC/vazkii/botania/api/package-info.java +++ b/MODSRC/vazkii/botania/api/package-info.java @@ -1,4 +1,4 @@ -@API(owner = "Botania", apiVersion = "3", provides = "BotaniaAPI") +@API(owner = "Botania", apiVersion = "4", provides = "BotaniaAPI") package vazkii.botania.api; import cpw.mods.fml.common.API; diff --git a/MODSRC/vazkii/botania/common/entity/EntityManaBurst.java b/MODSRC/vazkii/botania/common/entity/EntityManaBurst.java index 43da106de..1be2daaeb 100644 --- a/MODSRC/vazkii/botania/common/entity/EntityManaBurst.java +++ b/MODSRC/vazkii/botania/common/entity/EntityManaBurst.java @@ -46,7 +46,8 @@ import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.core.helper.Vector3; public class EntityManaBurst extends EntityThrowable implements IManaBurst { - + + private static final String TAG_TICKS_EXISTED = "ticksExisted"; private static final String TAG_COLOR = "color"; private static final String TAG_MANA = "mana"; private static final String TAG_STARTING_MANA = "startingMana"; @@ -56,13 +57,14 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { private static final String TAG_SPREADER_Y = "spreaderY"; private static final String TAG_SPREADER_Z = "spreaderZ"; private static final String TAG_GRAVITY = "gravity"; + private static final String TAG_LENS_STACK = "lensStack"; private static final String TAG_LAST_MOTION_X = "lastMotionX"; private static final String TAG_LAST_MOTION_Y = "lastMotionY"; private static final String TAG_LAST_MOTION_Z = "lastMotionZ"; boolean fake = false; - final int dataWatcherEntries = 10; + final int dataWatcherEntries = 11; final int dataWatcherStart = 32 - dataWatcherEntries; List alreadyCollidedAt = new ArrayList(); @@ -77,7 +79,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { setSize(0F, 0F); for(int i = 0; i < dataWatcherEntries; i++) { int j = dataWatcherStart + i; - if(i == 4 || i == 5 || i == 10 || i == 11 || i == 12) + if(i == 4 || i == 5) dataWatcher.addObject(j, 0F); else if(i == 9) dataWatcher.addObject(j, new ItemStack(Blocks.stone, 0, 0)); @@ -340,8 +342,9 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { @Override public void onUpdate() { + setTicksExisted(getTicksExisted() + 1); superUpdate(); - + if(!fake && !isDead) { ChunkCoordinates coords = getBurstSourceChunkCoordinates(); TileEntity tile = worldObj.getTileEntity(coords.posX, coords.posY, coords.posZ); @@ -393,10 +396,8 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { public TileEntity getCollidedTile(boolean noParticles) { this.noParticles = noParticles; - while(!isDead) { - ++ticksExisted; + while(!isDead) onUpdate(); - } if(fake) incrementFakeParticleTick(); @@ -407,6 +408,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { @Override public void writeEntityToNBT(NBTTagCompound par1nbtTagCompound) { super.writeEntityToNBT(par1nbtTagCompound); + par1nbtTagCompound.setInteger(TAG_TICKS_EXISTED, getTicksExisted()); par1nbtTagCompound.setInteger(TAG_COLOR, getColor()); par1nbtTagCompound.setInteger(TAG_MANA, getMana()); par1nbtTagCompound.setInteger(TAG_STARTING_MANA, getStartingMana()); @@ -414,6 +416,12 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { par1nbtTagCompound.setFloat(TAG_TICK_MANA_LOSS, getManaLossPerTick()); par1nbtTagCompound.setFloat(TAG_GRAVITY, getGravity()); + ItemStack stack = getSourceLens(); + NBTTagCompound lensCmp = new NBTTagCompound(); + if(stack != null) + stack.writeToNBT(lensCmp); + par1nbtTagCompound.setTag(TAG_LENS_STACK, lensCmp); + ChunkCoordinates coords = getBurstSourceChunkCoordinates(); par1nbtTagCompound.setInteger(TAG_SPREADER_X, coords.posX); par1nbtTagCompound.setInteger(TAG_SPREADER_Y, coords.posY); @@ -427,6 +435,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { @Override public void readEntityFromNBT(NBTTagCompound par1nbtTagCompound) { super.readEntityFromNBT(par1nbtTagCompound); + setTicksExisted(par1nbtTagCompound.getInteger(TAG_TICKS_EXISTED)); setColor(par1nbtTagCompound.getInteger(TAG_COLOR)); setMana(par1nbtTagCompound.getInteger(TAG_MANA)); setStartingMana(par1nbtTagCompound.getInteger(TAG_STARTING_MANA)); @@ -434,6 +443,12 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { setManaLossPerTick(par1nbtTagCompound.getFloat(TAG_TICK_MANA_LOSS)); setGravity(par1nbtTagCompound.getFloat(TAG_GRAVITY)); + NBTTagCompound lensCmp = par1nbtTagCompound.getCompoundTag(TAG_LENS_STACK); + ItemStack stack = ItemStack.loadItemStackFromNBT(lensCmp); + if(stack != null) + setSourceLens(stack); + else setSourceLens(new ItemStack(Blocks.stone, 0, 0)); + int x = par1nbtTagCompound.getInteger(TAG_SPREADER_X); int y = par1nbtTagCompound.getInteger(TAG_SPREADER_Y); int z = par1nbtTagCompound.getInteger(TAG_SPREADER_Z); @@ -693,6 +708,15 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { public void setSourceLens(ItemStack lens) { dataWatcher.updateObject(dataWatcherStart + 9, lens == null ? new ItemStack(Blocks.stone, 0, 0) : lens); } + + @Override + public int getTicksExisted() { + return dataWatcher.getWatchableObjectInt(dataWatcherStart + 10); + } + + public void setTicksExisted(int ticks) { + dataWatcher.updateObject(dataWatcherStart + 10, ticks); + } public ILensEffect getLensInstance() { ItemStack lens = getSourceLens(); @@ -727,7 +751,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { ChunkCoordinates coords = getBurstSourceChunkCoordinates(); TileEntity tile = worldObj.getTileEntity(coords.posX, coords.posY, coords.posZ); if(tile != null && tile instanceof TileSpreader) - return getMana() != getStartingMana() && fullManaLastTick || Math.abs(((TileSpreader) tile).burstParticleTick - ticksExisted) < 4; + return getMana() != getStartingMana() && fullManaLastTick || Math.abs(((TileSpreader) tile).burstParticleTick - getTicksExisted()) < 4; return false; } @@ -746,7 +770,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { ChunkCoordinates coords = getBurstSourceChunkCoordinates(); TileEntity tile = worldObj.getTileEntity(coords.posX, coords.posY, coords.posZ); if(tile != null && tile instanceof TileSpreader) - ((TileSpreader) tile).lastBurstDeathTick = ticksExisted; + ((TileSpreader) tile).lastBurstDeathTick = getTicksExisted(); } public static class PositionProperties { diff --git a/MODSRC/vazkii/botania/common/item/ItemLaputaShard.java b/MODSRC/vazkii/botania/common/item/ItemLaputaShard.java index 77a46ae93..2f41b39eb 100644 --- a/MODSRC/vazkii/botania/common/item/ItemLaputaShard.java +++ b/MODSRC/vazkii/botania/common/item/ItemLaputaShard.java @@ -43,7 +43,7 @@ public class ItemLaputaShard extends ItemMod implements ILensEffect { @Override public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { - if(par5 < 160) { + if(par5 < 160 && !par3World.provider.isHellWorld) { par3World.playSound(par4 + 0.5D, par5 + 0.5D, par6 + 0.5D, "mob.zombie.remedy", 1.0F + par3World.rand.nextFloat(), par3World.rand.nextFloat() * 0.7F + 1.3F, false); spawnBurst(par3World, par4, par5, par6); par1ItemStack.stackSize--; @@ -65,7 +65,7 @@ public class ItemLaputaShard extends ItemMod implements ILensEffect { if(MathHelper.pointDistanceSpace(x, y, z, srcx, srcy, srcz) < range) { Block block = world.getBlock(x, y, z); - if(!block.isAir(world, x, y, z) && !block.isReplaceable(world, x, y, z) && !(block instanceof BlockFalling)) { + if(!block.isAir(world, x, y, z) && !block.isReplaceable(world, x, y, z) && !(block instanceof BlockFalling) && block.getBlockHardness(world, x, y, z) != -1) { int id = Block.getIdFromBlock(block); int meta = world.getBlockMetadata(x, y, z); TileEntity tile = world.getTileEntity(x, y, z); @@ -138,36 +138,38 @@ public class ItemLaputaShard extends ItemMod implements ILensEffect { ItemStack lens = burst.getSourceLens(); - if(entity.ticksExisted == spawnTicks) { + if(burst.getTicksExisted() == spawnTicks) { int x = ItemNBTHelper.getInt(lens, TAG_X, 0); int y = ItemNBTHelper.getInt(lens, TAG_Y, -1); int z = ItemNBTHelper.getInt(lens, TAG_Z, 0); if(y != -1) spawnBurst(entity.worldObj, x, y, z); - } else if(entity.ticksExisted == placeTicks) { + } else if(burst.getTicksExisted() == placeTicks) { int x = (int) net.minecraft.util.MathHelper.floor_double(entity.posX); int y = (int) net.minecraft.util.MathHelper.floor_double(entity.posY); int z = (int) net.minecraft.util.MathHelper.floor_double(entity.posZ); - int id = ItemNBTHelper.getInt(lens, TAG_BLOCK, 0); - Block block = Block.getBlockById(id); - int meta = ItemNBTHelper.getInt(lens, TAG_META, 0); + if(entity.worldObj.isAirBlock(x, y, z)) { + int id = ItemNBTHelper.getInt(lens, TAG_BLOCK, 0); + Block block = Block.getBlockById(id); + int meta = ItemNBTHelper.getInt(lens, TAG_META, 0); - TileEntity tile = null; - NBTTagCompound tilecmp = ItemNBTHelper.getCompound(lens, TAG_TILE, false); - if(tilecmp.hasKey("id")) - tile = TileEntity.createAndLoadEntity(tilecmp); + TileEntity tile = null; + NBTTagCompound tilecmp = ItemNBTHelper.getCompound(lens, TAG_TILE, false); + if(tilecmp.hasKey("id")) + tile = TileEntity.createAndLoadEntity(tilecmp); - entity.worldObj.setBlock(x, y, z, block, meta, 1 | 2); - entity.worldObj.playAuxSFX(2001, x, y, z, id + (meta << 12)); - if(tile != null) { - tile.xCoord = x; - tile.yCoord = y; - tile.zCoord = z; - entity.worldObj.setTileEntity(x, y, z, tile); + entity.worldObj.setBlock(x, y, z, block, meta, 1 | 2); + entity.worldObj.playAuxSFX(2001, x, y, z, id + (meta << 12)); + if(tile != null) { + tile.xCoord = x; + tile.yCoord = y; + tile.zCoord = z; + entity.worldObj.setTileEntity(x, y, z, tile); + } } - + entity.setDead(); } }