use of net.minecraft.entity.passive.EntityVillager in project ICBM-Classic by BuiltBrokenModding.
the class BlastMutation method doExplode.
@Override
public void doExplode() {
if (!this.world().isRemote) {
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - this.getRadius(), position.y() - this.getRadius(), position.z() - this.getRadius(), position.x() + this.getRadius(), position.y() + this.getRadius(), position.z() + this.getRadius());
List<EntityLiving> entitiesNearby = world().getEntitiesWithinAABB(EntityLiving.class, bounds);
for (EntityLiving entity : entitiesNearby) {
if (entity instanceof EntityPig) {
EntityPigZombie newEntity = new EntityPigZombie(world());
newEntity.preventEntitySpawning = true;
newEntity.setPosition(entity.posX, entity.posY, entity.posZ);
entity.setDead();
} else if (entity instanceof EntityVillager) {
EntityZombie newEntity = new EntityZombie(world());
newEntity.preventEntitySpawning = true;
newEntity.setPosition(entity.posX, entity.posY, entity.posZ);
entity.setDead();
}
}
}
}
use of net.minecraft.entity.passive.EntityVillager in project VoodooCraft by Mod-DevCafeTeam.
the class TestItem method itemInteractionForEntity.
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand) {
World world = playerIn.world;
BlockPos pos = target.getPosition();
EntityVillager villager = new EntityVillager(world);
EntityZombie zombie = new EntityZombie(world);
if (!world.isRemote) {
if (target instanceof EntityZombie) {
villager.setPosition(pos.getX(), pos.getY(), pos.getZ());
world.spawnEntity(villager);
target.setDead();
return true;
} else if (target instanceof EntityVillager) {
zombie.setPosition(pos.getX(), pos.getY(), pos.getZ());
world.spawnEntity(zombie);
target.setDead();
return true;
}
}
return false;
}
use of net.minecraft.entity.passive.EntityVillager in project VoodooCraft by Mod-DevCafeTeam.
the class HexZombify method activeUse.
@Override
public ItemStack activeUse(ItemStack stackIn, World world, EntityPlayer player, EnumHand hand, int strength, @Nullable EntityLivingBase target) {
if (!world.isRemote) {
if (target instanceof EntityZombie) {
EntityVillager villager = new EntityVillager(world);
villager.copyLocationAndAnglesFrom(target);
villager.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(villager)), null);
world.removeEntity(target);
world.spawnEntity(villager);
} else if (target instanceof EntityVillager) {
EntityZombie zombie = new EntityZombie(world);
zombie.copyLocationAndAnglesFrom(target);
zombie.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(zombie)), null);
world.removeEntity(target);
world.spawnEntity(zombie);
}
}
if (target != null)
VoodooCraft.proxy.spawnParticle(world, EnumParticleTypes.EXPLOSION_NORMAL, target.posX, target.posY, target.posZ);
player.playSound(VCSoundHandler.transformation, 1.0F, 1.0F);
return super.activeUse(stackIn, world, player, hand, strength, target);
}
use of net.minecraft.entity.passive.EntityVillager in project PneumaticCraft by MineMaarten.
the class TileEntityPressureChamberValve method updateEntity.
// main update method
@Override
public void updateEntity() {
if (readNBT) {
// this way of doing this is needed because other TE's are
// loaded after the reading of the NBT of this TE.
readNBT = false;
accessoryValves.clear();
for (int[] valve : nbtValveList) {
TileEntity te = worldObj.getTileEntity(valve[0], valve[1], valve[2]);
if (te instanceof TileEntityPressureChamberValve) {
accessoryValves.add((TileEntityPressureChamberValve) te);
}
}
if (accessoryValves.isEmpty()) {
//Hacky solution for an unexplainable bug.
invalidateMultiBlock();
checkIfProperlyFormed(worldObj, xCoord, yCoord, zCoord);
}
if (worldObj.isRemote)
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
}
if (!worldObj.isRemote) {
//code to check if we need to leak air.
//assume we are not leaking at any side
boolean[] connected = new boolean[] { true, true, true, true, true, true };
switch(//take off the sides that tubes can connect to.
ForgeDirection.getOrientation(getBlockMetadata())) {
case UP:
case DOWN:
connected[ForgeDirection.UP.ordinal()] = false;
connected[ForgeDirection.DOWN.ordinal()] = false;
break;
case NORTH:
case SOUTH:
connected[ForgeDirection.NORTH.ordinal()] = false;
connected[ForgeDirection.SOUTH.ordinal()] = false;
break;
case EAST:
case WEST:
connected[ForgeDirection.EAST.ordinal()] = false;
connected[ForgeDirection.WEST.ordinal()] = false;
break;
}
//we need the super method, as the overridden method adds the other valves.
List<Pair<ForgeDirection, IAirHandler>> teList = super.getConnectedPneumatics();
for (Pair<ForgeDirection, IAirHandler> entry : teList) {
connected[entry.getKey().ordinal()] = true;
}
//retrieve the valve that is controlling the (potential) chamber.
TileEntityPressureChamberValve baseValve = null;
for (TileEntityPressureChamberValve valve : accessoryValves) {
if (valve.multiBlockSize > 0) {
baseValve = valve;
break;
}
}
//if we found one, we can scratch one side to be leaking air.
if (baseValve != null) {
switch(ForgeDirection.getOrientation(getBlockMetadata())) {
case UP:
case DOWN:
if (baseValve.multiBlockY == yCoord)
connected[ForgeDirection.UP.ordinal()] = true;
else
connected[ForgeDirection.DOWN.ordinal()] = true;
break;
case NORTH:
case SOUTH:
if (baseValve.multiBlockZ == zCoord)
connected[ForgeDirection.SOUTH.ordinal()] = true;
else
connected[ForgeDirection.NORTH.ordinal()] = true;
break;
case EAST:
case WEST:
if (baseValve.multiBlockX == xCoord)
connected[ForgeDirection.EAST.ordinal()] = true;
else
connected[ForgeDirection.WEST.ordinal()] = true;
break;
}
}
for (int i = 0; i < 6; i++) if (!connected[i])
airLeak(ForgeDirection.getOrientation(i));
}
super.updateEntity();
if (multiBlockSize != 0 && !worldObj.isRemote) {
ItemStack[] stacksInChamber = getStacksInChamber();
isValidRecipeInChamber = false;
isSufficientPressureInChamber = false;
recipePressure = Float.MAX_VALUE;
//simple recipes
for (PressureChamberRecipe recipe : PressureChamberRecipe.chamberRecipes) {
boolean isValidRecipeInChamberFlag = canBeCompressed(recipe, stacksInChamber);
boolean isSufficientPressureInChamberFlag = recipe.pressure <= getPressure(ForgeDirection.UNKNOWN) && recipe.pressure > 0F || recipe.pressure >= getPressure(ForgeDirection.UNKNOWN) && recipe.pressure < 0F;
if (isValidRecipeInChamberFlag) {
isValidRecipeInChamber = true;
if (Math.abs(recipe.pressure) < Math.abs(recipePressure)) {
recipePressure = recipe.pressure;
}
}
if (isSufficientPressureInChamberFlag)
isSufficientPressureInChamber = true;
if (isValidRecipeInChamberFlag && isSufficientPressureInChamberFlag && areEntitiesDoneMoving) {
double[] outputPosition = clearStacksInChamber(recipe.input);
giveOutput(recipe.output, outputPosition);
}
}
//special recipes
for (IPressureChamberRecipe recipe : PressureChamberRecipe.specialRecipes) {
ItemStack[] removedStacks = recipe.isValidRecipe(stacksInChamber);
boolean isValidRecipeInChamberFlag = removedStacks != null;
boolean isSufficientPressureInChamberFlag = recipe.getCraftingPressure() <= getPressure(ForgeDirection.UNKNOWN) && recipe.getCraftingPressure() > 0F || recipe.getCraftingPressure() >= getPressure(ForgeDirection.UNKNOWN) && recipe.getCraftingPressure() < 0F;
if (isValidRecipeInChamberFlag) {
isValidRecipeInChamber = true;
if (Math.abs(recipe.getCraftingPressure()) < Math.abs(recipePressure)) {
recipePressure = recipe.getCraftingPressure();
}
}
if (isSufficientPressureInChamberFlag)
isSufficientPressureInChamber = true;
if (isValidRecipeInChamberFlag && isSufficientPressureInChamberFlag && areEntitiesDoneMoving) {
double[] outputPosition = clearStacksInChamber(removedStacks);
giveOutput(recipe.craftRecipe(stacksInChamber, removedStacks), outputPosition);
}
}
if (getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MAX_PRESSURE_LIVING_ENTITY) {
AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(multiBlockX + 1, multiBlockY + 1, multiBlockZ + 1, multiBlockX + multiBlockSize - 1, multiBlockY + multiBlockSize - 1, multiBlockZ + multiBlockSize - 1);
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, bbBox);
for (EntityLivingBase entity : entities) {
if (entity instanceof EntityVillager) {
EntityVillager villager = (EntityVillager) entity;
if (villager.getProfession() != Config.villagerMechanicID) {
villager.setProfession(Config.villagerMechanicID);
NBTTagCompound tag = new NBTTagCompound();
villager.writeEntityToNBT(tag);
if (tag.hasKey("Offers")) {
//reset the trade list
tag.removeTag("Offers");
villager.readEntityFromNBT(tag);
}
}
}
entity.attackEntityFrom(DamageSourcePneumaticCraft.pressure, (int) (getPressure(ForgeDirection.UNKNOWN) * 2D));
}
}
}
// move entities to eachother.
AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(multiBlockX, multiBlockY, multiBlockZ, multiBlockX + multiBlockSize, multiBlockY + multiBlockSize, multiBlockZ + multiBlockSize);
List<EntityItem> entities = worldObj.getEntitiesWithinAABB(EntityItem.class, bbBox);
// set to true, set to false when one of
areEntitiesDoneMoving = true;
// the entities is moving.
for (int i = 0; i < entities.size() - 1; i++) {
EntityItem lastEntity = entities.get(i);
EntityItem entity = entities.get(i + 1);
// XP Orb code snippet
double d0 = 8.0D;
double d1 = (lastEntity.posX - entity.posX) / d0;
double d3 = (lastEntity.posZ - entity.posZ) / d0;
double d4 = Math.sqrt(d1 * d1 + d3 * d3);
double d5 = 1.0D - d4;
if (d5 > 0.0D && d4 > 0.02D) {
d5 *= d5;
entity.motionX += d1 / d4 * d5 * 0.01D;
entity.motionZ += d3 / d4 * d5 * 0.01D;
lastEntity.motionX -= d1 / d4 * d5 * 0.01D;
lastEntity.motionZ -= d3 / d4 * d5 * 0.01D;
areEntitiesDoneMoving = false;
}
}
boolean lifeUpgrade = getUpgrades(ItemMachineUpgrade.UPGRADE_ITEM_LIFE, getUpgradeSlots()) > 0;
if (lifeUpgrade && !worldObj.isRemote) {
for (EntityItem entity : entities) {
entity.age--;
}
}
// particles
if (worldObj.isRemote && getPressure(ForgeDirection.UNKNOWN) > 0.2D) {
int particles = (int) Math.pow(multiBlockSize - 2, 3);
for (int i = 0; i < particles; i++) {
if (rand.nextInt(Math.max(1, 8 - (int) (getPressure(ForgeDirection.UNKNOWN) * 2D))) == 0) {
double posX = multiBlockX + 1D + rand.nextDouble() * (multiBlockSize - 2D);
double posY = multiBlockY + 1D + rand.nextDouble() * (multiBlockSize - 2D);
double posZ = multiBlockZ + 1D + rand.nextDouble() * (multiBlockSize - 2D);
worldObj.spawnParticle("explode", posX, posY, posZ, 0D, 0D, 0D);
}
}
}
}
use of net.minecraft.entity.passive.EntityVillager in project Pearcel-Mod by MiningMark48.
the class BlockSummoner method onBlockActivated.
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
Random rand = new Random();
int spawnRand = rand.nextInt(5) + 1;
int negRand = rand.nextInt(2) + 1;
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
if (negRand == 1) {
spawnRand = -spawnRand;
}
EntitySheep sheep = new EntitySheep(world);
sheep.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityEnderman enderman = new EntityEnderman(world);
enderman.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityBlaze blaze = new EntityBlaze(world);
blaze.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityGhast ghast = new EntityGhast(world);
ghast.setPosition(x + spawnRand, y + 5, z + spawnRand);
EntitySkeleton skeleton = new EntitySkeleton(world);
skeleton.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityCreeper creeper = new EntityCreeper(world);
creeper.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityEnderCrystal endcrystal = new EntityEnderCrystal(world);
endcrystal.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityHorse horse = new EntityHorse(world);
horse.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityIronGolem iron_golem = new EntityIronGolem(world);
iron_golem.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityVillager villager = new EntityVillager(world);
villager.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityDragon dragon = new EntityDragon(world);
dragon.setPosition(x + spawnRand, y + 2, z + spawnRand);
EntityWither wither = new EntityWither(world);
wither.setPosition(x + spawnRand, y + 2, z + spawnRand);
if (player.getHeldItem(EnumHand.MAIN_HAND) != null) {
if (!player.isSneaking() && player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.sap) {
if (!world.isRemote) {
//Missing Block
if (world.getBlockState(pos.up()).getBlock() == Blocks.AIR) {
player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + Translate.toLocal("summoner.error.missingBlock")));
if (world.isRemote) {
world.spawnEntity(new EntityLightningBolt(world, player.posX, player.posY, player.posZ, true));
}
} else //Dragon
if (isCorrectSetup(pos, world, Blocks.DRAGON_EGG, Blocks.DIAMOND_BLOCK)) {
if (player.dimension == 1) {
setTainted(pos, world);
world.spawnEntity(dragon);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.dragon") + " " + Translate.toLocal("summoner.summoned")));
} else {
player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + Translate.toLocal("summoner.error.wrongDimension")));
}
} else //Wither
if (isCorrectSetup(pos, world, Blocks.SKULL, Blocks.DIAMOND_BLOCK)) {
setTainted(pos, world);
world.spawnEntity(wither);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.wither") + " " + Translate.toLocal("summoner.summoned")));
} else //Sheep
if (isCorrectSetup(pos, world, Blocks.WOOL, Blocks.WOOL)) {
setTainted(pos, world);
world.spawnEntity(sheep);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.sheep") + " " + Translate.toLocal("summoner.summoned")));
} else //Enderman
if (isCorrectSetup(pos, world, Blocks.END_STONE, Blocks.END_STONE)) {
setTainted(pos, world);
world.spawnEntity(enderman);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.enderman") + " " + Translate.toLocal("summoner.summoned")));
} else //Blaze
if (isCorrectSetup(pos, world, Blocks.GRAVEL, Blocks.NETHERRACK)) {
setTainted(pos, world);
world.spawnEntity(blaze);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.blaze") + " " + Translate.toLocal("summoner.summoned")));
} else //Ghast
if (isCorrectSetup(pos, world, Blocks.COBBLESTONE, Blocks.SOUL_SAND)) {
setTainted(pos, world);
world.spawnEntity(ghast);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.ghast") + " " + Translate.toLocal("summoner.summoned")));
} else //Skeleton
if (isCorrectSetup(pos, world, Blocks.PLANKS, Blocks.SAND)) {
setTainted(pos, world);
world.spawnEntity(skeleton);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.skeleton") + " " + Translate.toLocal("summoner.summoned")));
} else //Creeper
if (isCorrectSetup(pos, world, Blocks.TNT, Blocks.TNT)) {
setTainted(pos, world);
world.spawnEntity(creeper);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.creeper") + " " + Translate.toLocal("summoner.summoned")));
} else //Horse
if (isCorrectSetup(pos, world, Blocks.HAY_BLOCK, Blocks.HAY_BLOCK)) {
setTainted(pos, world);
world.spawnEntity(horse);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.horse") + " " + Translate.toLocal("summoner.summoned")));
} else //Iron Golem
if (isCorrectSetup(pos, world, Blocks.IRON_BLOCK, Blocks.IRON_BLOCK)) {
setTainted(pos, world);
world.spawnEntity(iron_golem);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.iron_golem") + " " + Translate.toLocal("summoner.summoned")));
} else //Villager
if (isCorrectSetup(pos, world, Blocks.EMERALD_BLOCK, Blocks.SKULL)) {
setTainted(pos, world);
world.spawnEntity(villager);
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("summoner.mob_summon.villager") + " " + Translate.toLocal("summoner.summoned")));
} else {
if (!world.isRemote) {
setTainted(pos, world);
player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + Translate.toLocal("summoner.error.incorrectBlock")));
}
if (world.isRemote) {
world.spawnEntity(new EntityLightningBolt(world, player.posX, player.posY, player.posZ, true));
}
}
}
player.playSound(ModSoundEvents.BLOCK_SUMMONER_LAUGH, 5.0F, 1.0F);
world.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, x, y, z, 1.0D, 0.0D, 0.0D);
if (!player.isCreative()) {
player.getHeldItem(EnumHand.MAIN_HAND).damageItem(1, player);
player.attackEntityFrom(DamageSource.outOfWorld, 10.0F);
}
} else {
if (!world.isRemote) {
player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + Translate.toLocal("summoner.error.incorrectItem")));
}
}
}
return true;
}
Aggregations