Java Code Examples for net.minecraft.entity.passive.EntityPig

The following are top voted examples for showing how to use net.minecraft.entity.passive.EntityPig. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: DecompiledMinecraft   File: ItemCarrotOnAStick.java   View source code 6 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.isRiding() && playerIn.ridingEntity instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.ridingEntity;

        if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
        {
            entitypig.getAIControlledByPlayer().boostSpeed();
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.fishing_rod);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return itemstack;
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    return itemStackIn;
}
 
Example 2
Project: DecompiledMinecraft   File: ItemSaddle.java   View source code 6 votes vote down vote up
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target)
{
    if (target instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)target;

        if (!entitypig.getSaddled() && !entitypig.isChild())
        {
            entitypig.setSaddled(true);
            entitypig.worldObj.playSoundAtEntity(entitypig, "mob.horse.leather", 0.5F, 1.0F);
            --stack.stackSize;
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 3
Project: DecompiledMinecraft   File: ItemCarrotOnAStick.java   View source code 6 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.isRiding() && playerIn.ridingEntity instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.ridingEntity;

        if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
        {
            entitypig.getAIControlledByPlayer().boostSpeed();
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.fishing_rod);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return itemstack;
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    return itemStackIn;
}
 
Example 4
Project: DecompiledMinecraft   File: ItemSaddle.java   View source code 6 votes vote down vote up
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target)
{
    if (target instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)target;

        if (!entitypig.getSaddled() && !entitypig.isChild())
        {
            entitypig.setSaddled(true);
            entitypig.worldObj.playSoundAtEntity(entitypig, "mob.horse.leather", 0.5F, 1.0F);
            --stack.stackSize;
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 5
Project: BaseClient   File: ItemCarrotOnAStick.java   View source code 6 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.isRiding() && playerIn.ridingEntity instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.ridingEntity;

        if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
        {
            entitypig.getAIControlledByPlayer().boostSpeed();
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.fishing_rod);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return itemstack;
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    return itemStackIn;
}
 
Example 6
Project: BaseClient   File: ItemSaddle.java   View source code 6 votes vote down vote up
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target)
{
    if (target instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)target;

        if (!entitypig.getSaddled() && !entitypig.isChild())
        {
            entitypig.setSaddled(true);
            entitypig.worldObj.playSoundAtEntity(entitypig, "mob.horse.leather", 0.5F, 1.0F);
            --stack.stackSize;
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 7
Project: BaseClient   File: ItemCarrotOnAStick.java   View source code 6 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.isRiding() && playerIn.ridingEntity instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.ridingEntity;

        if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
        {
            entitypig.getAIControlledByPlayer().boostSpeed();
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.fishing_rod);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return itemstack;
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    return itemStackIn;
}
 
Example 8
Project: BaseClient   File: ItemSaddle.java   View source code 6 votes vote down vote up
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target)
{
    if (target instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)target;

        if (!entitypig.getSaddled() && !entitypig.isChild())
        {
            entitypig.setSaddled(true);
            entitypig.worldObj.playSoundAtEntity(entitypig, "mob.horse.leather", 0.5F, 1.0F);
            --stack.stackSize;
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 9
Project: connor41-etfuturum2   File: ServerEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void spawnEvent(EntityJoinWorldEvent event) {
	if (event.entity instanceof EntityPig) {
		EntityPig pig = (EntityPig) event.entity;
		if (EtFuturum.enableBeetroot)
			pig.tasks.addTask(4, new EntityAITempt(pig, 1.2, ModItems.beetroot, false));
	} else if (event.entity instanceof EntityChicken) {
		EntityChicken chicken = (EntityChicken) event.entity;
		if (EtFuturum.enableBeetroot)
			chicken.tasks.addTask(3, new EntityAITempt(chicken, 1.0D, ModItems.beetroot_seeds, false));
	} else if (event.entity instanceof EntityWolf) {
		EntityWolf wolf = (EntityWolf) event.entity;
		if (EtFuturum.enableRabbit)
			wolf.targetTasks.addTask(4, new EntityAITargetNonTamed(wolf, EntityRabbit.class, 200, false));
	} else if (event.entity instanceof EntityVillager) {
		EntityVillager villager = (EntityVillager) event.entity;
		for (Object obj : villager.tasks.taskEntries) {
			EntityAITaskEntry entry = (EntityAITaskEntry) obj;
			if (entry.action instanceof EntityAIOpenDoor) {
				villager.tasks.removeTask(entry.action);
				villager.tasks.addTask(entry.priority, new EntityAIOpenCustomDoor(villager, true));
				break;
			}
		}
	}
}
 
Example 10
Project: connor41-etfuturum2   File: ServerEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void interactEntityEvent(EntityInteractEvent event) {
	ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
	if (stack == null)
		return;
	if (!(event.target instanceof EntityAnimal))
		return;

	EntityAnimal animal = (EntityAnimal) event.target;
	if (!animal.isChild()) {
		if (animal instanceof EntityPig) {
			if (stack.getItem() == ModItems.beetroot && EtFuturum.enableBeetroot)
				setAnimalInLove(animal, event.entityPlayer, stack);
		} else if (animal instanceof EntityChicken)
			if (stack.getItem() == ModItems.beetroot_seeds && EtFuturum.enableBeetroot)
				setAnimalInLove(animal, event.entityPlayer, stack);
	} else if (EtFuturum.enableBabyGrowthBoost && isFoodItem(animal, stack))
		feedBaby(animal, event.entityPlayer, stack);
}
 
Example 11
Project: Backmemed   File: ItemSaddle.java   View source code 6 votes vote down vote up
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand)
{
    if (target instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)target;

        if (!entitypig.getSaddled() && !entitypig.isChild())
        {
            entitypig.setSaddled(true);
            entitypig.world.playSound(playerIn, entitypig.posX, entitypig.posY, entitypig.posZ, SoundEvents.ENTITY_PIG_SADDLE, SoundCategory.NEUTRAL, 0.5F, 1.0F);
            stack.func_190918_g(1);
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 12
Project: CustomWorldGen   File: ItemCarrotOnAStick.java   View source code 6 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    if (playerIn.isRiding() && playerIn.getRidingEntity() instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.getRidingEntity();

        if (itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7 && entitypig.boost())
        {
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.FISHING_ROD);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }

            return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
        }
    }

    playerIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult(EnumActionResult.PASS, itemStackIn);
}
 
