Search in sources :

Example 1 with CommandBlockBlockEntity

use of net.minecraft.block.entity.CommandBlockBlockEntity in project roadrunner by MaxNeedsSnacks.

the class BlockEntityList method addNoDoubleAdd.

private boolean addNoDoubleAdd(BlockEntity blockEntity, boolean exceptionOnDoubleAdd) {
    if (currentlyOffThread()) {
        // Off-thread adds are always treated as "if absent", otherwise the most typical case (race on
        // getBlockEntity) would always crash
        addOffThreadOperation(new OffThreadOperation(blockEntity, OperationType.ADD));
        return true;
    }
    checkOffThreadModifications(false);
    boolean added = this.allBlockEntities.add(blockEntity);
    if (!added && exceptionOnDoubleAdd && // Ignore double add when we encounter vanilla's command block double add bug
    !(blockEntity instanceof CommandBlockBlockEntity)) {
        this.throwException(blockEntity);
    }
    if (added && this.posMap != null) {
        long pos = getEntityPos(blockEntity);
        BlockEntity prev = this.posMap.putIfAbsent(pos, blockEntity);
        if (prev != null) {
            List<BlockEntity> multiEntry = this.posMapMulti.computeIfAbsent(pos, (long l) -> new ArrayList<>());
            if (multiEntry.size() == 0) {
                // newly created multi entry: make sure it contains all elements
                multiEntry.add(prev);
            }
            multiEntry.add(blockEntity);
        }
    }
    return added;
}
Also used : CommandBlockBlockEntity(net.minecraft.block.entity.CommandBlockBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) CommandBlockBlockEntity(net.minecraft.block.entity.CommandBlockBlockEntity)

Aggregations

BlockEntity (net.minecraft.block.entity.BlockEntity)1 CommandBlockBlockEntity (net.minecraft.block.entity.CommandBlockBlockEntity)1