net.minecraft.world.chunk.WorldChunk Java Examples

The following examples show how to use net.minecraft.world.chunk.WorldChunk. 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: MixinClientChunkManager.java    From multiconnect with MIT License 6 votes vote down vote up
@Inject(method = "loadChunkFromPacket", at = @At("RETURN"))
private void onLoadChunkFromPacket(int x, int z, BiomeArray biomes, PacketByteBuf buf, CompoundTag heightmaps, int verticalStripBitmask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        if (ci.getReturnValue() != null) {
            synchronized (LOCK) {
                UpgradeData upgradeData = ChunkUpgrader.fixChunk(ci.getReturnValue());
                ((IUpgradableChunk) ci.getReturnValue()).multiconnect_setClientUpgradeData(upgradeData);
                for (int dx = -1; dx <= 1; dx++) {
                    for (int dz = -1; dz <= 1; dz++) {
                        WorldChunk chunk = getChunk(x + dx, z + dz, ChunkStatus.FULL, false);
                        if (chunk != null)
                            ((IUpgradableChunk) chunk).multiconnect_onNeighborLoaded();
                    }
                }
            }
        }
    }
}
 
Example #2
Source File: WorldChunk_movableTEMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "setBlockState", at = @At(value = "INVOKE", ordinal = 1,
        target = "Lnet/minecraft/world/chunk/WorldChunk;getBlockEntity(Lnet/minecraft/util/math/BlockPos;" + "Lnet/minecraft/world/chunk/WorldChunk$CreationType;)" + "Lnet/minecraft/block/entity/BlockEntity;"))
private BlockEntity ifGetBlockEntity(WorldChunk worldChunk, BlockPos blockPos_1,
        WorldChunk.CreationType worldChunk$CreationType_1)
{
    if (!CarpetSettings.movableBlockEntities)
    {
        return this.getBlockEntity(blockPos_1, WorldChunk.CreationType.CHECK);
    }
    else
    {
        return this.world.getBlockEntity(blockPos_1);
    }
}
 
Example #3
Source File: MixinClientChunkManager.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "loadChunkFromPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;getSectionArray()[Lnet/minecraft/world/chunk/ChunkSection;"))
private void recalculateHeightmaps(int x, int z, BiomeArray biomeArray, PacketByteBuf buf, CompoundTag tag, int verticalStripMask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) {
        WorldChunk chunk = this.chunk.get();
        for (ChunkSection section : chunk.getSectionArray()) {
            if (section != null) {
                section.calculateCounts();
            }
        }
        Heightmap.populateHeightmaps(chunk, CLIENT_HEIGHTMAPS);
    }
    this.chunk.set(null);
}
 
Example #4
Source File: MixinClientChunkManager.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "loadChunkFromPacket", at = @At("RETURN"))
private void onLoadChunkFromPacket(int x, int z, BiomeArray biomeArray, PacketByteBuf buf, CompoundTag heightmaps, int verticalStripMask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_14_4) {
        if (ci.getReturnValue() != null) {
            Biome[] biomeData = PendingBiomeData.getPendingBiomeData(x, z);
            if (biomeData != null) {
                ((IBiomeStorage_1_14_4) ci.getReturnValue()).multiconnect_setBiomeArray_1_14_4(biomeData);
                PendingBiomeData.setPendingBiomeData(x, z, null);
            }
        }
    }
}
 
Example #5
Source File: MixinWorldChunk.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public void multiconnect_onNeighborLoaded() {
    if (clientUpgradeData != null) {
        for (int dx = -1; dx <= 1; dx++) {
            for (int dz = -1; dz <= 1; dz++) {
                if (world.getChunk(pos.x + dx, pos.z + dz, ChunkStatus.FULL, false) == null) {
                    return;
                }
            }
        }
        clientUpgradeData.upgrade((WorldChunk) (Object) this);
        clientUpgradeData = null;
    }
}
 
Example #6
Source File: SpawnHelperMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/player/PlayerEntity;squaredDistanceTo(DDD)D"
))
private static double getSqDistanceTo(PlayerEntity playerEntity, double double_1, double double_2, double double_3,
                                      EntityCategory entityCategory_1, ServerWorld world_1, WorldChunk worldChunk_1, BlockPos blockPos_1)
{
    double distanceTo = playerEntity.squaredDistanceTo(double_1, double_2, double_3);
    if (CarpetSettings.lagFreeSpawning && distanceTo > 16384.0D && entityCategory_1 != EntityCategory.CREATURE)
        return 0.0;
    return distanceTo;
}
 
