diff --git a/src/main/java/vazkii/botania/api/BotaniaAPI.java b/src/main/java/vazkii/botania/api/BotaniaAPI.java index cee71196e..8f8ac7812 100644 --- a/src/main/java/vazkii/botania/api/BotaniaAPI.java +++ b/src/main/java/vazkii/botania/api/BotaniaAPI.java @@ -29,7 +29,6 @@ import net.minecraft.item.Item; import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemArmor.ArmorMaterial; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.fml.common.Loader; @@ -56,8 +55,8 @@ import vazkii.botania.api.wiki.SimpleWikiProvider; import vazkii.botania.api.wiki.WikiHooks; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -97,8 +96,9 @@ public final class BotaniaAPI { public static final Map> paintableBlocks = new LinkedHashMap<>(); public static final Set magnetBlacklist = new LinkedHashSet<>(); public static final Set> gravityRodBlacklist = new LinkedHashSet<>(); - - + + public static final Set gaiaBreakBlacklist = new HashSet<>(); + public static final ArmorMaterial manasteelArmorMaterial = EnumHelper.addArmorMaterial("MANASTEEL", "manasteel", 16, new int[] { 2, 5, 6, 2 }, 18, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0); public static final ToolMaterial manasteelToolMaterial = EnumHelper.addToolMaterial("MANASTEEL", 3, 300, 6.2F, 2F, 20); @@ -243,6 +243,8 @@ public final class BotaniaAPI { registerSemiDisposableBlock("stoneBasalt"); // Vanilla registerSemiDisposableBlock("stoneDiorite"); // Vanilla registerSemiDisposableBlock("stoneGranite"); // Vanilla + + blacklistBlockFromGaiaGuardian(Blocks.BEACON); } /** @@ -667,4 +669,7 @@ public final class BotaniaAPI { return "bm_" + block.getTranslationKey() + "@" + meta; } + public static void blacklistBlockFromGaiaGuardian(Block block) { + gaiaBreakBlacklist.add(block); + } } diff --git a/src/main/java/vazkii/botania/api/package-info.java b/src/main/java/vazkii/botania/api/package-info.java index 5e7cc4872..1d08d4ba2 100644 --- a/src/main/java/vazkii/botania/api/package-info.java +++ b/src/main/java/vazkii/botania/api/package-info.java @@ -1,4 +1,4 @@ -@API(owner = "Botania", apiVersion = "92", provides = "BotaniaAPI") +@API(owner = "Botania", apiVersion = "93", provides = "BotaniaAPI") package vazkii.botania.api; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/vazkii/botania/common/block/BlockPylon.java b/src/main/java/vazkii/botania/common/block/BlockPylon.java index 6ef94e53f..468093352 100644 --- a/src/main/java/vazkii/botania/common/block/BlockPylon.java +++ b/src/main/java/vazkii/botania/common/block/BlockPylon.java @@ -17,7 +17,6 @@ import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; @@ -27,11 +26,11 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.fml.common.Optional; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import thaumcraft.api.crafting.IInfusionStabiliser; +import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.lexicon.ILexiconable; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.state.BotaniaStateProps; @@ -55,6 +54,7 @@ public class BlockPylon extends BlockMod implements ILexiconable, IInfusionStabi setSoundType(SoundType.METAL); setLightLevel(0.5F); setDefaultState(blockState.getBaseState().withProperty(BotaniaStateProps.PYLON_VARIANT, PylonVariant.MANA)); + BotaniaAPI.blacklistBlockFromGaiaGuardian(this); } @Nonnull diff --git a/src/main/java/vazkii/botania/common/core/handler/SleepingHandler.java b/src/main/java/vazkii/botania/common/core/handler/SleepingHandler.java new file mode 100644 index 000000000..1d0baca22 --- /dev/null +++ b/src/main/java/vazkii/botania/common/core/handler/SleepingHandler.java @@ -0,0 +1,25 @@ +package vazkii.botania.common.core.handler; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import vazkii.botania.common.entity.EntityDoppleganger; +import vazkii.botania.common.lib.LibMisc; + +@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID) +public final class SleepingHandler { + + private SleepingHandler() {} + + @SubscribeEvent + public static void trySleep(PlayerSleepInBedEvent event) { + World world = event.getEntityPlayer().world; + for(EntityDoppleganger guardian : world.getEntities(EntityDoppleganger.class, e -> true)) { + if(guardian.getPlayersAround().contains(event.getEntityPlayer())) { + event.setResult(EntityPlayer.SleepResult.NOT_SAFE); + } + } + } +} diff --git a/src/main/java/vazkii/botania/common/entity/EntityDoppleganger.java b/src/main/java/vazkii/botania/common/entity/EntityDoppleganger.java index 23ebf6e59..f70758a6f 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityDoppleganger.java +++ b/src/main/java/vazkii/botania/common/entity/EntityDoppleganger.java @@ -45,6 +45,7 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntityBeacon; import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; @@ -66,6 +67,7 @@ import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.opengl.ARBShaderObjects; +import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.boss.IBotaniaBoss; import vazkii.botania.api.internal.ShaderCallback; import vazkii.botania.api.lexicon.multiblock.Multiblock; @@ -90,8 +92,10 @@ import javax.annotation.Nonnull; import java.awt.Rectangle; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Random; +import java.util.Set; import java.util.UUID; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -99,6 +103,8 @@ import java.util.stream.Collectors; public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IEntityAdditionalSpawnData { public static final float ARENA_RANGE = 12F; + public static final int ARENA_HEIGHT = 5; + private static final int SPAWN_TICKS = 160; private static final float MAX_HP = 320F; @@ -128,8 +134,8 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE }; private static final List CHEATY_BLOCKS = Arrays.asList( - new ResourceLocation("openblocks", "beartrap"), - new ResourceLocation("thaumictinkerer", "magnet") + new ResourceLocation("openblocks", "beartrap"), + new ResourceLocation("thaumictinkerer", "magnet") ); private boolean spawnLandmines = false; @@ -173,43 +179,53 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE } public static boolean spawn(EntityPlayer player, ItemStack stack, World world, BlockPos pos, boolean hard) { - if(world.getTileEntity(pos) instanceof TileEntityBeacon && isTruePlayer(player)) { - if(world.getDifficulty() == EnumDifficulty.PEACEFUL) { + //initial checks + if( + !(world.getTileEntity(pos) instanceof TileEntityBeacon) || + !isTruePlayer(player) || + countGaiaGuardiansAround(world, pos) > 0 + ) + return false; + + //check difficulty + if(world.getDifficulty() == EnumDifficulty.PEACEFUL) { + if(!world.isRemote) + player.sendMessage(new TextComponentTranslation("botaniamisc.peacefulNoob").setStyle(new Style().setColor(TextFormatting.RED))); + return false; + } + + //check pylons + for(BlockPos coords : PYLON_LOCATIONS) { + BlockPos pos_ = pos.add(coords); + + IBlockState state = world.getBlockState(pos_); + if(state.getBlock() != ModBlocks.pylon || state.getValue(BotaniaStateProps.PYLON_VARIANT) != PylonVariant.GAIA) { if(!world.isRemote) - player.sendMessage(new TextComponentTranslation("botaniamisc.peacefulNoob").setStyle(new Style().setColor(TextFormatting.RED))); + player.sendMessage(new TextComponentTranslation("botaniamisc.needsCatalysts").setStyle(new Style().setColor(TextFormatting.RED))); return false; } + } - for(BlockPos coords : PYLON_LOCATIONS) { - BlockPos pos_ = pos.add(coords); + //check arena shape + List invalidArenaBlocks = checkArena(world, pos); + if(!invalidArenaBlocks.isEmpty()) { + if(world.isRemote) { + Botania.proxy.setWispFXDepthTest(false); + for(BlockPos pos_ : invalidArenaBlocks) + Botania.proxy.wispFX(pos_.getX() + 0.5, pos_.getY() + 0.5, pos_.getZ() + 0.5, 1F, 0.2F, 0.2F, 0.5F, 0F, 8); + Botania.proxy.setWispFXDepthTest(true); + } else { + PacketHandler.sendTo((EntityPlayerMP) player, + new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.ARENA_INDICATOR, pos.getX(), pos.getY(), pos.getZ())); - IBlockState state = world.getBlockState(pos_); - Block blockat = state.getBlock(); - if(blockat != ModBlocks.pylon || state.getValue(BotaniaStateProps.PYLON_VARIANT) != PylonVariant.GAIA) { - if(!world.isRemote) - player.sendMessage(new TextComponentTranslation("botaniamisc.needsCatalysts").setStyle(new Style().setColor(TextFormatting.RED))); - return false; - } + player.sendMessage(new TextComponentTranslation("botaniamisc.badArena").setStyle(new Style().setColor(TextFormatting.RED))); } - if(!hasProperArena(world, pos)) { - if(!world.isRemote) { - PacketHandler.sendTo((EntityPlayerMP) player, - new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.ARENA_INDICATOR, pos.getX(), pos.getY(), pos.getZ())); - - player.sendMessage(new TextComponentTranslation("botaniamisc.badArena").setStyle(new Style().setColor(TextFormatting.RED))); - } - - return false; - } - - int guardians = getGaiaGuardiansAround(world, pos); - if(guardians > 0) - return false; - - if(world.isRemote) - return true; + return false; + } + //all checks ok, spawn the boss + if(!world.isRemote) { stack.shrink(1); EntityDoppleganger e = new EntityDoppleganger(world); @@ -220,72 +236,46 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE e.mobSpawnTicks = MOB_SPAWN_TICKS; e.hardMode = hard; - int playerCount = (int) e.getPlayersAround().stream().filter(EntityDoppleganger::isTruePlayer).count(); + int playerCount = e.getPlayersAround().size(); e.playerCount = playerCount; e.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(MAX_HP * playerCount); - if (hard) + if(hard) e.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.ARMOR).setBaseValue(15); e.playSound(SoundEvents.ENTITY_ENDERDRAGON_GROWL, 10F, 0.1F); e.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(e)), null); world.spawnEntity(e); - return true; } - - return false; + + return true; } - private static boolean hasProperArena(World world, BlockPos startPos) { + private static List checkArena(World world, BlockPos beaconPos) { List trippedPositions = new ArrayList<>(); - boolean tripped = false; - - int heightCheck = 3; - int heightMin = 2; int range = (int) Math.ceil(ARENA_RANGE); - for(int i = -range; i < range + 1; i++) - for(int j = -range; j < range + 1; j++) { - if(Math.abs(i) == 4 && Math.abs(j) == 4 || vazkii.botania.common.core.helper.MathHelper.pointDistancePlane(i, j, 0, 0) > ARENA_RANGE) + BlockPos pos; + + for(int x = -range; x <= range; x++) + for(int z = -range; z <= range; z++) { + if(Math.abs(x) == 4 && Math.abs(z) == 4 || vazkii.botania.common.core.helper.MathHelper.pointDistancePlane(x, z, 0, 0) > ARENA_RANGE) continue; // Ignore pylons and out of circle - int air = 0; + for(int y = -1; y <= ARENA_HEIGHT; y++) { + if(x == 0 && y == 0 && z == 0) + continue; //this is the beacon - yCheck: { - BlockPos pos = null; - int trippedColumn = 0; + pos = beaconPos.add(x, y, z); - for(int k = heightCheck + heightMin; k >= -heightCheck; k--) { - pos = startPos.add(i, k, j); - boolean isAir = world.getBlockState(pos).getCollisionBoundingBox(world, pos) == null; - if(isAir) - air++; - else { - if(air >= 2) - break yCheck; - else if(trippedColumn < 2) { - trippedPositions.add(pos); - trippedColumn++; - } - air = 0; - } - } + boolean expectedBlockHere = y == -1; //the floor + boolean isBlockHere = world.getBlockState(pos).getCollisionBoundingBox(world, pos) != null; - if(trippedColumn == 0) + if(expectedBlockHere != isBlockHere) { trippedPositions.add(pos); - - tripped = true; + } } } - if(tripped) { - Botania.proxy.setWispFXDepthTest(false); - for(BlockPos pos : trippedPositions) - Botania.proxy.wispFX(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 1F, 0.2F, 0.2F, 0.5F, 0F, 8); - Botania.proxy.setWispFXDepthTest(true); - - return false; - } - - return true; + return trippedPositions; } @Override @@ -313,35 +303,35 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE } @Override - public void writeEntityToNBT(NBTTagCompound par1nbtTagCompound) { - super.writeEntityToNBT(par1nbtTagCompound); - par1nbtTagCompound.setInteger(TAG_INVUL_TIME, getInvulTime()); - par1nbtTagCompound.setBoolean(TAG_AGGRO, aggro); - par1nbtTagCompound.setInteger(TAG_MOB_SPAWN_TICKS, mobSpawnTicks); + public void writeEntityToNBT(NBTTagCompound cmp) { + super.writeEntityToNBT(cmp); + cmp.setInteger(TAG_INVUL_TIME, getInvulTime()); + cmp.setBoolean(TAG_AGGRO, aggro); + cmp.setInteger(TAG_MOB_SPAWN_TICKS, mobSpawnTicks); - par1nbtTagCompound.setInteger(TAG_SOURCE_X, source.getX()); - par1nbtTagCompound.setInteger(TAG_SOURCE_Y, source.getY()); - par1nbtTagCompound.setInteger(TAG_SOURCE_Z, source.getZ()); + cmp.setInteger(TAG_SOURCE_X, source.getX()); + cmp.setInteger(TAG_SOURCE_Y, source.getY()); + cmp.setInteger(TAG_SOURCE_Z, source.getZ()); - par1nbtTagCompound.setBoolean(TAG_HARD_MODE, hardMode); - par1nbtTagCompound.setInteger(TAG_PLAYER_COUNT, playerCount); + cmp.setBoolean(TAG_HARD_MODE, hardMode); + cmp.setInteger(TAG_PLAYER_COUNT, playerCount); } @Override - public void readEntityFromNBT(NBTTagCompound par1nbtTagCompound) { - super.readEntityFromNBT(par1nbtTagCompound); - setInvulTime(par1nbtTagCompound.getInteger(TAG_INVUL_TIME)); - aggro = par1nbtTagCompound.getBoolean(TAG_AGGRO); - mobSpawnTicks = par1nbtTagCompound.getInteger(TAG_MOB_SPAWN_TICKS); + public void readEntityFromNBT(NBTTagCompound cmp) { + super.readEntityFromNBT(cmp); + setInvulTime(cmp.getInteger(TAG_INVUL_TIME)); + aggro = cmp.getBoolean(TAG_AGGRO); + mobSpawnTicks = cmp.getInteger(TAG_MOB_SPAWN_TICKS); - int x = par1nbtTagCompound.getInteger(TAG_SOURCE_X); - int y = par1nbtTagCompound.getInteger(TAG_SOURCE_Y); - int z = par1nbtTagCompound.getInteger(TAG_SOURCE_Z); + int x = cmp.getInteger(TAG_SOURCE_X); + int y = cmp.getInteger(TAG_SOURCE_Y); + int z = cmp.getInteger(TAG_SOURCE_Z); source = new BlockPos(x, y, z); - hardMode = par1nbtTagCompound.getBoolean(TAG_HARD_MODE); - if(par1nbtTagCompound.hasKey(TAG_PLAYER_COUNT)) - playerCount = par1nbtTagCompound.getInteger(TAG_PLAYER_COUNT); + hardMode = cmp.getBoolean(TAG_HARD_MODE); + if(cmp.hasKey(TAG_PLAYER_COUNT)) + playerCount = cmp.getInteger(TAG_PLAYER_COUNT); else playerCount = 1; if (this.hasCustomName()) { @@ -395,10 +385,10 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE } @Override - protected void damageEntity(@Nonnull DamageSource par1DamageSource, float par2) { - super.damageEntity(par1DamageSource, par2); + protected void damageEntity(@Nonnull DamageSource source, float par2) { + super.damageEntity(source, par2); - Entity attacker = par1DamageSource.getImmediateSource(); + Entity attacker = source.getImmediateSource(); if(attacker != null) { Vector3 thisVector = Vector3.fromEntityCenter(this); Vector3 playerVector = Vector3.fromEntityCenter(attacker); @@ -447,8 +437,7 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE } @Override - protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, @Nonnull DamageSource source) - { + protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, @Nonnull DamageSource source) { // Save true killer, they get extra loot if (wasRecentlyHit && source.getTrueSource() instanceof EntityPlayer) { trueKiller = (EntityPlayer) source.getTrueSource(); @@ -494,12 +483,12 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE super.setDead(); } - private List getPlayersAround() { + public List getPlayersAround() { float range = 15F; - return world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(source.getX() + 0.5 - range, source.getY() + 0.5 - range, source.getZ() + 0.5 - range, source.getX() + 0.5 + range, source.getY() + 0.5 + range, source.getZ() + 0.5 + range)); + return world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(source.getX() + 0.5 - range, source.getY() + 0.5 - range, source.getZ() + 0.5 - range, source.getX() + 0.5 + range, source.getY() + 0.5 + range, source.getZ() + 0.5 + range), player -> isTruePlayer(player) && !player.isSpectator()); } - private static int getGaiaGuardiansAround(World world, BlockPos source) { + private static int countGaiaGuardiansAround(World world, BlockPos source) { float range = 15F; List l = world.getEntitiesWithinAABB(EntityDoppleganger.class, new AxisAlignedBB(source.getX() + 0.5 - range, source.getY() + 0.5 - range, source.getZ() + 0.5 - range, source.getX() + 0.5 + range, source.getY() + 0.5 + range, source.getZ() + 0.5 + range)); return l.size(); @@ -545,20 +534,31 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE } } - private void smashCheatyBlocks() { - int radius = 1; - int posXInt = MathHelper.floor(posX); - int posYInt = MathHelper.floor(posY); - int posZInt = MathHelper.floor(posZ); - for(int i = -radius; i < radius + 1; i++) - for(int j = -radius; j < radius + 1; j++) - for(int k = -radius; k < radius + 1; k++) { - int xp = posXInt + i; - int yp = posYInt + j; - int zp = posZInt + k; - BlockPos posp = new BlockPos(xp, yp, zp); - if(isCheatyBlock(world, posp)) { - world.destroyBlock(posp, true); + private void smashBlocksAround(int centerX, int centerY, int centerZ, int radius) { + for(int dx = -radius; dx <= radius; dx++) + for(int dy = -radius; dy <= radius + 1; dy++) + for(int dz = -radius; dz <= radius; dz++) { + int x = centerX + dx; + int y = centerY + dy; + int z = centerZ + dz; + + BlockPos pos = new BlockPos(x, y, z); + IBlockState state = world.getBlockState(pos); + Block block = state.getBlock(); + + if(state.getBlockHardness(world, pos) == -1) continue; + + if(CHEATY_BLOCKS.contains(block.getRegistryName())) { + world.destroyBlock(pos, true); + } else { + //don't break blacklisted blocks + if(BotaniaAPI.gaiaBreakBlacklist.contains(block)) continue; + //don't break the floor + if(y == source.getY() - 1) continue; + //don't break blocks in pylon columns + if(Math.abs(source.getX() - x) == 4 && Math.abs(source.getZ() - z) == 4) continue; + + world.destroyBlock(pos, true); } } } @@ -646,11 +646,11 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE int invul = getInvulTime(); - if (world.isRemote) { + if(world.isRemote) { particles(); EntityPlayer player = Botania.proxy.getClientPlayer(); if(getPlayersAround().contains(player)) - player.capabilities.isFlying = player.capabilities.isFlying && player.capabilities.isCreativeMode; + player.capabilities.isFlying &= player.capabilities.isCreativeMode; return; } @@ -662,7 +662,7 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE if(world.getDifficulty() == EnumDifficulty.PEACEFUL) setDead(); - smashCheatyBlocks(); + smashBlocksAround(MathHelper.floor(posX), MathHelper.floor(posY), MathHelper.floor(posZ), 1); List players = getPlayersAround(); @@ -677,9 +677,12 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE } } + //also see SleepingHandler + if(player.isPlayerSleeping()) player.wakeUpPlayer(true, true, false); + clearPotions(player); keepInsideArena(player); - player.capabilities.isFlying = player.capabilities.isFlying && player.capabilities.isCreativeMode; + player.capabilities.isFlying &= player.capabilities.isCreativeMode; } } @@ -731,18 +734,14 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE tpDelay--; if(tpDelay == 0 && getHealth() > 0) { - int tries = 0; - while(!teleportRandomly() && tries < 50) - tries++; - if(tries >= 50) - teleportTo(source.getX() + 0.5, source.getY() + 1.6, source.getZ() + 0.5); + teleportRandomly(); if(spawnLandmines) { int count = dying && hardMode ? 7 : 6; for(int i = 0; i < count; i++) { int x = source.getX() - 10 + rand.nextInt(20); + int y = (int) players.get(rand.nextInt(players.size())).posY; int z = source.getZ() - 10 + rand.nextInt(20); - int y = world.getTopSolidOrLiquidBlock(new BlockPos(x, -1, z)).getY(); EntityMagicLandmine landmine = new EntityMagicLandmine(world); landmine.setPosition(x + 0.5, y, z + 0.5); @@ -778,21 +777,18 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE } @Override - public boolean isNonBoss() - { + public boolean isNonBoss() { return false; } @Override - public void addTrackingPlayer(EntityPlayerMP player) - { + public void addTrackingPlayer(EntityPlayerMP player) { super.addTrackingPlayer(player); bossInfo.addPlayer(player); } @Override - public void removeTrackingPlayer(EntityPlayerMP player) - { + public void removeTrackingPlayer(EntityPlayerMP player) { super.removeTrackingPlayer(player); bossInfo.removePlayer(player); } @@ -817,127 +813,73 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss, IE } } - private static boolean isCheatyBlock(World world, BlockPos pos) { - Block block = world.getBlockState(pos).getBlock(); - return CHEATY_BLOCKS.contains(Block.REGISTRY.getNameForObject(block)); - } + private void teleportRandomly() { + //choose a location to teleport to + double oldX = posX, oldY = posY, oldZ = posZ; + double newX, newY, newZ; + int tries = 0; - // [VanillaCopy] EntityEnderman.teleportRandomly, edits noted. - private boolean teleportRandomly() { - double d0 = this.posX + (this.rand.nextDouble() - 0.5D) * 64.0D; - double d1 = this.posY + (double)(this.rand.nextInt(64) - 32); - double d2 = this.posZ + (this.rand.nextDouble() - 0.5D) * 64.0D; - return this.teleportTo(d0, d1, d2); - } + do { + newX = source.getX() + (rand.nextDouble() - .5) * ARENA_RANGE; + newY = source.getY(); + newZ = source.getZ() + (rand.nextDouble() - .5) * ARENA_RANGE; + tries++; + //ensure it's inside the arena ring, and not just its bounding square + } + while(tries < 50 && vazkii.botania.common.core.helper.MathHelper.pointDistanceSpace(newX, newY, newZ, source.getX(), source.getY(), source.getZ()) > 12); - // [VanillaCopy] EntityEnderman.teleportTo, edits noted. - private boolean teleportTo(double x, double y, double z) { - /* Botania - no events - net.minecraftforge.event.entity.living.EnderTeleportEvent event = new net.minecraftforge.event.entity.living.EnderTeleportEvent(this, x, y, z, 0); - if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return false; - boolean flag = this.attemptTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ()); - */ - - boolean flag = this.attemptTeleport(x, y, z); - - if (flag) - { - this.world.playSound((EntityPlayer)null, this.prevPosX, this.prevPosY, this.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, this.getSoundCategory(), 1.0F, 1.0F); - this.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F); + if(tries == 50) { + //failsafe: teleport to the beacon + newX = source.getX() + .5; + newY = source.getY() + 1.6; + newZ = source.getZ() + .5; } - return flag; - } + //teleport there + setPositionAndUpdate(newX, newY, newZ); - // [VanillaCopy] of super, edits noted - @Override - public boolean attemptTeleport(double x, double y, double z) { - double d0 = this.posX; - double d1 = this.posY; - double d2 = this.posZ; - this.posX = x; - this.posY = y; - this.posZ = z; - boolean flag = false; - BlockPos blockpos = new BlockPos(this); - World world = this.world; - Random random = this.getRNG(); + //play sound + world.playSound(null, oldX, oldY, oldZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, this.getSoundCategory(), 1.0F, 1.0F); + this.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F); - if (world.isBlockLoaded(blockpos)) - { - boolean flag1 = false; + Random random = getRNG(); - while (!flag1 && blockpos.getY() > 0) - { - BlockPos blockpos1 = blockpos.down(); - IBlockState iblockstate = world.getBlockState(blockpos1); - - if (iblockstate.getMaterial().blocksMovement()) - { - flag1 = true; - } - else - { - --this.posY; - blockpos = blockpos1; - } - } - - if (flag1) - { - this.setPositionAndUpdate(this.posX, this.posY, this.posZ); - - if (world.getCollisionBoxes(this, this.getEntityBoundingBox()).isEmpty() && !world.containsAnyLiquid(this.getEntityBoundingBox())) - { - flag = true; - } - - // Botania - Prevent out of bounds teleporting - if(vazkii.botania.common.core.helper.MathHelper.pointDistanceSpace(posX, posY, posZ, source.getX(), source.getY(), source.getZ()) > 12) - flag = false; - } + //spawn particles along the path + int particleCount = 128; + for(int i = 0; i < particleCount; ++i) { + double progress = i / (double) (particleCount - 1); + float vx = (random.nextFloat() - 0.5F) * 0.2F; + float vy = (random.nextFloat() - 0.5F) * 0.2F; + float vz = (random.nextFloat() - 0.5F) * 0.2F; + double px = oldX + (newX - oldX) * progress + (random.nextDouble() - 0.5D) * width * 2.0D; + double py = oldY + (newY - oldY) * progress + random.nextDouble() * height; + double pz = oldZ + (newZ - oldZ) * progress + (random.nextDouble() - 0.5D) * width * 2.0D; + world.spawnParticle(EnumParticleTypes.PORTAL, px, py, pz, vx, vy, vz); } - if (!flag) - { - this.setPositionAndUpdate(d0, d1, d2); - return false; - } - else - { - int i = 128; + Vec3d oldPosVec = new Vec3d(oldX, oldY + height / 2, oldZ); + Vec3d newPosVec = new Vec3d(newX, newY + height / 2, newZ); - for (int j = 0; j < 128; ++j) - { - double d6 = (double)j / 127.0D; - float f = (random.nextFloat() - 0.5F) * 0.2F; - float f1 = (random.nextFloat() - 0.5F) * 0.2F; - float f2 = (random.nextFloat() - 0.5F) * 0.2F; - double d3 = d0 + (this.posX - d0) * d6 + (random.nextDouble() - 0.5D) * (double)this.width * 2.0D; - double d4 = d1 + (this.posY - d1) * d6 + random.nextDouble() * (double)this.height; - double d5 = d2 + (this.posZ - d2) * d6 + (random.nextDouble() - 0.5D) * (double)this.width * 2.0D; - world.spawnParticle(EnumParticleTypes.PORTAL, d3, d4, d5, (double)f, (double)f1, (double)f2, new int[0]); + if(oldPosVec.squareDistanceTo(newPosVec) > 1) { + //damage players in the path of the teleport + for(EntityPlayer player : getPlayersAround()) { + RayTraceResult rtr = player.getEntityBoundingBox().grow(0.25).calculateIntercept(oldPosVec, newPosVec); + if(rtr != null) + player.attackEntityFrom(DamageSource.causeMobDamage(this), 6); } - // Botania - invalid/unneeded check - /*if (this instanceof EntityCreature) - { - ((EntityCreature)this).getNavigator().clearPathEntity(); - }*/ + //break blocks in the path of the teleport + int breakSteps = (int) oldPosVec.distanceTo(newPosVec); + if(breakSteps >= 2) { + for(int i = 0; i < breakSteps; i++) { + float progress = i / (float) (breakSteps - 1); + int breakX = MathHelper.floor(oldX + (newX - oldX) * progress); + int breakY = MathHelper.floor(oldY + (newY - oldY) * progress); + int breakZ = MathHelper.floor(oldZ + (newZ - oldZ) * progress); - // Botania - damage any players in our way - Vec3d origPos = new Vec3d(d0, d1 + height / 2, d2); - Vec3d newPos = new Vec3d(posX, posY + height / 2, posZ); - - if(origPos.squareDistanceTo(newPos) > 1) { - for(EntityPlayer player : getPlayersAround()) { - RayTraceResult rtr = player.getEntityBoundingBox().grow(0.25).calculateIntercept(origPos, newPos); - if(rtr != null) - player.attackEntityFrom(DamageSource.causeMobDamage(this), 6); + smashBlocksAround(breakX, breakY, breakZ, 1); } } - - return true; } }