Example 13
Project: CustomWorldGen   File: ItemSaddle.java   View source code 6 votes vote down vote up
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand)
{
    if (target instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)target;

        if (!entitypig.getSaddled() && !entitypig.isChild())
        {
            entitypig.setSaddled(true);
            entitypig.worldObj.playSound(playerIn, entitypig.posX, entitypig.posY, entitypig.posZ, SoundEvents.ENTITY_PIG_SADDLE, SoundCategory.NEUTRAL, 0.5F, 1.0F);
            --stack.stackSize;
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 14
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_rotationYaw_is_readable() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint();

  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig,NoAI:1}", pos.getX(),
      pos.getY(), pos.getZ());
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; print(string.format('%.5f',p.rotationYaw))");

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  String expectedRotationYaw =
      String.format("%.5f", ((EntityPig) actEntities.get(0)).renderYawOffset);
  assertThat(act.getMessage()).isEqualTo(expectedRotationYaw);
}
 
Example 15
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_rotationYaw_is_writable() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint();
  float expectedRotationYaw = 45f;
  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig,NoAI:1}", pos.getX(),
      pos.getY(), pos.getZ());
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; p.rotationYaw=%s; print('ok')",
      expectedRotationYaw);

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  float actualRotationYaw = ((EntityPig) actEntities.get(0)).rotationYaw;
  assertThat(actualRotationYaw).isEqualTo(expectedRotationYaw);
}
 
