/** * Returns whether or not the specified creature type can spawn at the specified location. */ public static boolean canCreatureTypeSpawnAtLocation(EnumCreatureType creatureType, World world, BlockPos pos) { Block block = world.getBlockState(pos).getBlock(); Block belowblock = world.getBlockState(pos.down(1)).getBlock(); Block aboveblock = world.getBlockState(pos.up(1)).getBlock(); if (creatureType.getCreatureClass() == EntityWaterMob.class) { return block.getMaterial().isLiquid() && belowblock.getMaterial().isLiquid() && !aboveblock.isNormalCube(); } boolean spawnBlock = block != null && canCreatureSpawn(belowblock, world, pos.down(1), SpawnPlacementType.ON_GROUND); //System.out.println("tests: " + spawnBlock); return spawnBlock && block != Blocks.bedrock && !block.isNormalCube() && !block.getMaterial().isLiquid() && !aboveblock.isNormalCube(); }
@Override protected boolean matches(EntityLivingBase entity) { if (type == BOSS) return !entity.isNonBoss(); else if (!entity.isNonBoss()) return false; switch (type) { case ANIMAL: return entity instanceof EntityAnimal; case MONSTER: return entity instanceof IMob; case TAMEABLE: return entity instanceof IEntityOwnable; case PLAYER: return entity instanceof EntityPlayer; case WATER: return entity instanceof EntityWaterMob || entity instanceof EntityGuardian; case NPC: return entity instanceof INpc; case GOLEM: return entity instanceof EntityGolem; default: return false; } }
private static EnumCreatureType getCreatureType(EntityLiving entity) { Class<? extends EntityLiving> entityClass = entity.getClass(); if (IMob.class.isAssignableFrom(entityClass)) { return EnumCreatureType.MONSTER; } else if (EntityAnimal.class.isAssignableFrom(entityClass)) { return EnumCreatureType.CREATURE; } else if (EntityAmbientCreature.class.isAssignableFrom(entityClass)) { return EnumCreatureType.AMBIENT; } else if (EntityWaterMob.class.isAssignableFrom(entityClass)) { return EnumCreatureType.WATER_CREATURE; } else { return null; } }
/** * Will update the entity in the world if the chunk the entity is in is currently loaded or its forced to update. * Args: entity, forceUpdate */ public void updateEntityWithOptionalForce(Entity entityIn, boolean forceUpdate) { if (!this.canSpawnAnimals() && (entityIn instanceof EntityAnimal || entityIn instanceof EntityWaterMob)) { entityIn.setDead(); } if (!this.canSpawnNPCs() && entityIn instanceof INpc) { entityIn.setDead(); } super.updateEntityWithOptionalForce(entityIn, forceUpdate); }
public boolean instanceOf(EntityType e) { // Generic types and players if (e.equals(EntityType.ENTITY_PLAYER_SP)) { return entity instanceof EntityPlayerSP; } else if (e.equals(EntityType.ENTITY_PLAYER)) { return entity instanceof EntityPlayer; } else if (e.equals(EntityType.ENTITY_LIVING_BASE)) { return entity instanceof EntityLivingBase; } else if (e.equals(EntityType.ENTITY_LIVING)) { return entity instanceof EntityLiving; } // Mobs if (e.equals(EntityType.ENTITY_WOLF)) { return entity instanceof EntityWolf; } else if (e.equals(EntityType.Entity_Ageable)) { return entity instanceof EntityAgeable; } else if (e.equals(EntityType.EntityAmbientCreature)) { return entity instanceof EntityAmbientCreature; } else if (e.equals(EntityType.EntityWaterMob)) { return entity instanceof EntityWaterMob; } else if (e.equals(EntityType.EntityMob)) { return entity instanceof EntityMob; } else if (e.equals(EntityType.EntitySlime)) { return entity instanceof EntitySlime; } else if (e.equals(EntityType.EntityFlying)) { return entity instanceof EntityFlying; } else if (e.equals(EntityType.EntityGolem)) { return entity instanceof EntityGolem; } else if (e.equals(EntityType.ENTITY_SPIDER)) { return entity instanceof EntitySpider; } else if (e.equals(EntityType.ENTITY_SPIDER)) { return entity instanceof EntitySpider; } else if (e.equals(EntityType.ENTITY_ZOMBIE_PIGMAN)) { return entity instanceof EntityZombie; } else if (e.equals(EntityType.ENTITY_ENDERMAN)) { return entity instanceof EntityEnderman; } return false; }
/** * Updates the entity in the world if the chunk the entity is in is currently loaded or its forced to update. */ public void updateEntityWithOptionalForce(Entity entityIn, boolean forceUpdate) { if (!this.canSpawnAnimals() && (entityIn instanceof EntityAnimal || entityIn instanceof EntityWaterMob)) { entityIn.setDead(); } if (!this.canSpawnNPCs() && entityIn instanceof INpc) { entityIn.setDead(); } super.updateEntityWithOptionalForce(entityIn, forceUpdate); }
/** * Will update the entity in the world if the chunk the entity is in is * currently loaded or its forced to update. Args: entity, forceUpdate */ public void updateEntityWithOptionalForce(Entity entity, boolean forceUpdate) { if (!this.mcServer.getCanSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterMob)) { entity.setDead(); } if (!this.mcServer.getCanSpawnNPCs() && entity instanceof INpc) { entity.setDead(); } super.updateEntityWithOptionalForce(entity, forceUpdate); }
/** * Will update the entity in the world if the chunk the entity is in is currently loaded or its forced to update. * Args: entity, forceUpdate */ public void updateEntityWithOptionalForce(Entity par1Entity, boolean par2) { if (!this.mcServer.getCanSpawnAnimals() && (par1Entity instanceof EntityAnimal || par1Entity instanceof EntityWaterMob)) { par1Entity.setDead(); } if (!this.mcServer.getCanSpawnNPCs() && par1Entity instanceof INpc) { par1Entity.setDead(); } super.updateEntityWithOptionalForce(par1Entity, par2); }
/** * Adds the persistenceRequired flag to entities, if they need it in order to not despawn. * The checks are probably at most accurate for vanilla entities. * @param livingBase * @return */ public static boolean applyMobPersistence(EntityLiving living) { if (living.isNoDespawnRequired() == false) { boolean canDespawn = ((living instanceof EntityMob) && living.isNonBoss()) || (living instanceof EntityWaterMob) || ((living instanceof EntityTameable) && ((EntityTameable)living).isTamed() == false); if (canDespawn == false) { try { canDespawn = (boolean) methodHandle_EntityLiving_canDespawn.invokeExact(living); } catch (Throwable t) { EnderUtilities.logger.warn("Error while trying to invoke EntityLiving.canDespawn() on entity '{}' via a MethodHandle", living, t); } } if (canDespawn) { // Sets the persistenceRequired boolean living.enablePersistence(); living.getEntityWorld().playSound(null, living.getPosition(), Sounds.JAILER, SoundCategory.MASTER, 0.8f, 1.2f); return true; } } return false; }
public void updateEntityWithOptionalForce(Entity p_72866_1_, boolean p_72866_2_) { if (!this.mcServer.getCanSpawnAnimals() && (p_72866_1_ instanceof EntityAnimal || p_72866_1_ instanceof EntityWaterMob)) { p_72866_1_.setDead(); } if (!this.mcServer.getCanSpawnNPCs() && p_72866_1_ instanceof INpc) { p_72866_1_.setDead(); } super.updateEntityWithOptionalForce(p_72866_1_, p_72866_2_); }
public void func_72866_a(Entity p_72866_1_, boolean p_72866_2_) { if(!this.field_73061_a.func_71268_U() && (p_72866_1_ instanceof EntityAnimal || p_72866_1_ instanceof EntityWaterMob)) { p_72866_1_.func_70106_y(); } if(!this.field_73061_a.func_71220_V() && p_72866_1_ instanceof INpc) { p_72866_1_.func_70106_y(); } super.func_72866_a(p_72866_1_, p_72866_2_); }
public static EnumCreatureType getDefaultMobType(Class<? extends EntityLiving> cls) { EnumCreatureType type = defaultMap.get(cls); if (type == null) { if (EntityAmbientCreature.class.isAssignableFrom(cls)) return EnumCreatureType.ambient; if (EntityWaterMob.class.isAssignableFrom(cls)) return EnumCreatureType.waterCreature; if (IMob.class.isAssignableFrom(cls)) return EnumCreatureType.monster; if (EntityCreature.class.isAssignableFrom(cls)) return EnumCreatureType.creature; } return type; }
@Override public Class<? extends EntityLivingBase> getEntityClass() { return EntityWaterMob.class; }
public boolean passesFilter(Entity entity){ if(filter == null || filter == FilterType.NONE) return false; switch(filter){ default : case ALL : { return true; } case PLAYER : { return entity instanceof EntityPlayer; } case UNDEAD : { return (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).getCreatureAttribute() == EnumCreatureAttribute.UNDEAD); } case ARTHROPOD : { return (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).getCreatureAttribute() == EnumCreatureAttribute.ARTHROPOD); } case MONSTER : { return (entity instanceof IMob); } case ANIMAL : { return (entity instanceof EntityAnimal); } case LIVING : { return (entity instanceof EntityLiving); } case WATER : { return (entity instanceof EntityWaterMob || entity instanceof EntityGuardian); } case BABY : { return (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isChild()); } case PET : { return (entity instanceof IEntityOwnable); } case SLIME : { return (entity instanceof EntitySlime); } case VILLAGER : { return (entity instanceof EntityVillager); } case ITEM : { return (entity instanceof EntityItem); } } }
public void updateSpawner() { if (isActivated() && !powered) { double d2; if (this.getSpawnerWorld().isRemote) { double d0 = this.getSpawnerX() + this.getSpawnerWorld().rand.nextFloat(); double d1 = this.getSpawnerY() + this.getSpawnerWorld().rand.nextFloat(); d2 = this.getSpawnerZ() + this.getSpawnerWorld().rand.nextFloat(); this.getSpawnerWorld().spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D); this.getSpawnerWorld().spawnParticle(EnumParticleTypes.FLAME, d0, d1, d2, 0.0D, 0.0D, 0.0D); if (this.spawnDelay > 0) { --this.spawnDelay; } this.renderRotation1 = this.renderRotation0; this.renderRotation0 = (this.renderRotation0 + 1000.0F / (this.spawnDelay + 200.0F)) % 360.0D; } else { if (this.spawnDelay == -1) { this.resetTimer(); } if (this.spawnDelay > 0) { --this.spawnDelay; return; } boolean flag = false; for (int i = 0; i < this.spawnCount; ++i) { EntityEssenceInstance<?> essence = ItemMobEssence.getEssence(getEntityNameToSpawn()); Entity entity = essence.createEntity(getSpawnerWorld()); if (entity == null) { return; } int j = this.getSpawnerWorld().getEntitiesWithinAABB(entity.getClass(), new AxisAlignedBB(this.getSpawnerX(), this.getSpawnerY(), this.getSpawnerZ(), this.getSpawnerX() + 1, this.getSpawnerY() + 1, this.getSpawnerZ() + 1).expand(this.spawnRange * 2, 4.0D, this.spawnRange * 2)).size(); if (j >= this.maxNearbyEntities) { this.resetTimer(); return; } World world = getSpawnerWorld(); BlockPos blockpos = new BlockPos(getSpawnerX(), getSpawnerY(), getSpawnerZ()); double x = blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * this.spawnRange + 0.5D; double y = blockpos.getY() + world.rand.nextInt(3) - 1; double z = blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * this.spawnRange + 0.5D; EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving) entity : null; entity.setLocationAndAngles(x, y, z, world.rand.nextFloat() * 360.0F, 0.0F); //Make Water Mobs require water boolean specialCheck = ignoreSpawnRequirements && getSpawnerWorld().isAirBlock(new BlockPos(x, y, z)); if(!ignoreSpawnRequirements && (entity instanceof EntityWaterMob || entity instanceof EntityGuardian)){ specialCheck = world.isMaterialInBB(entity.getEntityBoundingBox(), Material.WATER); } if (entityliving == null || (net.minecraftforge.event.ForgeEventFactory.canEntitySpawnSpawner(entityliving, getSpawnerWorld(), (float)entity.posX, (float)entity.posY, (float)entity.posZ) || specialCheck)) { this.spawnEntity(entity); this.getSpawnerWorld().playEvent(2004, this.getSpawnerPos(), 0); if (entityliving != null) { entityliving.spawnExplosionParticle(); } flag = true; } } if (flag) { this.resetTimer(); } } } }
public static boolean isCorrectEntity(Object o, boolean ignoreFriends) { // non-entities if (!(o instanceof Entity)) return false; // friends if (ignoreFriends && o instanceof EntityPlayer) { if (WurstClient.INSTANCE.friends.contains(((EntityPlayer) o).getName())) return false; } TargetFeature targetFeature = WurstClient.INSTANCE.specialFeatures.targetFeature; // invisible entities if (((Entity) o).isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer)) { return targetFeature.invisibleMobs.isChecked() && o instanceof EntityLiving || targetFeature.invisiblePlayers.isChecked() && o instanceof EntityPlayer; } // players if (o instanceof EntityPlayer) { return (((EntityPlayer) o).isPlayerSleeping() && targetFeature.sleepingPlayers.isChecked() || !((EntityPlayer) o).isPlayerSleeping() && targetFeature.players.isChecked()) && (!targetFeature.teams.isChecked() || checkName(((EntityPlayer) o).getDisplayName().getFormattedText())); } // animals if (o instanceof EntityAgeable || o instanceof EntityAmbientCreature || o instanceof EntityWaterMob) { return targetFeature.animals.isChecked() && (!targetFeature.teams.isChecked() || !((Entity) o).hasCustomName() || checkName(((Entity) o).getCustomNameTag())); } // monsters if (o instanceof EntityMob || o instanceof EntitySlime || o instanceof EntityFlying) { return targetFeature.monsters.isChecked() && (!targetFeature.teams.isChecked() || !((Entity) o).hasCustomName() || checkName(((Entity) o).getCustomNameTag())); } // golems return o instanceof EntityGolem && targetFeature.golems.isChecked() && (!targetFeature.teams.isChecked() || !((Entity) o).hasCustomName() || checkName(((Entity) o).getCustomNameTag())); }
@Override public void velocityToAddToEntity(World w, int x, int y, int z, Entity entity, Vec3 velocity) { if (entity instanceof EntityWaterMob) { velocity.xCoord = 0; velocity.yCoord = 0; velocity.zCoord = 0; return; } boolean isItem = entity instanceof EntityItem; if (isItem && FysiksFun.rand.nextInt(10) == 0) return; float speedMultiplier = 1.0f; if (isItem) speedMultiplier = 10.0f; Vec3 vec = this.getFFFlowVector(w, x, y, z); Vec3 vec2; // Let the direction of flow also be affected by streams of water one step // below us if (!isSameLiquid(w.getBlockId(x, y, z))) { FysiksFun.logger.log(Level.SEVERE, "BlockFluid::velocityToAdd called for a block that is not a fluid"); } if (isSameLiquid(w.getBlockId(x, y - 1, z))) { vec2 = this.getFFFlowVector(w, x, y - 1, z); vec.xCoord += vec2.xCoord * speedMultiplier; vec.yCoord += vec2.yCoord * speedMultiplier; } // Let the direction of flow also be affected by streams of water above us /* Disabled for now, it is expensive with these checks due to synchronization issues for (int dy = 1; dy < 3; dy++) { if (!isSameLiquid(w.getBlockId(x, y + dy, z))) break; vec2 = this.getFFFlowVector(w, x, y + dy, z); vec.xCoord += vec2.xCoord * speedMultiplier; vec.yCoord += vec2.yCoord * speedMultiplier; }*/ if (vec.lengthVector() > 0.0D && entity.isPushedByWater()) { double d1 = 0.0025d; // 0.014D; entity.motionX += vec.xCoord * d1; entity.motionY += vec.yCoord * d1; entity.motionZ += vec.zCoord * d1; velocity.xCoord += vec.xCoord; velocity.yCoord += vec.yCoord; velocity.zCoord += vec.zCoord; } }