Example #7
Source File: MixinUpgradeData.java    From multiconnect with MIT License 5 votes vote down vote up
@Redirect(method = "upgradeSide", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;getUpgradeData()Lnet/minecraft/world/chunk/UpgradeData;"))
private static UpgradeData redirectGetUpgradeData(WorldChunk chunk) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        return ((IUpgradableChunk) chunk).multiconnect_getClientUpgradeData();
    }
    return chunk.getUpgradeData();
}
 
Example #8
Source File: ChunkSerializerMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "deserialize", at = @At(value = "NEW", target = "net/minecraft/world/chunk/WorldChunk"))
private static WorldChunk newWorldChunk(
		World newWorld, ChunkPos newChunkPos, Biome[] newBiomes, UpgradeData newUpgradeData, TickScheduler<Block> newTickScheduler, TickScheduler<Fluid> newTickScheduler2, long newL, @Nullable ChunkSection[] newChunkSections, @Nullable Consumer<WorldChunk> newConsumer,
		ServerWorld serverWorld, StructureManager structureManager, PointOfInterestStorage pointOfInterestStorage, ChunkPos chunkPos, CompoundTag compoundTag) {
	WorldChunk chunk = new WorldChunk(newWorld, newChunkPos, newBiomes, newUpgradeData, newTickScheduler, newTickScheduler2, newL, newChunkSections, newConsumer);
	CompoundTag level = compoundTag.getCompound("Level");

	if (level.contains("ForgeCaps")) {
		((CapabilityProviderHolder) chunk).deserializeCaps(level.getCompound("ForgeCaps"));
	}

	return chunk;
}
 
Example #9
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Consumer<Packet<?>> trackingChunk(final Supplier<WorldChunk> worldChunk) {
	return packet -> {
		final WorldChunk chunk = worldChunk.get();
		((ServerChunkManager) chunk.getWorld().getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(chunk.getPos(), false)
			.forEach(e -> e.networkHandler.sendPacket(packet));
	};
}
 
Example #10
Source File: BlockValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static BlockEntity getBlockEntity(ServerWorld world, BlockPos pos)
{
    if (world.getServer().isOnThread())
        return world.getBlockEntity(pos);
    else
        return world.getWorldChunk(pos).getBlockEntity(pos, WorldChunk.CreationType.IMMEDIATE);
}
 
Example #11
Source File: ServerChunkManagerMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "method_20801", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/world/SpawnHelper;spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/util/math/BlockPos;)V"
))
// inject our repeat of spawns if more spawn ticks per tick are chosen.
private void spawnMultipleTimes(EntityCategory entityCategory_1, ServerWorld world_1, WorldChunk worldChunk_1, BlockPos blockPos_1)
{
    for (int i = 0; i < SpawnReporter.spawn_tries.get(entityCategory_1); i++)
    {
        SpawnHelper.spawnEntitiesInChunk(entityCategory_1, world_1, worldChunk_1, blockPos_1);
    }
}
 
Example #12
Source File: World_scarpetPlopMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "getTopY", at = @At(
        value = "INVOKE",
        target = "net/minecraft/world/chunk/WorldChunk.sampleHeightmap(Lnet/minecraft/world/Heightmap$Type;II)I"
))
private int fixSampleHeightmap(WorldChunk chunk, Heightmap.Type type, int x, int z)
{
    if (CarpetSettings.skipGenerationChecks)
    {
        Heightmap.Type newType = type;
        if (type == Heightmap.Type.OCEAN_FLOOR_WG) newType = Heightmap.Type.OCEAN_FLOOR;
        else if (type == Heightmap.Type.WORLD_SURFACE_WG) newType = Heightmap.Type.WORLD_SURFACE;
        return chunk.sampleHeightmap(newType, x, z);
    }
    return chunk.sampleHeightmap(type, x, z);
}
 
Example #13
Source File: ServerWorld_scarpetEventMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "tickChunk", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/world/ServerWorld;addLightning(Lnet/minecraft/entity/LightningEntity;)V"
))
private void onNaturalLightinig(WorldChunk chunk, int randomTickSpeed, CallbackInfo ci,
                                ChunkPos chunkPos, boolean bl, int i, int j, Profiler profiler, BlockPos blockPos, boolean bl2)
{
    if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerWorld) (Object)this, blockPos, bl2?1:0);
}
 