Example 16
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_rotationPitch_is_readable() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint();

  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig,NoAI:1}", pos.getX(),
      pos.getY(), pos.getZ());
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; print(string.format('%.5f',p.rotationPitch))");

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  String expectedRotationPitch =
      String.format("%.5f", ((EntityPig) actEntities.get(0)).rotationPitch);
  assertThat(act.getMessage()).isEqualTo(expectedRotationPitch);
}
 
Example 17
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_rotationPitch_is_writable() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint();
  float expectedRotationPitch = 45f;
  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig,NoAI:1}", pos.getX(),
      pos.getY(), pos.getZ());
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; p.rotationPitch=%s; print('ok')",
      expectedRotationPitch);

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  float actualRotationPitch = ((EntityPig) actEntities.get(0)).rotationPitch;
  assertThat(actualRotationPitch).isEqualTo(expectedRotationPitch);
}
 
Example 18
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_eyeHeight_is_readable() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint();

  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig}", pos.getX(),
      pos.getY(), pos.getZ());
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; print(string.format('%.5f',p.eyeHeight))");

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  String expectedEyeHeight =
      String.format("%.5f", ((EntityPig) actEntities.get(0)).getEyeHeight());
  assertThat(act.getMessage()).isEqualTo(expectedEyeHeight);
}
 
Example 19
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_motion_is_writable() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint();

  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig}", pos.getX(),
      pos.getY(), pos.getZ());
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; p.motion=Vec3(0,10,0); print('ok')");

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  double actualMotion = ((EntityPig) actEntities.get(0)).motionY;
  assertThat(actualMotion).isGreaterThan(0);
}
 
Example 20
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_tags_is_writable() throws Exception {
  // Given:
  String initialTag = "initialtag";
  String newTag1 = "newtag1";
  String newTag2 = "newtag2";
  BlockPos pos = mc().getWorldSpawnPoint();

  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig,Tags:[0:\"%s\"]}",
      pos.getX(), pos.getY(), pos.getZ(), initialTag);
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; p.tags={'%s','%s'}; print('ok')", newTag1,
      newTag2);

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  Set<String> actualTags = ((EntityPig) actEntities.get(0)).getTags();
  assertThat(actualTags).containsOnly(newTag1, newTag2);
}
 
Example 21
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_addTag() throws Exception {
  // Given:
  String initialTag = "initialtag";
  String newTag = "newtag";

  BlockPos pos = mc().getWorldSpawnPoint();

  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig,Tags:[0:\"%s\"]}",
      pos.getX(), pos.getY(), pos.getZ(), initialTag);
  mc().clearEvents();

  // When:
  mc().executeCommand("/lua p=Entities.find('@e[name=testpig]')[1]; p:addTag('%s'); print('ok')",
      newTag);

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  Set<String> actualTags = ((EntityPig) actEntities.get(0)).getTags();
  assertThat(actualTags).containsOnly(initialTag, newTag);
}
 
Example 22
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_removeTag() throws Exception {
  // Given:
  String initialTag = "initialtag";

  BlockPos pos = mc().getWorldSpawnPoint();

  mc().executeCommand("/summon minecraft:pig %s %s %s {CustomName:testpig,Tags:[0:\"%s\"]}",
      pos.getX(), pos.getY(), pos.getZ(), initialTag);
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; p:removeTag('%s'); print('ok')", initialTag);

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  Set<String> actualTags = ((EntityPig) actEntities.get(0)).getTags();
  assertThat(actualTags).isEmpty();
}
 
Example 23
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_move_forward() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint().up();
  float rotation = 90;
  BlockPos expectedPos = pos.west();

  mc().executeCommand(
      "/summon minecraft:pig %s %s %s {CustomName:testpig,NoAI:1,Rotation:[0:%sf,1:0f]}",
      pos.getX(), pos.getY(), pos.getZ(), rotation);
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; p:move('forward'); print('ok')");

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  BlockPos actPos = ((EntityPig) actEntities.get(0)).getPosition();
  assertThat(actPos).isEqualTo(expectedPos);
}
 
