Search in sources :

Example 26 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project FastAsyncWorldEdit by IntellectualSites.

the class FabricWorldNativeAccess method updateTileEntity.

@Override
public boolean updateTileEntity(BlockPos position, com.sk89q.jnbt.CompoundTag tag) {
    CompoundTag nativeTag = NBTConverter.toNative(tag);
    BlockEntity tileEntity = getWorld().getWorldChunk(position).getBlockEntity(position);
    if (tileEntity == null) {
        return false;
    }
    tileEntity.setLocation(getWorld(), position);
    tileEntity.fromTag(nativeTag);
    return true;
}
Also used : CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 27 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project SeedcrackerX by 19MisterX98.

the class DungeonFinder method findInChunk.

@Override
public List<BlockPos> findInChunk() {
    // Gets all the positions with a mob spawner in the chunk.
    List<BlockPos> result = super.findInChunk();
    if (result.size() != 1)
        return new ArrayList<>();
    result.removeIf(pos -> {
        BlockEntity blockEntity = this.world.getBlockEntity(pos);
        if (!(blockEntity instanceof MobSpawnerBlockEntity))
            return true;
        int count = 0;
        for (BlockPos blockPos : POSSIBLE_FLOOR_POSITIONS) {
            BlockPos currentPos = pos.add(blockPos);
            Block currentBlock = this.world.getBlockState(currentPos).getBlock();
            if (currentBlock == Blocks.COBBLESTONE || currentBlock == Blocks.MOSSY_COBBLESTONE) {
                count++;
            }
        }
        return count < 20;
    });
    if (result.size() != 1)
        return new ArrayList<>();
    Biome biome = this.world.getBiomeForNoiseGen((this.chunkPos.x << 2) + 2, 0, (this.chunkPos.z << 2) + 2).value();
    BlockPos pos = result.get(0);
    if (Config.get().getVersion().isNewerThan(MCVersion.v1_17_1)) {
        Decorator.Data<?> data;
        if (pos.getY() < 0) {
            data = Features.DEEP_DUNGEON.at(pos.getX(), pos.getY(), pos.getZ(), BiomeFixer.swap(biome));
        } else {
            data = Features.DUNGEON.at(pos.getX(), pos.getY(), pos.getZ(), null, null, BiomeFixer.swap(biome), null);
        }
        this.renderers.add(new Cube(pos, new Color(255, 0, 0)));
        SeedCracker.get().getDataStorage().addBaseData(data, DataAddedEvent.POKE_BIOMES);
        return result;
    }
    Vec3i size = this.getDungeonSize(pos);
    int[] floorCalls = this.getFloorCalls(size, pos);
    Dungeon.Data data = Features.DUNGEON.at(pos.getX(), pos.getY(), pos.getZ(), size, floorCalls, BiomeFixer.swap(biome), heightContext);
    if (AntiXRay(pos) && Config.get().antiXrayBypass) {
        if (SeedCracker.get().getDataStorage().baseSeedData.contains(new DataStorage.Entry<>(data, null))) {
            return result;
        }
        this.renderers.add(new Cube(pos, new Color(255, 0, 0)));
        Thread floorCallsUpdater = new Thread(() -> {
            try {
                // server needs to send the blocks before we do a second check
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            int[] floorCallsAfter = this.getFloorCalls(size, pos);
            for (int i = 0; i < floorCallsAfter.length; i++) {
                if (floorCallsAfter[i] != 2) {
                    floorCalls[i] = floorCallsAfter[i];
                }
            }
            if (SeedCracker.get().getDataStorage().addBaseData(data, data::onDataAdded)) {
                if (data.usesFloor()) {
                    this.renderers.add(new Cuboid(pos.subtract(size), pos.add(size).add(1, -1, 1), new Color(255, 0, 0)));
                }
            } else {
                this.renderers.clear();
            }
        });
        blockUpdateExploit(pos, size, floorCallsUpdater);
    } else if (SeedCracker.get().getDataStorage().addBaseData(data, data::onDataAdded)) {
        this.renderers.add(new Cube(pos, new Color(255, 0, 0)));
        if (data.usesFloor()) {
            this.renderers.add(new Cuboid(pos.subtract(size), pos.add(size).add(1, -1, 1), new Color(255, 0, 0)));
        }
    }
    return result;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) DataStorage(kaptainwutax.seedcrackerX.cracker.storage.DataStorage) Color(kaptainwutax.seedcrackerX.render.Color) Cuboid(kaptainwutax.seedcrackerX.render.Cuboid) Decorator(kaptainwutax.seedcrackerX.cracker.decorator.Decorator) Biome(net.minecraft.world.biome.Biome) Cube(kaptainwutax.seedcrackerX.render.Cube) Dungeon(kaptainwutax.seedcrackerX.cracker.decorator.Dungeon) MobSpawnerBlockEntity(net.minecraft.block.entity.MobSpawnerBlockEntity) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) MobSpawnerBlockEntity(net.minecraft.block.entity.MobSpawnerBlockEntity)

