Search in sources :

Example 26 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project roadrunner by MaxNeedsSnacks.

the class RedstoneWireBlockMixin method getPowerFromSide.

/**
 * Calculate the redstone power a wire receives from blocks next to it.
 */
private int getPowerFromSide(World world, BlockPos pos, Direction toDir, boolean checkWiresAbove) {
    WorldChunk chunk = world.getWorldChunk(pos);
    BlockState state = chunk.getBlockState(pos);
    if (state.isOf(this)) {
        return state.get(Properties.POWER) - 1;
    }
    int power = state.getWeakRedstonePower(world, pos, toDir);
    if (power >= MAX) {
        return MAX;
    }
    if (state.isSolidBlock(world, pos)) {
        power = Math.max(power, this.getStrongPowerTo(world, pos, toDir.getOpposite()));
        if (power >= MAX) {
            return MAX;
        }
        if (checkWiresAbove && power < MAX_WIRE) {
            BlockPos up = pos.up();
            BlockState aboveState = chunk.getBlockState(up);
            if (aboveState.isOf(this)) {
                power = Math.max(power, aboveState.get(Properties.POWER) - 1);
            }
        }
    } else if (power < MAX_WIRE) {
        BlockPos down = pos.down();
        BlockState belowState = chunk.getBlockState(down);
        if (belowState.isOf(this)) {
            power = Math.max(power, belowState.get(Properties.POWER) - 1);
        }
    }
    return power;
}
Also used : BlockState(net.minecraft.block.BlockState) WorldChunk(net.minecraft.world.chunk.WorldChunk) BlockPos(net.minecraft.util.math.BlockPos)

Example 27 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project roadrunner by MaxNeedsSnacks.

the class WorldHelper method getEntitiesOfClass.

/**
 * [VanillaCopy] Method for getting entities by class but also exclude one entity
 */
public static List<Entity> getEntitiesOfClass(World world, Entity except, Class<? extends Entity> entityClass, Box box) {
    world.getProfiler().visit("getEntities");
    int minChunkX = MathHelper.floor((box.minX - 2.0D) / 16.0D);
    int maxChunkX = MathHelper.ceil((box.maxX + 2.0D) / 16.0D);
    int minChunkZ = MathHelper.floor((box.minZ - 2.0D) / 16.0D);
    int maxChunkZ = MathHelper.ceil((box.maxZ + 2.0D) / 16.0D);
    List<Entity> entities = Lists.newArrayList();
    ChunkManager chunkManager = world.getChunkManager();
    for (int chunkX = minChunkX; chunkX < maxChunkX; ++chunkX) {
        for (int chunkZ = minChunkZ; chunkZ < maxChunkZ; ++chunkZ) {
            WorldChunk chunk = chunkManager.getWorldChunk(chunkX, chunkZ, false);
            if (chunk != null) {
                WorldHelper.getEntitiesOfClass(chunk, except, entityClass, box, entities);
            }
        }
    }
    return entities;
}
Also used : Entity(net.minecraft.entity.Entity) WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkManager(net.minecraft.world.chunk.ChunkManager)

Example 28 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project EdenClient by HahaOO7.

the class ContainerInfo method updateChunk.

private void updateChunk(WorldChunk chunk) {
    Map<BlockPos, BlockEntity> be = chunk.getBlockEntities();
    ChestMap map = chunkMap.get(chunk.getPos());
    if (map == null)
        return;
    map.keySet().removeIf(Predicate.not(e -> be.containsKey(new BlockPos(e))));
}
Also used : java.util(java.util) BlockEntity(net.minecraft.block.entity.BlockEntity) NbtElement(net.minecraft.nbt.NbtElement) PerWorldConfig(at.haha007.edenclient.utils.config.PerWorldConfig) Item(net.minecraft.item.Item) NbtList(net.minecraft.nbt.NbtList) ClientChunkManager(net.minecraft.client.world.ClientChunkManager) Inventory(net.minecraft.inventory.Inventory) at.haha007.edenclient.callbacks(at.haha007.edenclient.callbacks) Direction(net.minecraft.util.math.Direction) ItemStack(net.minecraft.item.ItemStack) Vec3i(net.minecraft.util.math.Vec3i) Block(net.minecraft.block.Block) ConfigLoader(at.haha007.edenclient.utils.config.loaders.ConfigLoader) RegistryKey(net.minecraft.util.registry.RegistryKey) Hand(net.minecraft.util.Hand) ItemList(at.haha007.edenclient.utils.config.wrappers.ItemList) ChestBlock(net.minecraft.block.ChestBlock) BlockState(net.minecraft.block.BlockState) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) ScreenHandler(net.minecraft.screen.ScreenHandler) Predicate(java.util.function.Predicate) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) ChestType(net.minecraft.block.enums.ChestType) Items(net.minecraft.item.Items) Collectors(java.util.stream.Collectors) Registry(net.minecraft.util.registry.Registry) ActionResult(net.minecraft.util.ActionResult) WorldChunk(net.minecraft.world.chunk.WorldChunk) NbtCompound(net.minecraft.nbt.NbtCompound) Stream(java.util.stream.Stream) ConfigSubscriber(at.haha007.edenclient.utils.config.ConfigSubscriber) Identifier(net.minecraft.util.Identifier) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) ShulkerBoxScreenHandler(net.minecraft.screen.ShulkerBoxScreenHandler) BlockTags(net.minecraft.tag.BlockTags) PlayerUtils(at.haha007.edenclient.utils.PlayerUtils) ClientWorld(net.minecraft.client.world.ClientWorld) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity)

Example 29 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project EdenClient by HahaOO7.

the class HeadHunt method tick.

