Java Code Examples for net.minecraft.world.World#notifyBlockUpdate()
The following examples show how to use
net.minecraft.world.World#notifyBlockUpdate() .
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: TemplateEnderUtilities.java From enderutilities with GNU Lesser General Public License v3.0 | 8 votes |
public void notifyBlocks(World world, BlockPos posStart) { for (TemplateEnderUtilities.TemplateBlockInfo blockInfo : this.blocks) { BlockPos pos = transformedBlockPos(this.placement, blockInfo.pos).add(posStart); IBlockState state = world.getBlockState(pos); if (blockInfo.tileEntityData != null) { TileEntity te = world.getTileEntity(pos); if (te != null) { te.markDirty(); } world.notifyBlockUpdate(pos, state, state, 7); } else { world.notifyNeighborsRespectDebug(pos, blockInfo.blockState.getBlock(), false); } } }
Example 2
Source File: BlockUtils.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
/** * Tries breaking a block safely and fires an event for it. * * @return Whether the block was successfully broken */ public static boolean breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nullable IBlockState oldState, @Nonnull EntityPlayerMP player) { if (!world.isBlockLoaded(pos)) return false; if (!(player instanceof FakePlayer) && !hasEditPermission(pos, player)) return false; if (oldState == null) oldState = world.getBlockState(pos); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, oldState, player); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) return false; TileEntity tile = world.getTileEntity(pos); Block block = oldState.getBlock(); if (block.removedByPlayer(oldState, world, pos, player, true)) { block.onPlayerDestroy(world, pos, oldState); block.harvestBlock(world, player, pos, oldState, tile, player.getHeldItemMainhand()); world.notifyBlockUpdate(pos, oldState, Blocks.AIR.getDefaultState(), 3); } else return false; return true; }
Example 3
Source File: GTBlockStorage.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean recolorBlock(World world, BlockPos pos, EnumFacing side, net.minecraft.item.EnumDyeColor color) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof IGTRecolorableStorageTile) { IGTRecolorableStorageTile colorTile = (IGTRecolorableStorageTile) tile; colorTile.setTileColor(color.getColorValue()); IBlockState state = tile.getWorld().getBlockState(tile.getPos()); world.notifyBlockUpdate(pos, state, state, 2); return true; } return false; }
Example 4
Source File: BlockUtils.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
/** * Places the specified block into the world at the specified position if it is possible to do so without violating permission restrictions. * * @return <tt>true</tt> if the specified block was successfully placed into the world */ public static boolean placeBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityPlayerMP player) { if (!world.isBlockLoaded(pos)) return false; if (!hasEditPermission(pos, player)) return false; BlockEvent.PlaceEvent event = new BlockEvent.PlaceEvent(BlockSnapshot.getBlockSnapshot(world, pos), Blocks.AIR.getDefaultState(), player, player.getActiveHand()); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) return false; world.setBlockState(pos, state); world.notifyBlockUpdate(pos, state, state, 3); return true; }
Example 5
Source File: MoveBlocks.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
/** * @param world * @param oldPos * @param newPos * @param physicsObjectOptional Used when we're using this to copy from world to physics object; * should be empty when other way around. */ public static void copyBlockToPos(World world, BlockPos oldPos, BlockPos newPos, Optional<PhysicsObject> physicsObjectOptional) { // To avoid any updates crap, just edit the chunk data array directly. // These look switched, but trust me they aren't IBlockState oldState = world.getBlockState(newPos); IBlockState newState = world.getBlockState(oldPos); // A hacky way to set the block state within the chunk while avoiding any block updates. Chunk chunkToSet = world.getChunk(newPos); int storageIndex = newPos.getY() >> 4; // Check that we're placing the block in a valid position if (storageIndex < 0 || storageIndex >= chunkToSet.storageArrays.length) { // Invalid position, abort! return; } if (chunkToSet.storageArrays[storageIndex] == Chunk.NULL_BLOCK_STORAGE) { chunkToSet.storageArrays[storageIndex] = new ExtendedBlockStorage(storageIndex << 4, true); } chunkToSet.storageArrays[storageIndex] .set(newPos.getX() & 15, newPos.getY() & 15, newPos.getZ() & 15, newState); // Only want to send the update to clients and nothing else, so we use flag 2. world.notifyBlockUpdate(newPos, oldState, newState, 2); // Pretty messy to put this here but it works. Basically the ship keeps track of which of its chunks are // actually being used for performance reasons. if (physicsObjectOptional.isPresent()) { int minChunkX = physicsObjectOptional.get() .getOwnedChunks() .minX(); int minChunkZ = physicsObjectOptional.get() .getOwnedChunks() .minZ(); } // Now that we've copied the block to the position, copy the tile entity copyTileEntityToPos(world, oldPos, newPos, physicsObjectOptional); }
Example 6
Source File: NEIServerPacketHandler.java From NotEnoughItems with MIT License | 5 votes |
private void handleMobSpawnerID(World world, BlockPos coord, String mobtype) { TileEntity tile = world.getTileEntity(coord); if (tile instanceof TileEntityMobSpawner) { ((TileEntityMobSpawner) tile).getSpawnerBaseLogic().setEntityId(new ResourceLocation(mobtype)); tile.markDirty(); IBlockState state = world.getBlockState(coord); world.notifyBlockUpdate(coord, state, state, 4); } }
Example 7
Source File: BlockTileRedstoneEmitter.java From AdvancedRocketry with MIT License | 5 votes |
public void setRedstoneState(World world, IBlockState state, BlockPos pos, boolean newState) { if(world.getBlockState(pos).getBlock() != this) return; world.setBlockState(pos, state.withProperty(STATE, newState)); world.notifyBlockUpdate(pos, state, state, 3); }
Example 8
Source File: BlockARHatch.java From AdvancedRocketry with MIT License | 5 votes |
public void setRedstoneState(World world, IBlockState bstate , BlockPos pos, boolean state) { if(bstate.getBlock() == this) { if(state && (bstate.getValue(VARIANT) & 8) == 0) { world.setBlockState(pos, bstate.withProperty(VARIANT, bstate.getValue(VARIANT) | 8)); world.notifyBlockUpdate(pos, bstate, bstate, 3); } else if(!state && (bstate.getValue(VARIANT) & 8) != 0) { world.setBlockState(pos, bstate.withProperty(VARIANT, bstate.getValue(VARIANT) & 7)); world.notifyBlockUpdate(pos, bstate, bstate, 3); } } }
Example 9
Source File: DebugModeTestBlockRange.java From AgriCraft with MIT License | 5 votes |
/** * This method allows the user to test what Block Positions are covered by the BlockRange * iterator. The expected result will be the full cuboid between opposing corner positions. Also * remember that the BlockRange min and max positions aren't necessarily the input positions. * * Usage: Right-click on two blocks to specify the opposite corners. Some blocks should get * replaced with free wool. Be careful. In case of terrible bugs, might destroy or overwrite * unexpected locations! */ @Override public void debugActionBlockClicked(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return; } Optional<BlockPos> startPos = getStartPos(stack); if (!startPos.isPresent()) { // This is the first click. Save 'pos' as the starting coordinate. setStartPos(stack, pos); player.sendMessage(new TextComponentString("Starting corner set: (" + pos.getX() + "," + pos.getY() + "," + pos.getZ() + ")")); player.sendMessage(new TextComponentString("Next right click will set the opposite/ending corner.")); player.sendMessage(new TextComponentString("WARNING: this mode will destroy blocks, be careful.")); } else { // This is the second click. Load the starting coordinate. Use 'pos' as the ending coordinate. Then fill the cuboid with wool. int count = 0; IBlockState wool = Blocks.WOOL.getDefaultState().withProperty(BlockColored.COLOR, EnumDyeColor.BLACK); // // IMPORTANT PART OF THE TEST IS BELOW // BlockRange range = new BlockRange(startPos.get(), pos); for (BlockPos target : range) { // <-- Is the iterator giving a complete set? IBlockState old = world.getBlockState(target); world.destroyBlock(target, true); world.setBlockState(target, wool); world.notifyBlockUpdate(target, old, wool, 2); count += 1; } // // IMPORTANT PART OF THE TEST IS ABOVE // player.sendMessage(new TextComponentString("Volume: " + range.getVolume())); player.sendMessage(new TextComponentString("Replaced: " + count)); player.sendMessage(new TextComponentString("Coverage: " + (range.getVolume() == count ? "Complete" : "INCOMPLETE"))); setStartPos(stack, null); } }
Example 10
Source File: BlockEnderUtilitiesTileEntity.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) { TileEntityEnderUtilities te = getTileEntitySafely(world, pos, TileEntityEnderUtilities.class); if (te != null) { te.rotate(Rotation.CLOCKWISE_90); IBlockState state = world.getBlockState(pos).getActualState(world, pos); world.notifyBlockUpdate(pos, state, state, 3); return true; } return false; }
Example 11
Source File: BlockPortalPanel.java From enderutilities with GNU Lesser General Public License v3.0 | 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 == false) { // Returns the "id" of the pointed element of this block the player is currently looking at. // The target selection buttons are ids 0..7, the middle button is 8 and the base of the panel is 9. Integer id = this.getPointedElementId(world, pos, state.getValue(FACING), player); if (id != null && id >= 0 && id <= 8) { TileEntityPortalPanel te = getTileEntitySafely(world, pos, TileEntityPortalPanel.class); if (te != null) { if (id == 8) { te.tryTogglePortal(); } else { te.setActiveTargetId(id); world.notifyBlockUpdate(pos, state, state, 3); } world.playSound(null, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.MASTER, 0.5f, 1.0f); } return true; } } return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ); }
Example 12
Source File: ItemChestUpgrade.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { if (world.isRemote) { return EnumActionResult.PASS; } IBlockState state = world.getBlockState(pos); TileEntity te = world.getTileEntity(pos); if (state.getBlock() == Blocks.CHEST && te instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest) te; ItemStack[] items = new ItemStack[chest.getSizeInventory()]; for (int i = 0; i < items.length; i++) { items[i] = chest.getStackInSlot(i); chest.setInventorySlotContents(i, ItemStack.EMPTY); } IBlockState newState = BlocksItemsBetterChests.betterchest.getDefaultState().withProperty(BlockBetterChest.directions, state.getValue(BlockChest.FACING)); world.setBlockState(pos, newState, 2); TileEntityBChest newte = new TileEntityBChest(); world.setTileEntity(pos, newte); for (int i = 0; i < items.length; i++) { newte.getChestPart().setInventorySlotContents(i, items[i]); } world.notifyBlockUpdate(pos, state, newState, 1); ItemStack heldItem = player.getHeldItem(hand); heldItem.setCount(heldItem.getCount() - 1); return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }