Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ neoforge-minecraft = "1.21.4"

sponge-minecraft = "1.21.4"
# https://repo.spongepowered.org/service/rest/repository/browse/maven-public/org/spongepowered/spongeapi/
sponge-api = "14.0.0-20241229.134205-2"
sponge-api = "14.0.0-20250114.224746-4"
sponge-api-major = "14"

# https://parchmentmc.org/docs/getting-started; note that we use older MC versions some times which is OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.item.ItemTypes;
import net.minecraft.world.level.block.Block;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.Sponge;
Expand All @@ -59,16 +58,16 @@
*/
public class SpongeAdapter {

public static org.spongepowered.api.block.BlockState adapt(BlockState blockState) {
public static org.spongepowered.api.block.BlockState adapt(BlockState blockState, ServerWorld world) {
int blockStateId = BlockStateIdAccess.getBlockStateId(blockState);
if (!BlockStateIdAccess.isValidInternalId(blockStateId)) {
return SpongeTransmogrifier.transmogToMinecraft(blockState);
}
return (org.spongepowered.api.block.BlockState) Block.stateById(blockStateId);
return world.blockPalette().get(blockStateId, world).orElseThrow();
}

public static BlockState adapt(org.spongepowered.api.block.BlockState blockState) {
int blockStateId = Block.getId((net.minecraft.world.level.block.state.BlockState) blockState);
public static BlockState adapt(org.spongepowered.api.block.BlockState blockState, ServerWorld world) {
int blockStateId = world.blockPalette().get(blockState).orElseThrow();
BlockState worldEdit = BlockStateIdAccess.getBlockStateById(blockStateId);
if (worldEdit == null) {
return SpongeTransmogrifier.transmogToWorldEdit(blockState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.type.MatterTypes;
import org.spongepowered.api.data.type.PushReactions;
import org.spongepowered.api.tag.BlockTypeTags;

import javax.annotation.Nullable;

Expand All @@ -42,55 +45,52 @@ public SpongeBlockMaterial(BlockState block, @Nullable BlockMaterial secondary)

@Override
public boolean isAir() {
return block.isAir() || super.isAir();
return block.type().is(BlockTypeTags.AIR) || super.isAir();
}

@Override
public boolean isOpaque() {
return block.canOcclude();
return ((net.minecraft.world.level.block.state.BlockState) block).canOcclude();
}

@Override
@SuppressWarnings("deprecation")
public boolean isLiquid() {
return block.liquid();
return block.require(Keys.MATTER_TYPE) == MatterTypes.LIQUID.get();
}

@Override
@SuppressWarnings("deprecation")
public boolean isSolid() {
return block.isSolid();
return block.require(Keys.IS_SOLID);
}

@Override
public boolean isFragileWhenPushed() {
return block.getPistonPushReaction() == PushReaction.DESTROY;
return block.require(Keys.PUSH_REACTION) == PushReactions.DESTROY.get();
}

@Override
public boolean isUnpushable() {
return block.getPistonPushReaction() == PushReaction.BLOCK;
return block.require(Keys.PUSH_REACTION) == PushReactions.BLOCK.get();
}

@Override
@SuppressWarnings("deprecation")
public boolean isMovementBlocker() {
return block.blocksMotion();
return !block.require(Keys.IS_PASSABLE);
}

@Override
public boolean isBurnable() {
return block.ignitedByLava();
return block.require(Keys.BURNABLE);
}

@Override
public boolean isToolRequired() {
return block.requiresCorrectToolForDrops();
return ((net.minecraft.world.level.block.state.BlockState) block).requiresCorrectToolForDrops();
}

@Override
public boolean isReplacedDuringPlacement() {
return block.canBeReplaced();
return block.require(Keys.IS_REPLACEABLE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
import net.minecraft.world.level.block.Block;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.registry.RegistryTypes;
import org.spongepowered.api.state.StateProperty;
import org.spongepowered.api.world.DefaultWorldKeys;
import org.spongepowered.api.world.server.ServerWorld;

import java.util.Collection;
import java.util.HashMap;
Expand All @@ -56,14 +57,10 @@ public BlockMaterial getMaterial(BlockType blockType) {
.value(ResourceKey.resolve(blockType.id()));
return materialMap.computeIfAbsent(
spongeBlockType.defaultState(),
m -> {
net.minecraft.world.level.block.state.BlockState blockState =
(net.minecraft.world.level.block.state.BlockState) m;
return new SpongeBlockMaterial(
blockState,
super.getMaterial(blockType)
);
}
blockState -> new SpongeBlockMaterial(
blockState,
super.getMaterial(blockType)
)
);
}

Expand All @@ -83,9 +80,9 @@ public BlockMaterial getMaterial(BlockType blockType) {

@Override
public OptionalInt getInternalBlockStateId(BlockState state) {
org.spongepowered.api.block.BlockState equivalent = SpongeAdapter.adapt(state);
return OptionalInt.of(Block.getId(
(net.minecraft.world.level.block.state.BlockState) equivalent
));
ServerWorld world = Sponge.server().worldManager().world(DefaultWorldKeys.DEFAULT).orElseThrow();
org.spongepowered.api.block.BlockState equivalent = SpongeAdapter.adapt(state, world);

return world.blockPalette().get(equivalent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B bl
if (block == null) {
player.resetBlockChange(pos.x(), pos.y(), pos.z());
} else {
BlockState spongeBlock = SpongeAdapter.adapt(block.toImmutableState());
BlockState spongeBlock = SpongeAdapter.adapt(block.toImmutableState(), player.world());
player.sendBlockChange(pos.x(), pos.y(), pos.z(), spongeBlock);
if (block instanceof final BaseBlock baseBlock
&& block.getBlockType().equals(com.sk89q.worldedit.world.block.BlockTypes.STRUCTURE_BLOCK)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.sk89q.worldedit.sponge;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
Expand All @@ -27,6 +28,7 @@
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.CuboidRegion;
Expand All @@ -53,7 +55,10 @@
import net.minecraft.data.worldgen.features.TreeFeatures;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
Expand Down Expand Up @@ -84,6 +89,7 @@

import java.lang.ref.WeakReference;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -152,7 +158,7 @@ public Path getStoragePath() {
public BlockState getBlock(BlockVector3 position) {
return SpongeAdapter.adapt(getWorld().block(
position.x(), position.y(), position.z()
));
), getWorld());
}

@Override
Expand Down Expand Up @@ -185,7 +191,7 @@ public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B

ServerWorld world = getWorld();

org.spongepowered.api.block.BlockState newState = SpongeAdapter.adapt(block.toImmutableState());
org.spongepowered.api.block.BlockState newState = SpongeAdapter.adapt(block.toImmutableState(), world);

boolean didSet = world.setBlock(
position.x(), position.y(), position.z(),
Expand All @@ -201,6 +207,7 @@ public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B
.withBlocksMoving(false)
.withForcedReRender(false)
.withIgnoreRender(false)
.withPerformBlockDestruction(false)
);
if (!didSet) {
// still update NBT if the block is the same
Expand Down Expand Up @@ -345,7 +352,6 @@ public int getBlockLightLevel(BlockVector3 position) {
int groundLight = getWorld().light(LightTypes.BLOCK, position.x(), position.y(), position.z());

return Math.max(skyLight, groundLight);

}

@Override
Expand Down Expand Up @@ -402,7 +408,7 @@ public void simulateBlockMine(BlockVector3 position) {

@Override
public boolean canPlaceAt(BlockVector3 position, com.sk89q.worldedit.world.block.BlockState blockState) {
return ((net.minecraft.world.level.block.state.BlockState) SpongeAdapter.adapt(blockState))
return ((net.minecraft.world.level.block.state.BlockState) SpongeAdapter.adapt(blockState, getWorld()))
.canSurvive(
((LevelReader) getWorld()),
new BlockPos(position.x(), position.y(), position.z())
Expand Down Expand Up @@ -478,6 +484,15 @@ public Entity createEntity(Location location, BaseEntity entity) {
return builder.build().apply(SpongeAdapter.adapt(location)).map(SpongeEntity::new).orElse(null);
}

@Override
public void sendBiomeUpdates(Iterable<BlockVector2> chunks) {
List<ChunkAccess> nativeChunks = chunks instanceof Collection<BlockVector2> chunkCollection ? Lists.newArrayListWithCapacity(chunkCollection.size()) : Lists.newArrayList();
for (BlockVector2 chunk : chunks) {
nativeChunks.add(((Level) getWorld()).getChunk(chunk.x(), chunk.z(), ChunkStatus.BIOMES, false));
}
((ServerLevel) getWorld()).getChunkSource().chunkMap.resendBiomesForChunks(nativeChunks);
}

@Override
public WeatherType getWeather() {
return WeatherTypes.get(
Expand Down
Loading
Loading