private void tick(ClientPlayerEntity player) {
    if (!enabled) {
        heads = new HashSet<>();
        foundHeads = new HashSet<>();
        return;
    }
    ChunkPos chunkPos = player.getChunkPos();
    ClientChunkManager cm = player.clientWorld.getChunkManager();
    BlockPos pp = player.getBlockPos();
    heads = ChunkPos.stream(chunkPos, 20).flatMap(cp -> {
        WorldChunk wc = cm.getWorldChunk(cp.x, cp.z, false);
        if (wc == null)
            return null;
        return wc.getBlockEntities().entrySet().stream();
    }).filter(e -> e.getValue().getType() == BlockEntityType.SKULL).map(Map.Entry::getKey).sorted(Comparator.comparingDouble(pos -> pos.getSquaredDistance(pp))).limit(1000).map(v -> (Vec3i) v).collect(Collectors.toSet());
    heads.removeAll(foundHeads);
    heads.stream().filter(bp -> player.getPos().squaredDistanceTo(Vec3d.ofCenter(bp)) < 20).forEach(this::clickPos);
    System.out.println("Heads found: " + heads.size());
}
Also used : PerWorldConfig(at.haha007.edenclient.utils.config.PerWorldConfig) ChatColor(at.haha007.edenclient.utils.ChatColor) ClientChunkManager(net.minecraft.client.world.ClientChunkManager) GameRenderCallback(at.haha007.edenclient.callbacks.GameRenderCallback) JoinWorldCallback(at.haha007.edenclient.callbacks.JoinWorldCallback) VertexBuffer(net.minecraft.client.gl.VertexBuffer) HashSet(java.util.HashSet) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) CommandManager(at.haha007.edenclient.command.CommandManager) PlayerUtils.sendModMessage(at.haha007.edenclient.utils.PlayerUtils.sendModMessage) Map(java.util.Map) PlayerTickCallback(at.haha007.edenclient.callbacks.PlayerTickCallback) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) Hand(net.minecraft.util.Hand) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) RequiredArgumentBuilder(com.mojang.brigadier.builder.RequiredArgumentBuilder) CommandContext(com.mojang.brigadier.context.CommandContext) net.minecraft.client.render(net.minecraft.client.render) net.minecraft.util.math(net.minecraft.util.math) MatrixStack(net.minecraft.client.util.math.MatrixStack) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Set(java.util.Set) RenderUtils(at.haha007.edenclient.utils.RenderUtils) BlockEntityType(net.minecraft.block.entity.BlockEntityType) Collectors(java.util.stream.Collectors) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) WorldChunk(net.minecraft.world.chunk.WorldChunk) ConfigSubscriber(at.haha007.edenclient.utils.config.ConfigSubscriber) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) LeaveWorldCallback(at.haha007.edenclient.callbacks.LeaveWorldCallback) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) Comparator(java.util.Comparator) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) PlayerUtils(at.haha007.edenclient.utils.PlayerUtils) WorldChunk(net.minecraft.world.chunk.WorldChunk) ClientChunkManager(net.minecraft.client.world.ClientChunkManager) Map(java.util.Map)

Example 30 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project fabric by FabricMC.

the class MixinChunkRendererRegion method init.

@Inject(at = @At("RETURN"), method = "<init>")
public void init(World world, int cxOff, int czOff, WorldChunk[][] chunks, BlockPos posFrom, BlockPos posTo, CallbackInfo info) {
    HashMap<BlockPos, Object> map = new HashMap<>();
    for (WorldChunk[] chunkA : chunks) {
        for (WorldChunk chunkB : chunkA) {
            for (Map.Entry<BlockPos, BlockEntity> entry : chunkB.getBlockEntities().entrySet()) {
                BlockPos entPos = entry.getKey();
                if (entPos.getX() >= posFrom.getX() && entPos.getX() <= posTo.getX() && entPos.getY() >= posFrom.getY() && entPos.getY() <= posTo.getY() && entPos.getZ() >= posFrom.getZ() && entPos.getZ() <= posTo.getZ()) {
                    Object o = ((RenderAttachmentBlockEntity) entry.getValue()).getRenderAttachmentData();
                    if (o != null) {
                        map.put(entPos, o);
                    }
                }
            }
        }
    }
    this.fabric_renderDataObjects = map;
}
Also used : HashMap(java.util.HashMap) WorldChunk(net.minecraft.world.chunk.WorldChunk) RenderAttachmentBlockEntity(net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map) BlockEntity(net.minecraft.block.entity.BlockEntity) RenderAttachmentBlockEntity(net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

WorldChunk (net.minecraft.world.chunk.WorldChunk)34 BlockPos (net.minecraft.util.math.BlockPos)15 BlockState (net.minecraft.block.BlockState)9 ChunkPos (net.minecraft.util.math.ChunkPos)8 Inject (org.spongepowered.asm.mixin.injection.Inject)8 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)6 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)4 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)4 PerWorldConfig (at.haha007.edenclient.utils.config.PerWorldConfig)4 Collectors (java.util.stream.Collectors)4 PlayerTickCallback (at.haha007.edenclient.callbacks.PlayerTickCallback)3 CommandManager (at.haha007.edenclient.command.CommandManager)3 ChatColor (at.haha007.edenclient.utils.ChatColor)3 PlayerUtils.sendModMessage (at.haha007.edenclient.utils.PlayerUtils.sendModMessage)3 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)3 CommandContext (com.mojang.brigadier.context.CommandContext)3 Biome (com.seedfinding.mcbiome.biome.Biome)3 BiomeSource (com.seedfinding.mcbiome.source.BiomeSource)3 BlockEntity (net.minecraft.block.entity.BlockEntity)3 Direction (net.minecraft.util.math.Direction)3