Java Code Examples for net.minecraft.block.Block#spawnAsEntity()
The following examples show how to use
net.minecraft.block.Block#spawnAsEntity() .
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: PipeCoverableImplementation.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public final boolean removeCover(EnumFacing side) { Preconditions.checkNotNull(side, "side"); CoverBehavior coverBehavior = getCoverAtSide(side); if (coverBehavior == null) { return false; } List<ItemStack> drops = coverBehavior.getDrops(); coverBehavior.onRemoved(); this.coverBehaviors[side.getIndex()] = null; for (ItemStack dropStack : drops) { Block.spawnAsEntity(getWorld(), getPos(), dropStack); } writeCustomData(2, buffer -> buffer.writeByte(side.getIndex())); holder.setConnectionBlocked(AttachmentType.COVER, side, false); holder.notifyBlockUpdate(); holder.markAsDirty(); return true; }
Example 2
Source File: MetaTileEntity.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public final boolean removeCover(EnumFacing side) { Preconditions.checkNotNull(side, "side"); CoverBehavior coverBehavior = getCoverAtSide(side); if (coverBehavior == null) { return false; } List<ItemStack> drops = coverBehavior.getDrops(); coverBehavior.onRemoved(); this.coverBehaviors[side.getIndex()] = null; for (ItemStack dropStack : drops) { Block.spawnAsEntity(getWorld(), getPos(), dropStack); } writeCustomData(-6, buffer -> buffer.writeByte(side.getIndex())); if (getHolder() != null) { getHolder().notifyBlockUpdate(); getHolder().markDirty(); } onCoverPlacementUpdate(); return true; }
Example 3
Source File: ChoppingBlockTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void spawnItemStack(World worldIn, double x, double y, double z, ItemStack stack) { while (stack.getCount() > 0) { int i = /*RANDOM.nextInt(3) +*/ 1; if (i > stack.getCount()) { i = stack.getCount(); } ItemStack copy = stack.copy(); copy.setCount(i); stack.grow(-i); Block.spawnAsEntity(worldIn, new BlockPos(x, y, z), stack); } }
Example 4
Source File: BlockOben.java From Sakura_mod with MIT License | 5 votes |
@Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntityOben te = (TileEntityOben) worldIn.getTileEntity(pos); IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); if (inventory != null && inventory.getStackInSlot(0) != ItemStack.EMPTY) { Block.spawnAsEntity(worldIn, pos, inventory.getStackInSlot(0)); ((IItemHandlerModifiable) inventory).setStackInSlot(0, ItemStack.EMPTY); } super.breakBlock(worldIn, pos, state); }
Example 5
Source File: BlockOben.java From Sakura_mod with MIT License | 5 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) return true; ItemStack stack = playerIn.getHeldItem(hand); TileEntity tile = worldIn.getTileEntity(pos); if (hand == EnumHand.MAIN_HAND) { if (tile instanceof TileEntityOben) { TileEntityOben tileEntity = (TileEntityOben) tile; if(!(tileEntity.getInventory().getStackInSlot(0)).isEmpty()&&!(stack.equals(tileEntity.getInventory().getStackInSlot(0)))){ Block.spawnAsEntity(worldIn, pos, tileEntity.getInventory().getStackInSlot(0)); tileEntity.getInventory().setStackInSlot(0, ItemStack.EMPTY); tileEntity.markDirty(); return true; } ItemStack campfireStack=stack.copy(); campfireStack.setCount(1); stack.shrink(1); tileEntity.getInventory().insertItem(0,campfireStack,false); tileEntity.markDirty(); return true; } } return true; }
Example 6
Source File: BlockCampfire.java From Sakura_mod with MIT License | 5 votes |
@Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { if (!keepInventory) { TileEntityCampfire te = (TileEntityCampfire) worldIn.getTileEntity(pos); IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); if (inventory != null && inventory.getStackInSlot(0) != ItemStack.EMPTY) { Block.spawnAsEntity(worldIn, pos, inventory.getStackInSlot(0)); ((IItemHandlerModifiable) inventory).setStackInSlot(0, ItemStack.EMPTY); } } super.breakBlock(worldIn, pos, state); }
Example 7
Source File: RenderBlockTileEntity.java From MiningGadgets with MIT License | 5 votes |
private void removeBlock() { if(world == null || world.isRemote) return; PlayerEntity player = world.getPlayerByUuid(playerUUID); if (player == null) return; int silk = 0; int fortune = 0; ItemStack tempTool = new ItemStack(ModItems.MININGGADGET.get()); // If silk is in the upgrades, apply it without a tier. if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.SILK)) { tempTool.addEnchantment(Enchantments.SILK_TOUCH, 1); silk = 1; } // FORTUNE_1 is eval'd against the basename so this'll support all fortune upgrades if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1)) { Optional<Upgrade> upgrade = UpgradeTools.getUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1); if (upgrade.isPresent()) { fortune = upgrade.get().getTier(); tempTool.addEnchantment(Enchantments.FORTUNE, fortune); } } List<ItemStack> drops = Block.getDrops(renderBlock, (ServerWorld) world, this.pos, null, player, tempTool); if ( blockAllowed ) { int exp = renderBlock.getExpDrop(world, pos, fortune, silk); boolean magnetMode = (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.MAGNET)); for (ItemStack drop : drops) { if (drop != null) { if (magnetMode) { int wasPickedUp = ForgeEventFactory.onItemPickup(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), drop), player); // 1 = someone allowed the event meaning it's handled, // -1 = someone blocked the event and thus we shouldn't drop it nor insert it // 0 = no body captured the event and we should handle it by hand. if( wasPickedUp == 0 ) { if (!player.addItemStackToInventory(drop)) Block.spawnAsEntity(world, pos, drop); } } else { Block.spawnAsEntity(world, pos, drop); } } } if (magnetMode) { if (exp > 0) player.giveExperiencePoints(exp); } else { if (exp > 0) renderBlock.getBlock().dropXpOnBlockBreak(world, pos, exp); } renderBlock.spawnAdditionalDrops(world, pos, tempTool); // Fixes silver fish basically... } world.removeTileEntity(this.pos); world.setBlockState(this.pos, Blocks.AIR.getDefaultState()); // Add to the break stats player.addStat(Stats.BLOCK_MINED.get(renderBlock.getBlock())); // Handle special cases if(SpecialBlockActions.getRegister().containsKey(renderBlock.getBlock())) SpecialBlockActions.getRegister().get(renderBlock.getBlock()).accept(world, pos, renderBlock); }
Example 8
Source File: BlockMachine.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos); if (metaTileEntity != null) { NonNullList<ItemStack> inventoryContents = NonNullList.create(); metaTileEntity.clearMachineInventory(inventoryContents); for (ItemStack itemStack : inventoryContents) { Block.spawnAsEntity(worldIn, pos, itemStack); } metaTileEntity.dropAllCovers(); metaTileEntity.onRemoval(); } super.breakBlock(worldIn, pos, state); }
Example 9
Source File: PipeCoverableImplementation.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public final void dropAllCovers() { for (EnumFacing coverSide : EnumFacing.VALUES) { CoverBehavior coverBehavior = coverBehaviors[coverSide.getIndex()]; if (coverBehavior == null) continue; List<ItemStack> drops = coverBehavior.getDrops(); coverBehavior.onRemoved(); for (ItemStack dropStack : drops) { Block.spawnAsEntity(getWorld(), getPos(), dropStack); } } }
Example 10
Source File: MetaTileEntity.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public final void dropAllCovers() { for (EnumFacing coverSide : EnumFacing.VALUES) { CoverBehavior coverBehavior = coverBehaviors[coverSide.getIndex()]; if (coverBehavior == null) continue; List<ItemStack> drops = coverBehavior.getDrops(); coverBehavior.onRemoved(); for (ItemStack dropStack : drops) { Block.spawnAsEntity(getWorld(), getPos(), dropStack); } } }
Example 11
Source File: CoverPump.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onRemoved() { NonNullList<ItemStack> drops = NonNullList.create(); MetaTileEntity.clearInventory(drops, fluidFilter.getFilterInventory()); for (ItemStack itemStack : drops) { Block.spawnAsEntity(coverHolder.getWorld(), coverHolder.getPos(), itemStack); } }
Example 12
Source File: CoverConveyor.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onRemoved() { NonNullList<ItemStack> drops = NonNullList.create(); MetaTileEntity.clearInventory(drops, itemFilterContainer.getFilterInventory()); for (ItemStack itemStack : drops) { Block.spawnAsEntity(coverHolder.getWorld(), coverHolder.getPos(), itemStack); } }
Example 13
Source File: CrowbarBehaviour.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private boolean tryBreakRailBlock(IBlockState blockState, World world, BlockPos blockPos, EntityPlayer player) { if (world.canMineBlockBody(player, blockPos) && blockState.getBlock().canHarvestBlock(world, blockPos, player)) { for (ItemStack drops : blockState.getBlock().getDrops(world, blockPos, blockState, 0)) { Block.spawnAsEntity(world, blockPos, drops); } blockState.getBlock().onBlockDestroyedByPlayer(world, blockPos, blockState); blockState.getBlock().onBlockHarvested(world, blockPos, blockState, player); blockState.getBlock().breakBlock(world, blockPos, blockState); world.setBlockToAir(blockPos); return true; } return false; }
Example 14
Source File: HoeBehaviour.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); if (player.canPlayerEdit(blockPos, facing, stack) && !world.isAirBlock(blockPos)) { IBlockState blockState = world.getBlockState(blockPos); if (blockState.getBlock() == Blocks.GRASS || blockState.getBlock() == Blocks.DIRT) { if (blockState.getBlock() == Blocks.GRASS && player.isSneaking()) { if (GTUtility.doDamageItem(stack, this.cost, false)) { if (world.rand.nextInt(3) == 0) { ItemStack grassSeed = ForgeHooks.getGrassSeed(world.rand, 0); Block.spawnAsEntity(world, blockPos.up(), grassSeed); } world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F); world.setBlockState(blockPos, Blocks.DIRT.getDefaultState() .withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT)); return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } } else if (blockState.getBlock() == Blocks.GRASS || blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT || blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.COARSE_DIRT) { if (GTUtility.doDamageItem(stack, this.cost, false)) { world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F); world.setBlockState(blockPos, Blocks.FARMLAND.getDefaultState()); return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } } } } return ActionResult.newResult(EnumActionResult.FAIL, stack); }
Example 15
Source File: BlockCampfire.java From Sakura_mod with MIT License | 4 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) return true; ItemStack stack = playerIn.getHeldItem(hand); TileEntity tile = worldIn.getTileEntity(pos); if (hand == EnumHand.MAIN_HAND) { if (tile instanceof TileEntityCampfire) { TileEntityCampfire tileEntityCampfire = (TileEntityCampfire) tile; if(tileEntityCampfire.getInventory().isItemValid(0,stack)&& tileEntityCampfire.getInventory().getStackInSlot(0).getCount() < 16){ ItemStack campfireStack=new ItemStack(stack.getItem(),1,stack.getMetadata()); stack.shrink(1); tileEntityCampfire.getInventory().insertItem(0,campfireStack,false); return true; } if(stack.getItem()==ItemLoader.POT){ worldIn.setBlockToAir(pos); worldIn.removeTileEntity(pos); worldIn.setBlockState(pos, BlockLoader.CAMPFIRE_POT_IDLE.getDefaultState()); stack.shrink(1); return true; } if (WorldUtil.isItemFuel(stack)) { tileEntityCampfire.setBurningTime(tileEntityCampfire.getBurningTime() + TileEntityFurnace.getItemBurnTime(stack)); setState(true, worldIn, pos); if(stack.getItem().hasContainerItem(stack)) stack = stack.getItem().getContainerItem(stack); else stack.shrink(1); return true; } if (stack.getItem() == Items.FLINT_AND_STEEL) { tileEntityCampfire.setBurningTime(tileEntityCampfire.getBurningTime() + 10000); setState(true, worldIn, pos); stack.damageItem(1, playerIn); return true; } if(stack.isEmpty()){ Block.spawnAsEntity(worldIn, pos, ((TileEntityCampfire) tile).getInventory().getStackInSlot(0)); ((TileEntityCampfire) tile).getInventory().setStackInSlot(0, ItemStack.EMPTY); return true; } } } return true; }