/* 34: */ /* 35: */ public boolean onLeftClickEntity( ItemStack stack, EntityPlayer player, Entity entity) /* 36: */ { /* 37: 39 */ if (!entity.worldObj.isRemote) /* 38: */ { /* 39: 40 */ if ((entity instanceof EntityGolemMecha)) { /* 40: 42 */ if ((entity.riddenByEntity instanceof EntityHumanBase)) { /* 41: 43 */ entity = entity.riddenByEntity; /* 42: */ } /* 43: */ } /* 44: 46 */ if ((entity instanceof EntityHumanBase)) /* 45: */ { /* 46: 48 */ int x = MathHelper.floor_double(entity.posX); /* 47: 49 */ int y = MathHelper.floor_double(entity.posY); /* 48: 50 */ int z = MathHelper.floor_double(entity.posZ); /* 49: 51 */ boolean saved = saveToSpawner(x, y, z, (EntityHumanBase) entity); /* 50: 52 */ if (saved) /* 51: */ { /* 52: 53 */ EntityParty p = ((EntityHumanBase) entity).party; /* 53: 54 */ if (p != null) { /* 54: 55 */ for (int i = 0; i < p.getMembersLength(); i++) { /* 55: 56 */ if (p.getMember(i) != null) /* 56: */ { /* 57: 57 */ Entity member = p.getMember(i); /* 58: 58 */ if (member.ridingEntity != null) { /* 59: 59 */ member.ridingEntity.setDead(); /* 60: */ } /* 61: 60 */ member.setDead(); /* 62: */ } /* 63: */ } /* 64: */ } /* 65: 64 */ if (entity.ridingEntity != null) { /* 66: 65 */ entity.ridingEntity.setDead(); /* 67: */ } /* 68: 66 */ entity.setDead(); /* 69: 67 */ return true; /* 70: */ } /* 71: */ } /* 72: */ else /* 73: */ { /* 74: 70 */ int x = MathHelper.floor_double(entity.posX); /* 75: 71 */ int y = MathHelper.floor_double(entity.posY); /* 76: 72 */ int z = MathHelper.floor_double(entity.posZ); /* 77: 73 */ boolean saved = saveEntityToSpawner(x, y, z, entity); /* 78: 74 */ if (saved) /* 79: */ { /* 80: 75 */ entity.setDead(); /* 81: 76 */ return true; /* 82: */ } /* 83: */ } /* 84: */ } /* 85: 80 */ return false; /* 86: */ }
public static StorageChunk cutWorldBB(World worldObj, AxisAlignedBB bb) { StorageChunk chunk = StorageChunk.copyWorldBB(worldObj, bb); for (int x = (int) bb.minX; x <= bb.maxX; x++) { for (int z = (int) bb.minZ; z <= bb.maxZ; z++) { for (int y = (int) bb.minY; y <= bb.maxY; y++) { // Workaround for dupe TileEntity tile = worldObj.getTileEntity(x, y, z); if (tile instanceof IInventory) { IInventory inv = (IInventory) tile; for (int i = 0; i < inv.getSizeInventory(); i++) { inv.setInventorySlotContents(i, null); } } worldObj.setBlock(x, y, z, Blocks.air, 0, 2); } } } // Carpenter's block's dupe for (Object entity : worldObj.getEntitiesWithinAABB(EntityItem.class, bb.expand(5, 5, 5))) { ((Entity) entity).setDead(); } return chunk; }
@Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { EntityPlayer par3EntityPlayer = (EntityPlayer) player; DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet.data)); ItemStack par1ItemStack; try { par1ItemStack = Packet.readItemStack(dis); Entity entityID = par3EntityPlayer.worldObj.getEntityByID(dis.readInt()); if (par1ItemStack.getTagCompound() == null) par1ItemStack.setTagCompound(new NBTTagCompound()); if (par1ItemStack.getTagCompound().hasKey(ModBreeds.tag) && (!par1ItemStack.getTagCompound().getString(ModBreeds.tag).equals("none"))) { par3EntityPlayer.addChatMessage( "Pet trap still has a " + EntityList.getEntityString(entityID) + " inside !"); } else { NBTTagCompound nbt = new NBTTagCompound(); nbt.setString(ModBreeds.tag, EntityList.getEntityString(entityID)); par1ItemStack.setTagCompound(nbt); entityID.setDead(); par3EntityPlayer.setCurrentItemOrArmor(0, par1ItemStack); if (!par3EntityPlayer.worldObj.isRemote) par3EntityPlayer.addChatMessage( "Stored a " + EntityList.getEntityString(entityID) + " in the Animal trap"); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** Will get destroyed next tick. */ public void setDead() { super.setDead(); if (this.angler != null) { this.angler.fishEntity = null; } }
public static boolean check(Entity entity) { if (entity instanceof EntityLiving) { if (!getFlagValueAtLocation( FlagType.ENTITIES, entity.dimension, (int) Math.floor(entity.posX), (int) Math.floor(entity.posY), (int) Math.floor(entity.posZ))) { entity.setDead(); return true; } } for (SegmentEntity segment : segmentsEntity.get(entity.getClass())) { if (!segment.shouldExist(entity)) { entity.setDead(); return true; } } return false; }
@SubscribeEvent public void onEntityHurt(LivingHurtEvent event) { EntityLivingBase entity = event.entityLiving; if (entity instanceof EntityPlayer) { float curMaxHealth = (float) ((EntityPlayer) entity) .getEntityAttribute(SharedMonsterAttributes.maxHealth) .getAttributeValue(); float newMaxHealth = FoodStatsTFC.getMaxHealth((EntityPlayer) entity); float h = ((EntityPlayer) entity).getHealth(); if (newMaxHealth != curMaxHealth) ((EntityPlayer) entity) .getEntityAttribute(SharedMonsterAttributes.maxHealth) .setBaseValue(newMaxHealth); if (newMaxHealth < h) ((EntityPlayer) entity).setHealth(newMaxHealth); } if (event.source == DamageSource.onFire) { event.ammount = 50; } else if (event.source == DamageSource.fall) { float healthMod = TFC_Core.getEntityMaxHealth(entity) / 1000f; event.ammount *= 80 * healthMod; } else if (event.source == DamageSource.drown) { event.ammount = 50; } else if (event.source == DamageSource.lava) { event.ammount = 100; } else if (event.source == DamageSource.inWall) { event.ammount = 100; } else if (event.source == DamageSource.fallingBlock) { event.ammount = 100; } else if (event.source.isExplosion()) { event.ammount *= 30; } else if (event.source == DamageSource.magic && entity.getHealth() > 25) { event.ammount = 25; } else if ("player".equals(event.source.damageType) || "mob".equals(event.source.damageType) || "arrow".equals(event.source.damageType)) { event.ammount = applyArmorCalculations(entity, event.source, event.ammount); if ("arrow".equals(event.source.damageType)) { Entity e = ((EntityDamageSourceIndirect) event.source).getSourceOfDamage(); if (e instanceof EntityJavelin) { ((EntityJavelin) e).setDamageTaken((short) (((EntityJavelin) e).damageTaken + 10)); if (((EntityJavelin) e).damageTaken >= ((EntityJavelin) e).pickupItem.getMaxDamage()) { e.setDead(); } } } } }
// change soup type @Override public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { if (world.isRemote || !this.onFurnace(world, x, y, z) || entity == null) return; TileEntity tile = world.getTileEntity(x, y, z); if (tile == null || !(tile instanceof TileFilledSoupPan)) return; TileFilledSoupPan pan = (TileFilledSoupPan) tile; boolean flag = false; if (entity instanceof EntityItem) { ItemStack input = ((EntityItem) entity).getEntityItem(); IFondueSource recipe = RecipeRegisterManager.fondueRecipe.getType(input); if (recipe != null && recipe.beforeType() == pan.getType() && recipe.matches(input)) { this.setSoupType(world, x, y, z, pan, recipe.afterType()); world.playSoundAtEntity(entity, "random.pop", 0.4F, 1.8F); ItemStack container = null; if (FluidContainerRegistry.isFilledContainer(input)) { container = FluidContainerRegistry.drainFluidContainer(input); } else { container = input.getItem().getContainerItem(input); } if (container != null) { EntityItem cont = new EntityItem(world, x, y + 1.0D, z, container); world.spawnEntityInWorld(cont); } if (input.stackSize > 1) { ((EntityItem) entity).getEntityItem().stackSize--; } else { entity.setDead(); } } } }
/** Will get destroyed next tick. */ public void setDead() { super.setDead(); }
@SuppressWarnings({"unchecked", "unused"}) @Override public void processCommand(ICommandSender sender, String[] params) { if ((params.length > 0) && (params.length <= 7)) { if (params[0].equals("help")) { sender.addChatMessage( new ChatComponentText(Utils.localize("chat.sstow.command.help")) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN))); sender.addChatMessage(new ChatComponentText(Utils.localize("chat.sstow.command.killall"))); sender.addChatMessage(new ChatComponentText(Utils.localize("chat.sstow.command.settier"))); sender.addChatMessage(new ChatComponentText(Utils.localize("chat.sstow.command.addkills"))); sender.addChatMessage( new ChatComponentText(Utils.localize("chat.sstow.command.removekills"))); } else if (params[0].equals("killall")) { int killCounter = 0; for (Entity ent : (List<Entity>) sender.getEntityWorld().loadedEntityList) { if (ent.getEntityData().getBoolean("SSTOW")) { ent.setDead(); killCounter++; } } if (killCounter == 0) { sender.addChatMessage( new ChatComponentText(Utils.localize("chat.sstow.command.notfound")) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); } else { sender.addChatMessage( new ChatComponentText( Utils.localizeFormatted("chat.sstow.command.killed", "" + killCounter)) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN))); } } else if (params[0].equals("settier")) { if (params.length == 2) { int tierAmount = Integer.parseInt(params[1]); int minKills = TierHandler.getMinKills(tierAmount); if (((EntityPlayerMP) sender).getHeldItem() != null && ((EntityPlayerMP) sender).getHeldItem().getItem() == Register.ItemShardSoul) { ItemStack shard = ((EntityPlayerMP) sender).getHeldItem(); for (int i = 1; i <= tierAmount; i++) { Utils.setShardTier(shard, (byte) 1); Utils.setShardKillCount(shard, (short) minKills); } } } else { sender.addChatMessage( new ChatComponentText(Utils.localize("chat.sstow.command.setwrong")) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); } } else if (params[0].equals("addkills")) { int killAmount = 1000; if (params.length >= 2) { killAmount = Integer.parseInt(params[1]); } else { sender.addChatMessage( new ChatComponentText(Utils.localize("chat.sstow.command.addkillwrong")) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); } if (((EntityPlayerMP) sender).getHeldItem() != null && ((EntityPlayerMP) sender).getHeldItem().getItem() == Register.ItemShardSoul) { ItemStack shard = ((EntityPlayerMP) sender).getHeldItem(); for (int i = 1; i <= killAmount; i++) { Utils.increaseShardKillCount(shard, (short) 1); } } } else if (params[0].equals("removekills")) { if (params.length == 2) { int killAmount = Integer.parseInt(params[1]); } else { sender.addChatMessage( new ChatComponentText(Utils.localize("chat.sstow.command.remkillwrong")) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); } } else if (params[0].equals("xp")) { int xp = 0; if (((EntityPlayerMP) sender).experienceTotal > 0) { xp = ((EntityPlayerMP) sender).experienceTotal; sender.addChatMessage( new ChatComponentText(EnumChatFormatting.GREEN + "You have " + xp + " of xp")); } else { sender.addChatMessage( new ChatComponentText(EnumChatFormatting.RED + "You do not have any xp")); } } else { sender.addChatMessage( new ChatComponentText(Utils.localize("chat.sstow.command.wrongcommand")) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); } } }
@Override protected void onDeathUpdate() { ++this.deathTime; this.hurtResistantTime = 0; this.hurtTime = 0; if (this.deathTime >= 200) { this.deathTime = 1; int i; if (!this.worldObj.isRemote && this.recentlyHit > 0) { i = this.getExperiencePoints(this.attackingPlayer); while (i > 0) { int j = EntityXPOrb.getXPSplit(i); i -= j; this.worldObj.spawnEntityInWorld( new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j)); } } this.setDead(); for (int ji = 0; ji < 20; ++ji) { this.worldObj.spawnParticle( EnumParticleTypes.EXPLOSION_HUGE, this.posX + this.rand.nextFloat() * this.width * 2.0F - this.width, this.posY + this.rand.nextFloat() * this.height * 2.0F, this.posZ + this.rand.nextFloat() * this.width * 2.0F - this.width, 0.1, 0.1, 0.1); } if (!this.worldObj.isRemote) { List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.getEntityBoundingBox().expand(16.0, 16.0, 16.0)); for (Entity e : list) { if (e instanceof EntityLivingBase && ((EntityLivingBase) e).getCreatureAttribute() == TragicEntities.Synapse) { e.setDead(); } } if (TragicConfig.getBoolean("overlordTransformation")) { EntityOverlordCombat combat = new EntityOverlordCombat(this.worldObj); combat.setPosition(this.posX, this.posY, this.posZ); combat.setTransforming(); this.worldObj.spawnEntityInWorld(combat); } } } if (!this.worldObj.isRemote) for (EntitySeeker sk : this.seekers) sk.setDead(); for (int j = 0; j < 40; ++j) { this.worldObj.spawnParticle( EnumParticleTypes.REDSTONE, this.posX + this.rand.nextFloat() * this.width * 5.0F - this.width, this.posY + this.rand.nextFloat() * this.height * 2.0F, this.posZ + this.rand.nextFloat() * this.width * 5.0F - this.width, 0, 0, 0); } for (int ji = 0; ji < 40; ++ji) { this.worldObj.spawnParticle( EnumParticleTypes.REDSTONE, this.posX + this.rand.nextFloat() * this.width * 5.0F - this.width, this.posY + this.rand.nextFloat() * this.height * 2.0F, this.posZ + this.rand.nextFloat() * this.width * 5.0F - this.width, 0.1, 0.1, 0.1); } }
@Override public void removeEntity(Entity entity) { net.minecraft.entity.Entity wrapper = entity.get(MCEntityTransform.class).wrapper; wrapper.setDead(); world().removeEntity(wrapper); }
@Override public void updateWeather() { super.updateWeather(); if (!this.worldObj.isRemote) { if (this.dataNotLoaded) { this.savefile = OrbitSpinSaveData.initWorldData(this.worldObj); this.readFromNBT(this.savefile.datacompound); if (ConfigManagerCore.enableDebug) System.out.println( "Loading data from save: " + this.savefile.datacompound.getFloat("omegaSky")); this.dataNotLoaded = false; } if (this.doSpinning) { boolean updateNeeded = true; if (this.angularVelocityTarget < this.angularVelocityRadians) { float newAngle = this.angularVelocityRadians - this.angularVelocityAccel; if (newAngle < this.angularVelocityTarget) { newAngle = this.angularVelocityTarget; } this.setSpinRate(newAngle); this.thrustersFiring = true; } else if (this.angularVelocityTarget > this.angularVelocityRadians) { float newAngle = this.angularVelocityRadians + this.angularVelocityAccel; if (newAngle > this.angularVelocityTarget) { newAngle = this.angularVelocityTarget; } this.setSpinRate(newAngle); this.thrustersFiring = true; } else if (this.thrustersFiring) { this.thrustersFiring = false; } else { updateNeeded = false; } if (updateNeeded) { this.writeToNBT(this.savefile.datacompound); this.savefile.markDirty(); List<Object> objList = new ArrayList<Object>(); objList.add(Float.valueOf(this.angularVelocityRadians)); objList.add(Boolean.valueOf(this.thrustersFiring)); GalacticraftCore.packetPipeline.sendToDimension( new PacketSimple(EnumSimplePacket.C_UPDATE_STATION_SPIN, objList), this.spaceStationDimensionID); } // Update entity positions if in freefall this.loadedEntities.clear(); this.loadedEntities.addAll(this.worldObj.loadedEntityList); for (Entity e : this.loadedEntities) { if ((e instanceof EntityItem || e instanceof EntityLivingBase && !(e instanceof EntityPlayer) || e instanceof EntityTNTPrimed || e instanceof EntityFallingBlock) && !e.onGround) { boolean freefall = true; if (e.boundingBox.maxX >= this.ssBoundsMinX && e.boundingBox.minX <= this.ssBoundsMaxX && e.boundingBox.maxY >= this.ssBoundsMinY && e.boundingBox.minY <= this.ssBoundsMaxY && e.boundingBox.maxZ >= this.ssBoundsMinZ && e.boundingBox.minZ <= this.ssBoundsMaxZ) { // Entity is somewhere within the space station boundaries // Check if the entity's bounding box is in the same block coordinates as any // non-vacuum block (including torches etc) // If so, it's assumed the entity has something close enough to catch onto, so is not // in freefall // Note: breatheable air here means the entity is definitely not in freefall int xmx = MathHelper.floor_double(e.boundingBox.maxX + 0.2D); int ym = MathHelper.floor_double(e.boundingBox.minY - 0.1D); int yy = MathHelper.floor_double(e.boundingBox.maxY + 0.1D); int zm = MathHelper.floor_double(e.boundingBox.minZ - 0.2D); int zz = MathHelper.floor_double(e.boundingBox.maxZ + 0.2D); BLOCKCHECK: for (int x = MathHelper.floor_double(e.boundingBox.minX - 0.2D); x <= xmx; x++) { for (int y = ym; y <= yy; y++) { for (int z = zm; z <= zz; z++) { if (this.worldObj.blockExists(x, y, z) && this.worldObj.getBlock(x, y, z) != Blocks.air) { freefall = false; break BLOCKCHECK; } } } } } if (freefall) { // Do the rotation if (this.angularVelocityRadians != 0F) { float angle; final double xx = e.posX - this.spinCentreX; final double zz = e.posZ - this.spinCentreZ; double arc = Math.sqrt(xx * xx + zz * zz); if (xx == 0D) { angle = zz > 0 ? 3.141592536F / 2 : -3.141592536F / 2; } else { angle = (float) Math.atan(zz / xx); } if (xx < 0D) { angle += 3.141592536F; } angle += this.angularVelocityRadians / 3F; arc = arc * this.angularVelocityRadians; final double offsetX = -arc * MathHelper.sin(angle); final double offsetZ = arc * MathHelper.cos(angle); e.posX += offsetX; e.posZ += offsetZ; e.lastTickPosX += offsetX; e.lastTickPosZ += offsetZ; // Rotated into an unloaded chunk (probably also drifted out to there): byebye if (!this.worldObj.blockExists( MathHelper.floor_double(e.posX), 64, MathHelper.floor_double(e.posZ))) { e.setDead(); } e.boundingBox.offset(offsetX, 0.0D, offsetZ); // TODO check for block collisions here - if so move the entity appropriately and // apply fall damage // Moving the entity = slide along / down e.rotationYaw += this.skyAngularVelocity; while (e.rotationYaw > 360F) { e.rotationYaw -= 360F; } } // Undo deceleration if (e instanceof EntityLivingBase) { e.motionX /= 0.91F; e.motionZ /= 0.91F; if (e instanceof EntityFlying) { e.motionY /= 0.91F; } else if (e instanceof EntityFallingBlock) { e.motionY /= 0.9800000190734863D; // e.motionY += 0.03999999910593033D; // e.posY += 0.03999999910593033D; // e.lastTickPosY += 0.03999999910593033D; } else { e.motionY /= 0.9800000190734863D; } } else { e.motionX /= 0.9800000190734863D; e.motionY /= 0.9800000190734863D; e.motionZ /= 0.9800000190734863D; } } } } } } }
/** Will get destroyed next tick. */ public void setDead() { blast(); super.setDead(); shootingEntity = null; }
/* * Tick毎に呼ばれる更新処理。 * 速度の更新、衝突判定などをここで行う。 */ @Override public void onUpdate() { super.onUpdate(); livingTimeCount++; // その1、爆発処理 byte exp = this.isExploded(); if (exp == 1) { this.setDead(); } else if (exp > 1) { AMTLogger.debugInfo("current explode int :" + exp); this.worldObj.spawnParticle( "hugeexplosion", this.posX, this.posY + 1.0D, this.posZ, this.motionX, this.motionY, this.motionZ); exp--; this.setTimeCount(exp); } // その2、アクティブか否か if (livingTimeCount > 3 && !this.active) { this.active = true; this.setActive((byte) 1); this.playSound("defeatedcrow:knock", 0.5F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); } boolean explode = false; // 以降、アクティブか否かで動作が変わる。 if (this.active) { double dx = -(double) (MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI)); double dz = -(double) (MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI)); for (int i = 0; i < 4; ++i) { this.worldObj.spawnParticle( "crit", this.posX + dx, this.posY, this.posZ + dz, -this.motionX, -this.motionY + 0.2D, -this.motionZ); } } // 直前のパラメータと新パラメータを一致させているところ。 // また、速度に応じてエンティティの向きを調整し、常に進行方向に前面が向くようにしている。 if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI); } // 激突したブロックを確認している Block i = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile); boolean air = this.worldObj.isAirBlock(xTile, yTile, zTile); // 空気じゃないブロックに当たった&ブロック貫通エンティティでない時 if (i != null && i.getMaterial() != Material.air) { i.setBlockBoundsBasedOnState(this.worldObj, this.xTile, this.yTile, this.zTile); AxisAlignedBB axisalignedbb = i.getCollisionBoundingBoxFromPool(this.worldObj, this.xTile, this.yTile, this.zTile); // 当たり判定に接触しているかどうか if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) { this.inGround = true; } } // 空気じゃないブロックに当たった if (this.inGround) { Block j = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile); int k = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile); /* * 前のTickに確認した埋まりブロックのIDとメタを照合している。違ったら埋まり状態を解除、一致したら埋まり状態を継続。 * /* 埋まり状態2tick継続でこのエンティティを消す */ if (j == this.inTile && k == this.inData) { ++this.ticksInGround; // ブロック貫通の場合、20tick(1秒間)はブロック中にあっても消えないようになる。 int limit = 2; if (this.ticksInGround > limit) { explode = true; } } else // 埋まり状態の解除処理 { this.inGround = false; this.motionX *= this.rand.nextFloat() * 0.1F; this.motionY *= this.rand.nextFloat() * 0.1F; this.motionZ *= this.rand.nextFloat() * 0.1F; this.ticksInGround = 0; this.ticksInAir = 0; } } else // 埋まってない時。速度の更新。 { ++this.ticksInAir; // ブロックとの衝突判定 Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ); Vec3 vec31 = Vec3.createVectorHelper( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition movingobjectposition = this.worldObj.func_147447_a(vec3, vec31, false, true, false); vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ); vec31 = Vec3.createVectorHelper( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); // ブロックに当たった if (movingobjectposition != null) { vec31 = Vec3.createVectorHelper( movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } // Entityとの衝突判定。 List list = this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.boundingBox .addCoord(this.motionX, this.motionY, this.motionZ) .expand(1.0D, 1.0D, 1.0D)); double d0 = 0.0D; int l; float f1; MovingObjectPosition entityTarget = null; // 1ブロック分の範囲内にいるエンティティ全てに対して繰り返す for (l = 0; l < list.size(); ++l) { Entity entity1 = (Entity) list.get(l); Entity entity = null; // ターゲットの場合 if (entity1 instanceof EntityLivingBase || entity1 instanceof EntityDragonPart) { f1 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f1, f1, f1); MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3, vec31); if (movingobjectposition1 != null) { double d1 = vec3.distanceTo(movingobjectposition1.hitVec); if (d1 < d0 || d0 == 0.0D) { // arrowと異なり、あたったEntityすべてをリストに入れる entityTarget = new MovingObjectPosition(entity1); d0 = d1; break; } } } } /* * 当たったエンティティそれそれについての判定部分。 * ここで特定の種類のエンティティに当たらないようにできる。 */ boolean canAttack = false; if (entityTarget != null) { Entity target = entityTarget.entityHit; if (target instanceof EntityPlayer) { // プレイヤーに当たった時 EntityPlayer entityplayer = (EntityPlayer) target; if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) { // PvPが許可されていないと当たらない canAttack = false; } else if (entityplayer == this.shootingEntity) { // 対象が撃った本人の場合も当たらない canAttack = false; } else if (DCsConfig.PvPProhibitionMode && entityplayer instanceof EntityPlayer) { canAttack = false; } } else if (target instanceof EntityTameable || target instanceof EntityHorse) { // 事故防止の為、EntityTameable(犬や猫などのペット)、馬にも当たらないようにする canAttack = false; } else { canAttack = true; } } float f2; float f3; // 当たったあとの処理 // まずはリストから if (canAttack) { Entity target = entityTarget.entityHit; int i1 = MathHelper.ceiling_double_int(1.0D * this.damage); // 0~2程度の乱数値を上乗せ i1 += this.rand.nextInt(3); DamageSource damagesource = null; // 別メソッドでダメージソースを確認 damagesource = this.thisDamageSource(this.shootingEntity); // バニラ矢と同様、このエンティティが燃えているなら対象に着火することも出来る if (this.isBurning() && !(target instanceof EntityEnderman)) { target.setFire(5); } else if (target instanceof IProjectile) { // 対象が矢などの飛翔Entityの場合、打ち消すことが出来る target.setDead(); } else { // ダメージを与える処理を呼ぶ if (target.attackEntityFrom(damagesource, i1)) { // ダメージを与えることに成功したら以下の処理を行う if (target instanceof EntityLivingBase) { EntityLivingBase entitylivingbase = (EntityLivingBase) target; // ノックバック if (this.knockbackStrength > 0) { f3 = MathHelper.sqrt_double( this.motionX * this.motionX + this.motionZ * this.motionZ); if (f3 > 0.0F) { // Y方向に大きめに打ち上げる target.addVelocity( this.motionX * this.knockbackStrength * 0.2000000238418579D / f3, 0.3D, this.motionZ * this.knockbackStrength * 0.2000000238418579D / f3); } } // 無敵時間はなし target.hurtResistantTime = 0; // マルチプレイ時に、両者がプレイヤーだった時のパケット送信処理 if (this.shootingEntity != null && target != this.shootingEntity && target instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP) { ((EntityPlayerMP) this.shootingEntity) .playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F)); } } // ここでヒット時の効果音がなる this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); // 当たったあと、弾を消去する。エンティティ貫通がONの弾種はそのまま残す。 explode = true; } } } if (movingobjectposition != null) // blockのみ { this.xTile = movingobjectposition.blockX; this.yTile = movingobjectposition.blockY; this.zTile = movingobjectposition.blockZ; this.inTile = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile); this.inData = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile); this.motionX = ((float) (movingobjectposition.hitVec.xCoord - this.posX)); this.motionY = ((float) (movingobjectposition.hitVec.yCoord - this.posY)); this.motionZ = ((float) (movingobjectposition.hitVec.zCoord - this.posZ)); f2 = MathHelper.sqrt_double( this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); this.posX -= this.motionX / f2 * 0.05000000074505806D; this.posY -= this.motionY / f2 * 0.05000000074505806D; this.posZ -= this.motionZ / f2 * 0.05000000074505806D; this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); this.inGround = true; if (this.inTile != null) { // Block側に衝突を伝える this.inTile.onEntityCollidedWithBlock( this.worldObj, this.xTile, this.yTile, this.zTile, this); } } } // さいごに爆発処理 int live = (targetEntity != null && targetEntity.isEntityAlive()) ? 10 : 600; if (explode || this.livingTimeCount > live) { if (this.isExploded() == 0) { AMTLogger.debugInfo("explosion"); this.setExplosion(); if (!DCsConfig.disableMissileExplosion && !worldObj.isRemote) { float f = 5.0F; CustomExplosion explosion = new CustomExplosion( worldObj, this, shootingEntity, this.posX, this.posY, this.posZ, f, CustomExplosion.Type.Anchor, true); explosion.doExplosion(); } } } // 追尾 if (active) { if (targetEntity != null && targetEntity.isEntityAlive()) { double dx = targetEntity.posX - this.posX; double dy = targetEntity.boundingBox.minY + (targetEntity.height / 2.0D) - this.posY; double dz = targetEntity.posZ - this.posZ; double d3 = MathHelper.sqrt_double(dx * dx + dz * dz); if (d3 >= 1.0E-7D) { float f4 = (float) d3 * 0.2F; double dy2 = dy + f4; float ff = MathHelper.sqrt_double(dx * dx + dy2 * dy2 + dz * dz); dx /= ff; dy /= ff; dz /= ff; this.motionX = (this.motionX + dx) / 2; this.motionY = (this.motionY + dy) / 2; this.motionZ = (this.motionZ + dz) / 2; this.motionX *= 1.25D; this.motionY *= 1.25D; this.motionZ *= 1.25D; } } } // 直前のパラメータと新パラメータを一致させているところ。 // また、速度に応じてエンティティの向きを調整し、常に進行方向に前面が向くようにしている。 if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI); } // 改めてポジションに速度を加算。向きも更新。 this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); this.rotationPitch = (float) (Math.atan2(this.motionY, f2) * 180.0D / Math.PI); while (this.rotationPitch - this.prevRotationPitch < -180.0F) { this.prevRotationPitch -= 360.0F; } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; // 水中に有る if (this.isInWater()) { // 泡パーティクルが出る for (int j1 = 0; j1 < 4; ++j1) { float f3 = 0.25F; this.worldObj.spawnParticle( "bubble", this.posX - this.motionX * f3, this.posY - this.motionY * f3, this.posZ - this.motionZ * f3, this.motionX, this.motionY, this.motionZ); } } this.setPosition(this.posX, this.posY, this.posZ); this.func_145775_I(); }
@SuppressWarnings("unchecked") @Override public void update() { super.update(); if (this.roomCoords == null) { return; } if (!this.worldObj.isRemote) { if (this.lastKillTime > 0 && MinecraftServer.getCurrentTimeMillis() - lastKillTime > 900000) // 15 minutes { this.lastKillTime = 0; this.isBossDefeated = false; } final Vector3 thisVec = new Vector3(this); final List<E> l = this.worldObj.getEntitiesWithinAABB( bossClass, AxisAlignedBB.fromBounds( thisVec.x - 15, thisVec.y - 15, thisVec.z - 15, thisVec.x + 15, thisVec.y + 15, thisVec.z + 15)); for (final Entity e : l) { if (!e.isDead) { this.boss = (IBoss) e; this.boss.setRoom(this.roomCoords, this.roomSize); this.spawned = true; this.isBossDefeated = false; } } List<EntityMob> entitiesWithin = this.worldObj.getEntitiesWithinAABB( EntityMob.class, AxisAlignedBB.fromBounds( this.roomCoords.intX() - 3, this.roomCoords.intY() - 3, this.roomCoords.intZ() - 3, this.roomCoords.intX() + this.roomSize.intX() + 3, this.roomCoords.intY() + this.roomSize.intY() + 3, this.roomCoords.intZ() + this.roomSize.intZ() + 3)); for (Entity mob : entitiesWithin) { if (this.getDisabledCreatures().contains(mob.getClass())) { mob.setDead(); } } List<EntityPlayer> playersWithin = this.worldObj.getEntitiesWithinAABB( EntityPlayer.class, AxisAlignedBB.fromBounds( this.roomCoords.intX(), this.roomCoords.intY(), this.roomCoords.intZ(), this.roomCoords.intX() + this.roomSize.intX(), this.roomCoords.intY() + this.roomSize.intY(), this.roomCoords.intZ() + this.roomSize.intZ())); if (this.boss == null && !this.isBossDefeated && !playersWithin.isEmpty()) { try { Constructor<?> c = this.bossClass.getConstructor(new Class[] {World.class}); this.boss = (IBoss) c.newInstance(new Object[] {this.worldObj}); ((Entity) this.boss) .setPosition( this.getPos().getX() + 0.5, this.getPos().getY() + 1.0, this.getPos().getZ() + 0.5); this.boss.setRoom(this.roomCoords, this.roomSize); } catch (Exception e) { e.printStackTrace(); } } if (this.playerCheated) { if (!playersWithin.isEmpty()) { this.isBossDefeated = false; this.spawned = false; this.lastPlayerInRange = false; this.playerCheated = false; } } else if (playersWithin.size() == 0) { this.spawned = false; this.lastPlayerInRange = false; this.playerCheated = false; } this.playerInRange = !playersWithin.isEmpty(); if (this.playerInRange && !this.lastPlayerInRange) { if (this.boss != null && !this.spawned) { if (this.boss instanceof EntityLiving) { EntityLiving bossLiving = (EntityLiving) this.boss; bossLiving.onInitialSpawn( this.worldObj.getDifficultyForLocation(new BlockPos(bossLiving)), null); this.worldObj.spawnEntityInWorld(bossLiving); this.playSpawnSound(bossLiving); this.spawned = true; this.boss.onBossSpawned(this); this.boss.setRoom(this.roomCoords, this.roomSize); } } } if (this.boss != null && ((EntityLiving) this.boss).isDead) { this.isBossDefeated = false; this.spawned = false; this.lastPlayerInRange = false; this.playerCheated = false; this.boss = null; } this.lastPlayerInRange = this.playerInRange; } }
@Override public void setDead() { super.setDead(); this.cleanUp(); }