net.minecraft.block.BlockEntityProvider Java Examples

The following examples show how to use net.minecraft.block.BlockEntityProvider. 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: PistonBlockEntity_movableTEMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "fromTag", at = @At(value = "TAIL"))
private void onFromTag(CompoundTag compoundTag_1, CallbackInfo ci)
{
    if (CarpetSettings.movableBlockEntities && compoundTag_1.contains("carriedTileEntityCM", 10))
    {
        if (this.pushedBlock.getBlock() instanceof BlockEntityProvider)
            this.carriedBlockEntity = ((BlockEntityProvider) (this.pushedBlock.getBlock())).createBlockEntity(this.world);
        if (carriedBlockEntity != null) //Can actually be null, as BlockPistonMoving.createNewTileEntity(...) returns null
            this.carriedBlockEntity.fromTag(compoundTag_1.getCompound("carriedTileEntityCM"));
    }
}
 
Example #2
Source File: World_movableTEMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
/**
 * @author 2No2Name
 */
public boolean setBlockStateWithBlockEntity(BlockPos blockPos_1, BlockState blockState_1, BlockEntity newBlockEntity, int int_1)
{
    if ((Object) this instanceof EmptyChunk)
        return false;
    
    if (World.isHeightInvalid(blockPos_1))
    {
        return false;
    }
    else if (!this.isClient && this.properties.getGeneratorType() == LevelGeneratorType.DEBUG_ALL_BLOCK_STATES)
    {
        return false;
    }
    else
    {
        WorldChunk worldChunk_1 = this.getWorldChunk(blockPos_1);
        Block block_1 = blockState_1.getBlock();
        
        BlockState blockState_2;
        if (newBlockEntity != null && block_1 instanceof BlockEntityProvider)
            blockState_2 = ((WorldChunkInterface) worldChunk_1).setBlockStateWithBlockEntity(blockPos_1, blockState_1, newBlockEntity, (int_1 & 64) != 0);
        else
            blockState_2 = worldChunk_1.setBlockState(blockPos_1, blockState_1, (int_1 & 64) != 0);
        
        if (blockState_2 == null)
        {
            return false;
        }
        else
        {
            BlockState blockState_3 = this.getBlockState(blockPos_1);
            
            if (blockState_3 != blockState_2 && (blockState_3.getOpacity((BlockView) this, blockPos_1) != blockState_2.getOpacity((BlockView) this, blockPos_1) || blockState_3.getLuminance() != blockState_2.getLuminance() || blockState_3.hasSidedTransparency() || blockState_2.hasSidedTransparency()))
            {
                this.profiler.push("queueCheckLight");
                this.getChunkManager().getLightingProvider().checkBlock(blockPos_1);
                this.profiler.pop();
            }
            
            if (blockState_3 == blockState_1)
            {
                if (blockState_2 != blockState_3)
                {
                    this.checkBlockRerender(blockPos_1, blockState_2, blockState_3);
                }
                
                if ((int_1 & 2) != 0 && (!this.isClient || (int_1 & 4) == 0) && (this.isClient || worldChunk_1.getLevelType() != null && worldChunk_1.getLevelType().isAfter(ChunkHolder.LevelType.TICKING)))
                {
                    this.updateListeners(blockPos_1, blockState_2, blockState_1, int_1);
                }
                
                if (!this.isClient && (int_1 & 1) != 0)
                {
                    this.updateNeighbors(blockPos_1, blockState_2.getBlock());
                    if (blockState_1.hasComparatorOutput())
                    {
                        this.updateHorizontalAdjacent(blockPos_1, block_1);
                    }
                }
                
                if ((int_1 & 16) == 0)
                {
                    int int_2 = int_1 & -2;
                    blockState_2.method_11637((net.minecraft.world.IWorld) this, blockPos_1, int_2);
                    blockState_1.updateNeighborStates((net.minecraft.world.IWorld) this, blockPos_1, int_2);
                    blockState_1.method_11637((net.minecraft.world.IWorld) this, blockPos_1, int_2);
                }
                
                this.onBlockChanged(blockPos_1, blockState_2, blockState_3);
            }
            return true;
        }
    }
}
 
Example #3
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Called throughout the code as a replacement for {@link BlockEntityProvider#createBlockEntity(BlockView)}
 * Return the same thing you would from that function.
 * This will fall back to {@link BlockEntityProvider#createBlockEntity(BlockView)} if this block is a {@link BlockEntityProvider}
 *
 * @param state The state of the current block
 * @param world The world to create the BE in
 * @return An instance of a class extending {@link BlockEntity}
 */
@Nullable
default BlockEntity createTileEntity(BlockState state, BlockView world) {
	if (getBlock() instanceof BlockEntityProvider) {
		return ((BlockEntityProvider) getBlock()).createBlockEntity(world);
	}

	return null;
}
 
Example #4
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called throughout the code as a replacement for {@code block instanceof} {@link BlockEntityProvider}.
 * Allows for blocks to have a block entity conditionally based on block state.
 *
 * <p>Return true from this function to specify this block has a block entity.
 *
 * @param state State of the current block
 * @return True if block has a block entity, false otherwise
 */
default boolean hasTileEntity(BlockState state) {
	return this instanceof BlockEntityProvider;
}