Example #14
Source File: WorldChunkMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Nonnull
@Override
public CapabilityProvider<WorldChunk> getCapabilityProvider() {
	return provider;
}
 
Example #15
Source File: WorldChunk_movableTEMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Shadow
/* @Nullable */
public abstract BlockEntity getBlockEntity(BlockPos blockPos_1, WorldChunk.CreationType worldChunk$CreationType_1);
 
Example #16
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 #17
Source File: World_movableTEMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Shadow
public abstract WorldChunk getWorldChunk(BlockPos blockPos_1);
 
Example #18
Source File: MixinClientChunkManager.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "loadChunkFromPacket", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", ordinal = 0, remap = false), cancellable = true)
private void cancelErrorMessage(int x, int z, BiomeArray biomeArray, PacketByteBuf buf, CompoundTag tag, int verticalStripMask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2 && !PendingChunkDataPackets.isProcessingQueuedPackets())
        ci.setReturnValue(null);
}
 
Example #19
Source File: ChunkUpgrader.java    From multiconnect with MIT License 4 votes vote down vote up
public static UpgradeData fixChunk(WorldChunk chunk) {
    IntList centerIndicesToUpgrade = new IntArrayList();
    int sidesToUpgrade = 0;

    BlockPos.Mutable otherPos = new BlockPos.Mutable();
    for (BlockPos pos : BlockPos.iterate(chunk.getPos().getStartX(), 0, chunk.getPos().getStartZ(),
            chunk.getPos().getEndX(), chunk.getHighestNonEmptySectionYOffset() + 15, chunk.getPos().getEndZ())) {
        BlockState state = chunk.getBlockState(pos);
        Block block = state.getBlock();
        inPlaceFix(chunk, state, pos, otherPos);

        int blockId = Registry.BLOCK.getRawId(block) & 4095;
        if (ChunkPalettedStorageFixAccessor.getBlocksNeedingSideUpdate().get(blockId)) {
            boolean west = (pos.getX() & 15) == 0;
            boolean east = (pos.getX() & 15) == 15;
            boolean north = (pos.getZ() & 15) == 0;
            boolean south = (pos.getZ() & 15) == 15;
            if (north) {
                if (east) {
                    sidesToUpgrade |= 2;
                } else if (west) {
                    sidesToUpgrade |= 128;
                } else {
                    sidesToUpgrade |= 1;
                }
            } else if (south) {
                if (west) {
                    sidesToUpgrade |= 32;
                } else if (east) {
                    sidesToUpgrade |= 8;
                } else {
                    sidesToUpgrade |= 16;
                }
            } else if (east) {
                sidesToUpgrade |= 4;
            } else if (west) {
                sidesToUpgrade |= 64;
            } else {
                centerIndicesToUpgrade.add(pos.getY() << 8 | (pos.getZ() & 15) << 4 | (pos.getX() & 15));
            }
        }
    }

    if (centerIndicesToUpgrade.isEmpty() && sidesToUpgrade == 0)
        return null;

    CompoundTag upgradeData = new CompoundTag();
    upgradeData.putInt("Sides", sidesToUpgrade);
    CompoundTag centerIndices = new CompoundTag();
    centerIndicesToUpgrade.forEach((IntConsumer) index -> {
        int low = index & 4095;
        int high = index >>> 12;
        Tag tag = centerIndices.get(String.valueOf(high));
        if (tag == null)
            centerIndices.put(String.valueOf(high), tag = new ListTag());
        ((ListTag) tag).add(IntTag.of(low));
    });
    for (String key : centerIndices.getKeys()) {
        //noinspection ConstantConditions
        centerIndices.put(key, new IntArrayTag(((ListTag) centerIndices.get(key)).stream().mapToInt(val -> ((IntTag) val).getInt()).toArray()));
    }
    upgradeData.put("Indices", centerIndices);
    return new UpgradeData(upgradeData);
}
 
Example #20
Source File: MixinClientChunkManager.java    From multiconnect with MIT License 4 votes vote down vote up
@ModifyVariable(method = "loadChunkFromPacket", ordinal = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;getSectionArray()[Lnet/minecraft/world/chunk/ChunkSection;"))
private WorldChunk grabChunk(WorldChunk chunk) {
    this.chunk.set(chunk);
    return chunk;
}
 
Example #21
Source File: MixinClientChunkManager.java    From multiconnect with MIT License votes vote down vote up
@Shadow public abstract WorldChunk getChunk(int x, int z, ChunkStatus status, boolean create);