Example 24
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_move_back() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint().up();
  float rotation = 90;
  BlockPos expectedPos = pos.east();

  mc().executeCommand(
      "/summon minecraft:pig %s %s %s {CustomName:testpig,NoAI:1,Rotation:[0:%sf,1:0f]}",
      pos.getX(), pos.getY(), pos.getZ(), rotation);
  mc().clearEvents();

  // When:
  mc().executeCommand("/lua p=Entities.find('@e[name=testpig]')[1]; p:move('back'); print('ok')");

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  BlockPos actPos = ((EntityPig) actEntities.get(0)).getPosition();
  assertThat(actPos).isEqualTo(expectedPos);
}
 
Example 25
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_move_left() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint().up();
  float rotation = 90;
  BlockPos expectedPos = pos.south();

  mc().executeCommand(
      "/summon minecraft:pig %s %s %s {CustomName:testpig,NoAI:1,Rotation:[0:%sf,1:0f]}",
      pos.getX(), pos.getY(), pos.getZ(), rotation);
  mc().clearEvents();

  // When:
  mc().executeCommand("/lua p=Entities.find('@e[name=testpig]')[1]; p:move('left'); print('ok')");

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  BlockPos actPos = ((EntityPig) actEntities.get(0)).getPosition();
  assertThat(actPos).isEqualTo(expectedPos);
}
 
Example 26
Project: wizards-of-lua   File: EntityTest.java   View source code 6 votes vote down vote up
@Test
public void test_move_right() throws Exception {
  // Given:
  BlockPos pos = mc().getWorldSpawnPoint().up();
  float rotation = 90;
  BlockPos expectedPos = pos.north();

  mc().executeCommand(
      "/summon minecraft:pig %s %s %s {CustomName:testpig,NoAI:1,Rotation:[0:%sf,1:0f]}",
      pos.getX(), pos.getY(), pos.getZ(), rotation);
  mc().clearEvents();

  // When:
  mc().executeCommand(
      "/lua p=Entities.find('@e[name=testpig]')[1]; p:move('right'); print('ok')");

  // Then:
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo("ok");
  List<Entity> actEntities = mc().findEntities("@e[name=testpig]");
  assertThat(actEntities).hasSize(1);
  BlockPos actPos = ((EntityPig) actEntities.get(0)).getPosition();
  assertThat(actPos).isEqualTo(expectedPos);
}
 
Example 27
Project: Tannery   File: EntityDropsHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onLivingDrops(LivingDropsEvent event)
{
	Entity e = event.entity;
	List<EntityItem> drops = event.drops;
	// Remove all drops from cows, sheep and pigs, add carcass drop
	if (e instanceof EntityCow || e instanceof EntityPig || e instanceof EntitySheep)
	{
		EntityAnimal a = (EntityAnimal) e;
		Iterator<EntityItem> it = drops.iterator();
		while (it.hasNext())
		{
			EntityItem i = it.next();
			it.remove();
		}

		if (a.getGrowingAge() == 0)
		{
			if (a instanceof EntityCow) a.dropItem(TanneryItems.bloodyCowCarcass, 1);
			else if (a instanceof EntityPig) a.dropItem(TanneryItems.bloodyPigCarcass, 1);
			else if (a instanceof EntitySheep) a.dropItem(TanneryItems.bloodySheepCarcass, 1);
		}
	}
}
 
Example 28
Project: Minecraft-Flux   File: EntityActionEnergy.java   View source code 6 votes vote down vote up
@Override
public long inputEnergy(long amount, boolean simulate) {
	if (!simulate && !charged) {
		if (creature instanceof EntityPig) {
			final EntityPigZombie pigman = new EntityPigZombie(creature.world);
			pigman.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.GOLDEN_AXE));
			pigman.setLocationAndAngles(creature.posX, creature.posY, creature.posZ, creature.rotationYaw, creature.rotationPitch);
			pigman.setNoAI(creature.isAIDisabled());
			if (creature.hasCustomName()) {
				pigman.setCustomNameTag(creature.getCustomNameTag());
				pigman.setAlwaysRenderNameTag(creature.getAlwaysRenderNameTag());
			}
			creature.world.spawnEntity(pigman);
			creature.setDead();
		} else if (creature instanceof EntityCreeper)
			creature.onStruckByLightning(null);
		charged = true;
		return 1;
	}
	return charged ? 0 : 1;
}
 