Example 28 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project SeedcrackerX by 19MisterX98.

the class ShipwreckFinder method findInChunk.

@Override
public List<BlockPos> findInChunk() {
    Biome biome = this.world.getBiomeForNoiseGen((this.chunkPos.x << 2) + 2, 64, (this.chunkPos.z << 2) + 2).value();
    if (!Features.SHIPWRECK.isValidBiome(BiomeFixer.swap(biome))) {
        return new ArrayList<>();
    }
    List<BlockPos> result = super.findInChunk();
    result.removeIf(pos -> {
        BlockState state = this.world.getBlockState(pos);
        if (state.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE)
            return true;
        BlockEntity blockEntity = this.world.getBlockEntity(pos);
        if (!(blockEntity instanceof ChestBlockEntity))
            return true;
        return !this.onChestFound(pos);
    });
    return result;
}
Also used : Biome(net.minecraft.world.biome.Biome) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity)

Example 29 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project tweakermore by Fallen-Breath.

the class PlacementTweaksMixin method doSchematicWorldPickBlock.

/**
 * Stolen from {@link fi.dy.masa.litematica.util.WorldUtils#doSchematicWorldPickBlock}
 */
private static void doSchematicWorldPickBlock(MinecraftClient mc, BlockPos pos, Hand hand) {
    World schematicWorld = SchematicWorldHandler.getSchematicWorld();
    World clientWorld = mc.world;
    if (schematicWorld != null && mc.player != null && clientWorld != null && mc.interactionManager != null) {
        LayerRange layerRange = DataManager.getRenderLayerRange();
        if (!layerRange.isPositionWithinRange(pos)) {
            return;
        }
        BlockState state = schematicWorld.getBlockState(pos);
        ItemStack stack = MaterialCache.getInstance().getRequiredBuildItemForState(state, schematicWorld, pos);
        // System.err.println(pos + " " + state + " " + stack);
        if (!stack.isEmpty()) {
            PlayerInventory inv = mc.player.inventory;
            stack = stack.copy();
            if (mc.player.abilities.creativeMode) {
                BlockEntity te = schematicWorld.getBlockEntity(pos);
                if (GuiBase.isCtrlDown() && te != null && clientWorld.isAir(pos)) {
                    ItemUtils.storeTEInStack(stack, te);
                }
                InventoryUtils.setPickedItemToHand(stack, mc);
                mc.interactionManager.clickCreativeStack(mc.player.getStackInHand(Hand.MAIN_HAND), 36 + inv.selectedSlot);
            } else {
                int slot = inv.getSlotWithStack(stack);
                boolean shouldPick = inv.selectedSlot != slot;
                boolean canPick = slot != -1;
                if (shouldPick && canPick) {
                    InventoryUtils.setPickedItemToHand(stack, mc);
                }
            }
            // so hand restore works fine
            PlacementTweaks.cacheStackInHand(hand);
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) LayerRange(fi.dy.masa.malilib.util.LayerRange) PlayerInventory(net.minecraft.entity.player.PlayerInventory) World(net.minecraft.world.World) ClientWorld(net.minecraft.client.world.ClientWorld) ItemStack(net.minecraft.item.ItemStack) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 30 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project KahzerxMod by otakucraft.

the class WorldBlockEntityMixin method onTick.

@Redirect(method = "tickBlockEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/BlockEntityTickInvoker;tick()V"))
private void onTick(BlockEntityTickInvoker instance) {
    instance.tick();
    BlockEntity be = getBlockEntity(instance.getPos());
    if (be == null) {
        return;
    }
    BlockEntitiesProfiler.addBlockEntity(be, (World) (Object) this);
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

BlockEntity (net.minecraft.block.entity.BlockEntity)61 BlockPos (net.minecraft.util.math.BlockPos)26 BlockState (net.minecraft.block.BlockState)19 BlockHitResult (net.minecraft.util.hit.BlockHitResult)13 ItemStack (net.minecraft.item.ItemStack)10 ChestBlockEntity (net.minecraft.block.entity.ChestBlockEntity)8 Vec3d (net.minecraft.util.math.Vec3d)8 World (net.minecraft.world.World)7 Block (net.minecraft.block.Block)6 Inject (org.spongepowered.asm.mixin.injection.Inject)6 MatrixStack (net.minecraft.client.util.math.MatrixStack)5 FluidState (net.minecraft.fluid.FluidState)5 Random (java.util.Random)4 AbstractFurnaceBlockEntity (net.minecraft.block.entity.AbstractFurnaceBlockEntity)4 CommandBlockBlockEntity (net.minecraft.block.entity.CommandBlockBlockEntity)4 BlockRenderManager (net.minecraft.client.render.block.BlockRenderManager)4 ChunkRendererRegion (net.minecraft.client.render.chunk.ChunkRendererRegion)4 Inventory (net.minecraft.inventory.Inventory)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 ServerWorld (net.minecraft.server.world.ServerWorld)4