本文整理汇总了Java中net.minecraft.world.World.spawnEntity方法的典型用法代码示例。如果您正苦于以下问题:Java World.spawnEntity方法的具体用法?Java World.spawnEntity怎么用?Java World.spawnEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.world.World
的用法示例。
在下文中一共展示了World.spawnEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performEffect
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
if (rtrace.typeOfHit == Type.ENTITY && rtrace.entityHit instanceof EntityLivingBase) {
EntityLivingBase entity = (EntityLivingBase) rtrace.entityHit;
EnumHand hand = null;
if (!entity.getHeldItemMainhand().isEmpty()) hand = EnumHand.MAIN_HAND;
else if (!entity.getHeldItemOffhand().isEmpty()) hand = EnumHand.OFF_HAND;
if (hand != null) {
ItemStack stack = entity.getHeldItem(hand).copy();
entity.setHeldItem(hand, ItemStack.EMPTY);
if (!(entity instanceof EntityPlayer) && stack.isItemStackDamageable() && stack.getItemDamage() == 0) {
stack.setItemDamage((int) (stack.getMaxDamage() * (0.5D + 0.5D * Math.random())));
}
EntityItem ei = new EntityItem(world, entity.posX, entity.posY, entity.posZ, stack);
ei.setPickupDelay(200);
ei.setNoDespawn();
if (!world.isRemote) world.spawnEntity(ei);
}
}
}
示例2: onItemRightClick
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
if (!player.capabilities.isCreativeMode)
{
stack.shrink(1);
}
world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!world.isRemote)
{
EntityCurseOrb entity = new EntityCurseOrb(world, player);
entity.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
world.spawnEntity(entity);
}
// playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult(EnumActionResult.SUCCESS, stack);
}
示例3: onBlockActivated
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote && world.getTileEntity(pos) instanceof TilePedestal) {
TilePedestal pedestal = (TilePedestal) world.getTileEntity(pos);
if (pedestal.getStack().func_190926_b()) {
if (!player.getHeldItem(hand).func_190926_b()) {
pedestal.setStack(player.getHeldItem(hand));
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.field_190927_a);
player.openContainer.detectAndSendChanges();
}
} else {
ItemStack stack = pedestal.getStack();
pedestal.setStack(ItemStack.field_190927_a);
if (!player.inventory.addItemStackToInventory(stack)) {
EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack);
world.spawnEntity(entityItem);
} else {
player.openContainer.detectAndSendChanges();
}
}
}
return true;
}
示例4: onItemUse
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (!worldIn.isRemote) {
ItemStack stack = player.getHeldItem(hand);
if (stack.getMetadata() == 1 && !(worldIn.getTileEntity(pos) instanceof TileFaerieHome)) {
NBTTagCompound nbt = stack.getTagCompound();
if (nbt == null) return EnumActionResult.FAIL;
EntityFaerie faerie = new EntityFaerie(worldIn, nbt.getDouble("max_health"), nbt.getInteger("type"), nbt.getFloat("size"), nbt.getInteger("level"), nbt.getInteger("current_exp"));
faerie.setPosition((double) pos.getX(), (double) pos.up().getY(), (double) pos.getZ());
worldIn.spawnEntity(faerie);
player.setHeldItem(hand, new ItemStack(GeneraItems.ItemGlassJar, 1, 0));
return EnumActionResult.SUCCESS;
}
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
示例5: updateTick
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
super.updateTick(worldIn, pos, state, rand);
if (!worldIn.isRemote) {
if (state.getValue(AGE) == 2) {
EntityFaerie faerie = new EntityFaerie(worldIn, 4.0D, 0, 0.1F, 1);
faerie.setPosition((double) pos.getX(), (double) pos.up().getY(), (double) pos.getZ());
worldIn.spawnEntity(faerie);
}
if (!(worldIn.getBiome(pos) == Biomes.FOREST ||
worldIn.getBiome(pos) == Biomes.FOREST_HILLS ||
worldIn.getBiome(pos) == Biomes.TAIGA ||
worldIn.getBiome(pos) == Biomes.TAIGA_HILLS) && state.getValue(AGE) >= 1) {
worldIn.setBlockState(pos, state.withProperty(AGE, 0));
}
}
}
示例6: throwProjectile
import net.minecraft.world.World; //导入方法依赖的package包/类
private void throwProjectile(EntityPlayer player, EnumHand hand, World world) {
ItemStack heldItem = player.getHeldItem(hand);
int charge = getCharge(heldItem);
if (charge <= 0) {
MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_no_charge"), (EntityPlayerMP) player);
return;
}
setCharge(heldItem, charge-1);
List<TeleportDestination> destinations = getDestinations(heldItem);
int current = getCurrentDestination(heldItem);
if (current == -1) {
MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_no_destination"), (EntityPlayerMP) player);
} else if (destinations.get(current) == null) {
MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_bad_destination"), (EntityPlayerMP) player);
} else {
EntityProjectile projectile = new EntityProjectile(world, player);
projectile.setDestination(destinations.get(current));
projectile.setPlayerId(player.getUniqueID());
projectile.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
world.spawnEntity(projectile);
}
}
示例7: onItemRightClick
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ItemStack itemstack = playerIn.getHeldItem(hand);
ItemStack copy = playerIn.capabilities.isCreativeMode ? itemstack.copy() : itemstack.splitStack(1);
playerIn.playSound(SoundEvents.ENTITY_LINGERINGPOTION_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!worldIn.isRemote) {
EntityBrew brew = new EntityBrew(worldIn, playerIn, copy, EntityBrew.BrewDispersion.LINGER);
brew.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
worldIn.spawnEntity(brew);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
}
示例8: onItemUse
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (hand != EnumHand.MAIN_HAND) return EnumActionResult.PASS;
if (!world.isRemote) {
ItemStack iStack = player.getHeldItemMainhand();
EntityDrone drone = new EntityDrone(world, player);
BlockPos placePos = pos.offset(facing);
drone.setPosition(placePos.getX() + 0.5, placePos.getY() + 0.5, placePos.getZ() + 0.5);
world.spawnEntity(drone);
NBTTagCompound stackTag = iStack.getTagCompound();
NBTTagCompound entityTag = new NBTTagCompound();
drone.writeEntityToNBT(entityTag);
if (stackTag != null) {
entityTag.setTag("widgets", stackTag.getTagList("widgets", 10).copy());
entityTag.setFloat("currentAir", stackTag.getFloat("currentAir"));
entityTag.setInteger("color", stackTag.getInteger("color"));
entityTag.setTag(ChargeableItemHandler.NBT_UPGRADE_TAG, stackTag.getCompoundTag(ChargeableItemHandler.NBT_UPGRADE_TAG));
}
drone.readEntityFromNBT(entityTag);
if (iStack.hasDisplayName()) drone.setCustomNameTag(iStack.getDisplayName());
drone.naturallySpawned = false;
//TODO 1.8 check if valid replacement drone.onSpawnWithEgg(null);
drone.onInitialSpawn(world.getDifficultyForLocation(placePos), null);
iStack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
示例9: onItemUse
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack iStack = player.getHeldItem(hand);
if (!world.isRemote) {
EntityDrone drone = new EntityLogisticsDrone(world, player);
BlockPos placePos = pos.offset(facing);
drone.setPosition(placePos.getX() + 0.5, placePos.getY() + 0.5, placePos.getZ() + 0.5);
world.spawnEntity(drone);
NBTTagCompound stackTag = iStack.getTagCompound();
NBTTagCompound entityTag = new NBTTagCompound();
drone.writeEntityToNBT(entityTag);
if (stackTag != null) {
entityTag.setFloat("currentAir", stackTag.getFloat("currentAir"));
entityTag.setInteger("color", stackTag.getInteger("color"));
entityTag.setTag(ChargeableItemHandler.NBT_UPGRADE_TAG, stackTag.getCompoundTag(ChargeableItemHandler.NBT_UPGRADE_TAG));
}
drone.readEntityFromNBT(entityTag);
addLogisticsProgram(pos, drone.progWidgets);
if (iStack.hasDisplayName()) drone.setCustomNameTag(iStack.getDisplayName());
drone.naturallySpawned = false;
//TODO 1.8 check if valid replacement drone.onSpawnWithEgg(null);
drone.onInitialSpawn(world.getDifficultyForLocation(placePos), null);
iStack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
示例10: apply
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public void apply(World world, BlockPos pos, EntityLivingBase entity, int amplifier, int tick) {
if (entity instanceof EntityMooshroom) {
EntityCow cow = new EntityCow(world);
cow.setPosition(pos.getX(), pos.getY(), pos.getZ());
entity.setDead();
world.spawnEntity(cow);
}
}
示例11: drop
import net.minecraft.world.World; //导入方法依赖的package包/类
private static void drop(World world, BlockPos pos, BlockPos newPos) {
EntityFallingBlock fallingBlock = new EntityFallingBlock(world, newPos.getX(), newPos.getY(), newPos.getZ(), world.getBlockState(pos));
fallingBlock.setEntityBoundingBox(new AxisAlignedBB(newPos.add(0, 0, 0), newPos.add(1, 1, 1)));
fallingBlock.fallTime = 1;
world.spawnEntity(fallingBlock);
world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
示例12: addEntitiesToWorld
import net.minecraft.world.World; //导入方法依赖的package包/类
private void addEntitiesToWorld(World worldIn, BlockPos pos, Mirror mirrorIn, Rotation rotationIn, @Nullable StructureBoundingBox aabb)
{
for (Template.EntityInfo template$entityinfo : this.entities)
{
BlockPos blockpos = transformedBlockPos(template$entityinfo.blockPos, mirrorIn, rotationIn).add(pos);
if (aabb == null || aabb.isVecInside(blockpos))
{
NBTTagCompound nbttagcompound = template$entityinfo.entityData;
Vec3d vec3d = transformedVec3d(template$entityinfo.pos, mirrorIn, rotationIn);
Vec3d vec3d1 = vec3d.addVector((double)pos.getX(), (double)pos.getY(), (double)pos.getZ());
NBTTagList nbttaglist = new NBTTagList();
nbttaglist.appendTag(new NBTTagDouble(vec3d1.x));
nbttaglist.appendTag(new NBTTagDouble(vec3d1.y));
nbttaglist.appendTag(new NBTTagDouble(vec3d1.z));
nbttagcompound.setTag("Pos", nbttaglist);
nbttagcompound.setUniqueId("UUID", UUID.randomUUID());
Entity entity;
try
{
entity = EntityList.createEntityFromNBT(nbttagcompound, worldIn);
}
catch (Exception var15)
{
entity = null;
}
if (entity != null)
{
float f = entity.getMirroredYaw(mirrorIn);
f = f + (entity.rotationYaw - entity.getRotatedYaw(rotationIn));
entity.setLocationAndAngles(vec3d1.x, vec3d1.y, vec3d1.z, f, entity.rotationPitch);
worldIn.spawnEntity(entity);
}
}
}
}
示例13: onFinish
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public void onFinish(EntityPlayer player, IRitualHandler tile, World world, BlockPos pos, NBTTagCompound data) {
if (!world.isRemote) {
EntityWitch witch = new EntityWitch(world);
witch.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), (float) (Math.random() * 360), 0);
witch.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(witch)), (IEntityLivingData) null);
world.spawnEntity(witch);
if (Math.random() < 0.1)
witch.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 6000, 2, false, false));
}
}
示例14: throwREP
import net.minecraft.world.World; //导入方法依赖的package包/类
public void throwREP(ItemStack itemstack, World world, EntityPlayer player) {
if (REPThrowTimeout > 0) {
return;
}
if (!player.capabilities.isCreativeMode) {
itemstack.shrink(1);
}
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F));
activeREP = new EntityREP(world, player);
world.spawnEntity(activeREP);
REPThrowTimeout = 40;
}
示例15: onCastFinish
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public void onCastFinish(World world, EntityPlayer player, ItemStack stack) {
if (!world.isRemote && consumePower(player)) {
Vec3d lookVec = player.getLookVec();
double x = player.posX + lookVec.xCoord;
double y = player.posY + lookVec.yCoord + player.eyeHeight;
double z = player.posZ + lookVec.zCoord;
EntityWitheringBolt bolt = new EntityWitheringBolt(world, player, 1, x, y, z);
bolt.setAim(player, player.rotationPitch, player.rotationYaw, 0.75F, 0.08F);
world.spawnEntity(bolt);
}
}