Example 29
Project: Et-Futurum   File: ServerEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void spawnEvent(EntityJoinWorldEvent event) {
	if (event.entity instanceof EntityPig) {
		EntityPig pig = (EntityPig) event.entity;
		if (EtFuturum.enableBeetroot)
			pig.tasks.addTask(4, new EntityAITempt(pig, 1.2, ModItems.beetroot, false));
	} else if (event.entity instanceof EntityChicken) {
		EntityChicken chicken = (EntityChicken) event.entity;
		if (EtFuturum.enableBeetroot)
			chicken.tasks.addTask(3, new EntityAITempt(chicken, 1.0D, ModItems.beetroot_seeds, false));
	} else if (event.entity instanceof EntityWolf) {
		EntityWolf wolf = (EntityWolf) event.entity;
		if (EtFuturum.enableRabbit)
			wolf.targetTasks.addTask(4, new EntityAITargetNonTamed(wolf, EntityRabbit.class, 200, false));
	} else if (event.entity instanceof EntityVillager) {
		EntityVillager villager = (EntityVillager) event.entity;
		for (Object obj : villager.tasks.taskEntries) {
			EntityAITaskEntry entry = (EntityAITaskEntry) obj;
			if (entry.action instanceof EntityAIOpenDoor) {
				villager.tasks.removeTask(entry.action);
				villager.tasks.addTask(entry.priority, new EntityAIOpenCustomDoor(villager, true));
				break;
			}
		}
	}
}
 
Example 30
Project: Et-Futurum   File: ServerEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void interactEntityEvent(EntityInteractEvent event) {
	ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
	if (stack == null)
		return;
	if (!(event.target instanceof EntityAnimal))
		return;

	EntityAnimal animal = (EntityAnimal) event.target;
	if (!animal.isChild()) {
		if (animal instanceof EntityPig) {
			if (stack.getItem() == ModItems.beetroot && EtFuturum.enableBeetroot)
				setAnimalInLove(animal, event.entityPlayer, stack);
		} else if (animal instanceof EntityChicken)
			if (stack.getItem() == ModItems.beetroot_seeds && EtFuturum.enableBeetroot)
				setAnimalInLove(animal, event.entityPlayer, stack);
	} else if (EtFuturum.enableBabyGrowthBoost && isFoodItem(animal, stack))
		feedBaby(animal, event.entityPlayer, stack);
}
 
Example 31
Project: It-s-About-Time-Minecraft-Mod   File: EntityVelociraptor.java   View source code 6 votes vote down vote up
public EntityVelociraptor(World world)
  {
      super(world);
      this.setSize(1F, 0.6F);
      isCarnivore = true;
      minSize = 0.2F;
maxSize = 1.4F;
adultAge = 10;
maxAge = 16;
      this.tasks.addTask(8, new EntityAITempt(this, 1.2D, Items.chicken, false));
      this.tasks.addTask(10, new MobAIWatchClosestWhenAwake(this, EntityPlayer.class, 8.0F));
      this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityChicken.class, 200, false));
      this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityCow.class, 200, false));
      this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
      this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityCompsognathus.class, 200, false));
      this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityPig.class, 200, false));

      this.setTamed(false);
  }
 
