当前位置: 首页>>代码示例>>Java>>正文


Java EntityPig类代码示例

本文整理汇总了Java中net.minecraft.entity.passive.EntityPig的典型用法代码示例。如果您正苦于以下问题:Java EntityPig类的具体用法?Java EntityPig怎么用?Java EntityPig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EntityPig类属于net.minecraft.entity.passive包,在下文中一共展示了EntityPig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onItemRightClick

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:27,代码来源:ItemCarrotOnAStick.java

示例2: itemInteractionForEntity

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:24,代码来源:ItemSaddle.java

示例3: spawnEvent

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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;
			}
		}
	}
}
 
开发者ID:jm-organization,项目名称:connor41-etfuturum2,代码行数:27,代码来源:ServerEventHandler.java

示例4: interactEntityEvent

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:jm-organization,项目名称:connor41-etfuturum2,代码行数:20,代码来源:ServerEventHandler.java

示例5: itemInteractionForEntity

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:24,代码来源:ItemSaddle.java

示例6: onItemRightClick

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
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);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:25,代码来源:ItemCarrotOnAStick.java

示例7: itemInteractionForEntity

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:24,代码来源:ItemSaddle.java

示例8: test_rotationYaw_is_readable

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:wizards-of-lua,项目名称:wizards-of-lua,代码行数:22,代码来源:EntityTest.java

示例9: test_rotationYaw_is_writable

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:wizards-of-lua,项目名称:wizards-of-lua,代码行数:23,代码来源:EntityTest.java

示例10: test_rotationPitch_is_readable

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:wizards-of-lua,项目名称:wizards-of-lua,代码行数:22,代码来源:EntityTest.java

示例11: test_rotationPitch_is_writable

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:wizards-of-lua,项目名称:wizards-of-lua,代码行数:23,代码来源:EntityTest.java

示例12: test_eyeHeight_is_readable

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:wizards-of-lua,项目名称:wizards-of-lua,代码行数:22,代码来源:EntityTest.java

示例13: test_motion_is_writable

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:wizards-of-lua,项目名称:wizards-of-lua,代码行数:22,代码来源:EntityTest.java

示例14: test_tags_is_writable

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:wizards-of-lua,项目名称:wizards-of-lua,代码行数:26,代码来源:EntityTest.java

示例15: test_addTag

import net.minecraft.entity.passive.EntityPig; //导入依赖的package包/类
@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);
}
 
开发者ID:wizards-of-lua,项目名称:wizards-of-lua,代码行数:25,代码来源:EntityTest.java


注:本文中的net.minecraft.entity.passive.EntityPig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。