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;
}
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;
}
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))));
}
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());
}
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;
}
Aggregations