Example 32
Project: Resilience-Client-Source   File: ItemCarrotOnAStick.java   View source code 6 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
    if (par3EntityPlayer.isRiding() && par3EntityPlayer.ridingEntity instanceof EntityPig)
    {
        EntityPig var4 = (EntityPig)par3EntityPlayer.ridingEntity;

        if (var4.getAIControlledByPlayer().isControlledByPlayer() && par1ItemStack.getMaxDamage() - par1ItemStack.getItemDamage() >= 7)
        {
            var4.getAIControlledByPlayer().boostSpeed();
            par1ItemStack.damageItem(7, par3EntityPlayer);

            if (par1ItemStack.stackSize == 0)
            {
                ItemStack var5 = new ItemStack(Items.fishing_rod);
                var5.setTagCompound(par1ItemStack.stackTagCompound);
                return var5;
            }
        }
    }

    return par1ItemStack;
}
 
Example 33
Project: Resilience-Client-Source   File: ItemSaddle.java   View source code 6 votes vote down vote up
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
public boolean itemInteractionForEntity(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, EntityLivingBase par3EntityLivingBase)
{
    if (par3EntityLivingBase instanceof EntityPig)
    {
        EntityPig var4 = (EntityPig)par3EntityLivingBase;

        if (!var4.getSaddled() && !var4.isChild())
        {
            var4.setSaddled(true);
            var4.worldObj.playSoundAtEntity(var4, "mob.horse.leather", 0.5F, 1.0F);
            --par1ItemStack.stackSize;
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 34
Project: ZeroQuest   File: BiomeGenRedSeed.java   View source code 6 votes vote down vote up
public BiomeGenRedSeed(int id) {
    super(id);
   	this.waterColorMultiplier = 0x003333;
    this.theBiomeDecorator.treesPerChunk = -999;
    this.theBiomeDecorator.flowersPerChunk = 4;
    this.theBiomeDecorator.grassPerChunk = 10;
    this.flowers.clear();
    this.addFlower(Blocks.red_flower,    4,  3);
    this.addFlower(Blocks.red_flower,    5,  3);
    this.addFlower(Blocks.red_flower,    6,  3);
    this.addFlower(Blocks.red_flower,    7,  3);
    this.addFlower(ModBlocks.nileBlackFlower,    0, 20);
    this.addFlower(ModBlocks.nileBlackFlower,    3, 20);
    this.addFlower(ModBlocks.nileBlackFlower,    8, 20);
    this.addFlower(ModBlocks.nileBlackFlower, 0, 30);
    this.spawnableMonsterList.clear();
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityHorse.class, 5, 2, 6));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityRedZertum.class, 100, 4, 4));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityChicken.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityCow.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityPig.class, 5, 1, 5)); 
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySpider.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityZombie.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySkeleton.class, 100, 4, 4));
}
 
Example 35
Project: ZeroQuest   File: BiomeGenBioZone.java   View source code 6 votes vote down vote up
public BiomeGenBioZone(int id) {
    super(id);
    this.theBiomeDecorator.generateLakes = true;
    this.theBiomeDecorator.treesPerChunk = 4;
    this.spawnableMonsterList.clear();
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySpider.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityZombie.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySkeleton.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityCreeper.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySlime.class, 100, 4, 4));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityZertum.class, 100, 4, 4));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityBat.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityChicken.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityCow.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityPig.class, 5, 1, 5)); 
}
 
Example 36
Project: ZeroQuest   File: BiomeGenNileSavanna.java   View source code 6 votes vote down vote up
public BiomeGenNileSavanna(int p_i45383_1_)
{
    super(p_i45383_1_);
    this.theBiomeDecorator.treesPerChunk = 1;
    this.theBiomeDecorator.flowersPerChunk = 4;
    this.theBiomeDecorator.grassPerChunk = 20;
    this.spawnableMonsterList.clear();
    this.spawnableCreatureList.clear();
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityZertum.class, 100, 4, 4));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityKortor.class, 100, 2, 3));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityPig.class, 5, 1, 5)); 
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySpider.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityZombie.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityCreeper.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySkeleton.class, 100, 4, 4));
   	this.waterColorMultiplier = 0x0099cc;
}
 
