Java Code Examples for net.minecraft.world.World#spawnEntity()
The following examples show how to use
net.minecraft.world.World#spawnEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicSolarPanelBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
private void dropInventory(World world, BlockPos blockPos) { BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof BasicSolarPanelBlockEntity) { BasicSolarPanelBlockEntity basicSolarPanelBlockEntity = (BasicSolarPanelBlockEntity) blockEntity; for (int i = 0; i < basicSolarPanelBlockEntity.getInventory().getSize(); i++) { ItemStack itemStack = basicSolarPanelBlockEntity.getInventory().getStack(i); if (itemStack != null) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack)); } } } } }
Example 2
Source File: BlockPress.java From AdvancedRocketry with MIT License | 6 votes |
private void checkForMove(World worldIn, BlockPos pos, IBlockState state) { EnumFacing enumfacing = EnumFacing.DOWN; boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing); ItemStack stack; if (flag && (stack = getRecipe(worldIn, pos, state)) != null && !((Boolean)state.getValue(EXTENDED)).booleanValue()) { worldIn.setBlockToAir(pos.down()); if(!worldIn.isRemote) worldIn.spawnEntity(new EntityItem(worldIn, pos.getX() + 0.5, pos.getY() - 0.5, pos.getZ() + 0.5, stack)); if ((new BlockPistonStructureHelper(worldIn, pos, enumfacing, true)).canMove()) { worldIn.addBlockEvent(pos, this, 0, enumfacing.getIndex()); } } else if (!flag && ((Boolean)state.getValue(EXTENDED)).booleanValue()) { worldIn.addBlockEvent(pos, this, 1, enumfacing.getIndex()); } }
Example 3
Source File: OxygenCollectorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof OxygenCollectorBlockEntity) { OxygenCollectorBlockEntity be = (OxygenCollectorBlockEntity) blockEntity; for (int i = 0; i < be.getInventory().getSize(); i++) { ItemStack itemStack = be.getInventory().getStack(i); if (itemStack != null) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack)); } } } } }
Example 4
Source File: ElectricCompressorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof ElectricCompressorBlockEntity) { ElectricCompressorBlockEntity be = (ElectricCompressorBlockEntity) blockEntity; for (int i = 0; i < be.getInventory().getSize(); i++) { ItemStack itemStack = be.getInventory().getStack(i); if (!itemStack.isEmpty()) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack.copy())); } } } } }
Example 5
Source File: ItemBomb.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (!world.isRemote) { EntityBomb bomb = new EntityBomb(world, player); bomb.setBombItem(stack); bomb.setPosition(player.posX, player.posY + player.eyeHeight, player.posZ); bomb.shoot(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f); stack.shrink(1); world.spawnEntity(bomb); bomb.velocityChanged = true; } player.getCooldownTracker().setCooldown(this, 20); return new ActionResult<>(EnumActionResult.PASS, stack); }
Example 6
Source File: ItemGravityRay.java From Production-Line with MIT License | 6 votes |
/** * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount */ @Override public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityLivingBase player, int itemInUseCount) { if (ElectricItem.manager.getCharge(itemStack) >= 100) { int i = this.getMaxItemUseDuration(itemStack) - itemInUseCount; float damge = (float) i / 20.0F; damge = (damge * damge + damge * 2.0F) / 3.0F; if ((double)damge < 0.1D) { return; } if (damge > 1.0F) { damge = 1.0F; } world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + damge * 0.5F); if (!(player instanceof EntityPlayer && ((EntityPlayer) player).capabilities.isCreativeMode)) { ElectricItem.manager.discharge(itemStack, 100, this.tier, false, true, false); } if (!world.isRemote) { world.spawnEntity(new EntityRay(world, player, damge * 2.0F)); } } }
Example 7
Source File: BlockThatch.java From TFC2 with GNU General Public License v3.0 | 5 votes |
@Override public void createFallingEntity(World world, BlockPos pos, IBlockState state) { world.setBlockToAir(pos); EntityItem ei = new EntityItem(world, pos.getX()+0.5, pos.getY(), pos.getZ()+0.5, new ItemStack(TFCItems.Straw, 1+world.rand.nextInt(3))); world.spawnEntity(ei); }
Example 8
Source File: ValkyrienUtils.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
public static void fixEntityToShip(Entity toFix, Vector posInLocal, PhysicsObject mountingShip) { World world = mountingShip.world(); EntityMountable entityMountable = new EntityMountable(world, posInLocal.toVec3d(), CoordinateSpaceType.SUBSPACE_COORDINATES, mountingShip.getReferenceBlockPos()); world.spawnEntity(entityMountable); toFix.startRiding(entityMountable); }
Example 9
Source File: MixinServerPlayerEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Redirect(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z")) private boolean hookDropItemForCapture(World world, Entity entity) { ItemEntity itemEntity = (ItemEntity) entity; IForgeEntity forgeEntity = (IForgeEntity) this; if (forgeEntity.captureDrops() != null) { forgeEntity.captureDrops().add(itemEntity); return true; } else { return world.spawnEntity(itemEntity); } }
Example 10
Source File: ItemFairy.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@NotNull @Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); if (stack.isEmpty()) return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); if (worldIn.isRemote) return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); FairyData object = FairyData.deserialize(NBTHelper.getCompound(stack, "fairy")); if (object == null) return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); TileEntity tileEntity = worldIn.getTileEntity(pos); if (tileEntity instanceof TileJar) { TileJar jar = (TileJar) tileEntity; if (jar.fairy != null) return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); jar.fairy = object; jar.markDirty(); worldIn.checkLight(pos); } else { BlockPos offsetpos = pos.offset(facing); EntityFairy entity = new EntityFairy(worldIn, object); entity.setPosition(offsetpos.getX() + 0.5, offsetpos.getY() + 0.5, offsetpos.getZ() + 0.5); entity.originPos = offsetpos; worldIn.spawnEntity(entity); } stack.shrink(1); worldIn.playSound(pos.getX(), pos.getY(), pos.getZ(), ModSounds.FAIRY, SoundCategory.BLOCKS, 1, 1, false); return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); }
Example 11
Source File: MixinEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Redirect(method = "dropStack(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z")) private boolean hookDropStackForCapture(World world, Entity entity) { ItemEntity itemEntity = (ItemEntity) entity; if (captureDrops() != null) { captureDrops().add(itemEntity); return true; } else { return world.spawnEntity(itemEntity); } }
Example 12
Source File: Core.java From TFC2 with GNU General Public License v3.0 | 5 votes |
public static void dropItem(World world, double posX, double posY, double posZ, ItemStack is) { EntityItem ei = new EntityItem(world, posX, posY, posZ, is); ei.motionX = -0.07+world.rand.nextFloat() * 0.14; ei.motionY = 0.15; ei.motionZ = -0.07+world.rand.nextFloat() * 0.14; world.spawnEntity(ei); }
Example 13
Source File: StructureTofuVillagePieces.java From TofuCraftReload with MIT License | 5 votes |
protected void spawnVillagers(World worldIn, StructureBoundingBox structurebb, int x, int y, int z, int count,int profession) { if (this.villagersSpawned < count) { for (int i = this.villagersSpawned; i < count; ++i) { int j = this.getXWithOffset(x + i, z); int k = this.getYWithOffset(y); int l = this.getZWithOffset(x + i, z); if (!structurebb.isVecInside(new BlockPos(j, k, l))) { break; } ++this.villagersSpawned; if (this.field_189929_i) { EntityZombieVillager entityzombie = new EntityZombieVillager(worldIn); entityzombie.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F); entityzombie.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityzombie)), (IEntityLivingData) null); entityzombie.enablePersistence(); worldIn.spawnEntity(entityzombie); } else { EntityTofunian entityvillager = new EntityTofunian(worldIn); entityvillager.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F); entityvillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData) null); entityvillager.setTofuProfession(profession); worldIn.spawnEntity(entityvillager); } } } }
Example 14
Source File: BlockSeat.java From AdvancedRocketry with MIT License | 5 votes |
@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) { List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(player, new AxisAlignedBB(pos, pos.add(1,1,1))); //Try to mount player to dummy entity in the block for(Entity e : list) { if(e instanceof EntityDummy) { if(!e.getPassengers().isEmpty()) { return true; } else { //Ensure that the entity is in the correct position e.setPosition(pos.getX() + 0.5f, pos.getY() + 0.2f, pos.getZ() + 0.5f); player.startRiding(e); return true; } } } EntityDummy entity = new EntityDummy(world, pos.getX() + 0.5f, pos.getY() + 0.2f, pos.getZ() + 0.5f); world.spawnEntity(entity); player.startRiding(entity); } return true; }
Example 15
Source File: ToolUtility.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private static void dropListOfItems(World world, BlockPos pos, List<ItemStack> drops) { Random rand = new Random(); for (ItemStack stack : drops) { float f = 0.7F; double offX = (rand.nextFloat() * f) + (1.0F - f) * 0.5D; double offY = (rand.nextFloat() * f) + (1.0F - f) * 0.5D; double offZ = (rand.nextFloat() * f) + (1.0F - f) * 0.5D; EntityItem entityItem = new EntityItem(world, pos.getX() + offX, pos.getY() + offY, pos.getZ() + offZ, stack); entityItem.setDefaultPickupDelay(); world.spawnEntity(entityItem); } }
Example 16
Source File: ItemOwlEgg.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) { ItemStack itemStackIn = playerIn.getHeldItem(hand); if (!playerIn.capabilities.isCreativeMode) { itemStackIn.shrink(1); } worldIn.playSound(playerIn, playerIn.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.BLOCKS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!worldIn.isRemote) { EntityOwlEgg entityEgg = new EntityOwlEgg(worldIn, playerIn); //without setHeading the egg just falls to the players feet entityEgg.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, PITCHOFFSET, VELOCITY_DEFAULT, INACCURACY_DEFAULT); worldIn.spawnEntity(entityEgg); } return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn); }
Example 17
Source File: VillageHandlerBarracks.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
@Override protected boolean specialBlockHandling(World world, String c, int x, int y, int z) { if (!c.equals("xx")) { return false; } setBlockState(world, Blocks.AIR.getDefaultState(), x, y, z, boundingBox); int j = this.getXWithOffset(x, z); int k = this.getYWithOffset(y); int l = this.getZWithOffset(x, z); /* * if (!structurebb.isVecInside(new BlockPos(j, k, l))) { return; } */ EntityArmorStand stand = new EntityArmorStand(world); stand.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 90F, 0.0F); world.spawnEntity(stand); List<String> entities = new ArrayList<String>(); entities.add(ToroQuest.MODID + ":" + EntityGuard.NAME); specialHandlingForSpawner(world, "xx", c, x, y, z, entities); return true; }
Example 18
Source File: BlockConfusingCharge.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
protected void onIgnitedByNeighbour(World world, int x, int y, int z, EntityLivingBase placedBy) { EntityPrimedCharge entity = new EntityPrimedCharge(this, world, x + 0.5F, y + 0.5F, z + 0.5F, placedBy); entity.setFuse(world.rand.nextInt(entity.getFuse() / 4) + entity.getFuse() / 8); world.spawnEntity(entity); }
Example 19
Source File: CraftingFluidBlock.java From the-hallow with MIT License | 4 votes |
private void spawnCraftingResult(World world, BlockPos pos, ItemStack result) { ItemEntity itemEntity = new ItemEntity(world, pos.getX() + .5, pos.getY() + 1, pos.getZ() + .5, result); world.spawnEntity(itemEntity); // todo: add particles and/or an animation when dropping the recipe result }
Example 20
Source File: MageTowerGenerator.java From ToroQuest with GNU General Public License v3.0 | 4 votes |
private void spawnMage(World world, BlockPos pos) { EntityMage e = new EntityMage(world); e.setPosition(pos.getX() + 3, pos.getY() + (floors * floorHieght) + 1, pos.getZ() + 3); world.spawnEntity(e); }