Example 37
Project: ZeroQuest   File: BiomeGenBlueNile.java   View source code 6 votes vote down vote up
public BiomeGenBlueNile(int id) {
    super(id);
    //topBlock = (byte)ModBlocks.nileGrass.blockID;
    //fillerBlock = (byte)ModBlocks.nileDirt.blockID;
   	this.waterColorMultiplier = 0x003333;
   	this.theBiomeDecorator.treesPerChunk = 9;
   	this.theBiomeDecorator.grassPerChunk = 3;
   	this.theBiomeDecorator.flowersPerChunk = 2;
    this.theBiomeDecorator.generateLakes = true;
    this.spawnableMonsterList.clear();
    this.spawnableCreatureList.add(new SpawnListEntry(EntityZertum.class, 100, 4, 4));
    this.spawnableCreatureList.add(new SpawnListEntry(EntityBat.class, 5, 1, 5));
    this.spawnableCreatureList.add(new SpawnListEntry(EntityChicken.class, 5, 1, 5));
    this.spawnableCreatureList.add(new SpawnListEntry(EntityCow.class, 5, 1, 5));
    this.spawnableCreatureList.add(new SpawnListEntry(EntityPig.class, 5, 1, 5)); 
}
 
Example 38
Project: ZeroQuest   File: BiomeGenDarkLand.java   View source code 6 votes vote down vote up
public BiomeGenDarkLand(int id) {
    super(id);
    //topBlock = (byte)ModBlocks.nileGrass.blockID;
    //fillerBlock = (byte)ModBlocks.nileDirt.blockID;
   	this.waterColorMultiplier = 0x666600;
   	this.theBiomeDecorator.treesPerChunk = 1;
   	this.theBiomeDecorator.grassPerChunk = 1;
   	this.theBiomeDecorator.flowersPerChunk = -999;
    this.theBiomeDecorator.generateLakes = true;
    this.spawnableMonsterList.clear();
    this.spawnableCreatureList.add(new SpawnListEntry(EntityDarkZertum.class, 100, 4, 4));
    this.spawnableCreatureList.add(new SpawnListEntry(EntityBat.class, 5, 1, 5));
    this.spawnableCreatureList.add(new SpawnListEntry(EntityChicken.class, 5, 1, 5));
    this.spawnableCreatureList.add(new SpawnListEntry(EntityCow.class, 5, 1, 5));
    this.spawnableCreatureList.add(new SpawnListEntry(EntityPig.class, 5, 1, 5)); 
}
 
Example 39
Project: ZeroQuest   File: BiomeGenRedSeed.java   View source code 6 votes vote down vote up
public BiomeGenRedSeed(int id) {
    super(id);
   	this.waterColorMultiplier = 0x003333;
    this.theBiomeDecorator.treesPerChunk = -999;
    this.theBiomeDecorator.flowersPerChunk = 4;
    this.theBiomeDecorator.grassPerChunk = 10;
    this.flowers.clear();
    this.addFlower(Blocks.red_flower.getDefaultState(), 4);
    this.addFlower(ModBlocks.nileBlackFlower.getDefaultState(), 90);
    this.spawnableMonsterList.clear();
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityHorse.class, 5, 2, 6));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityChicken.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityCow.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityPig.class, 5, 1, 5)); 
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySpider.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityZombie.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySkeleton.class, 100, 4, 4));
}
 
Example 40
Project: ZeroQuest   File: BiomeGenBioZone.java   View source code 6 votes vote down vote up
public BiomeGenBioZone(int id) {
    super(id);
    this.theBiomeDecorator.generateLakes = true;
    this.theBiomeDecorator.treesPerChunk = 4;
    this.spawnableMonsterList.clear();
    this.addFlower(ModBlocks.nileBlueFlower.getDefaultState(), 90);
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySpider.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityZombie.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySkeleton.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityCreeper.class, 100, 4, 4));
    this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySlime.class, 100, 4, 4));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityBat.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityChicken.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityCow.class, 5, 1, 5));
    this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityPig.class, 5, 1, 5)); 
}