Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sponge module refactoring and fixes #2697

Open
wants to merge 6 commits into
base: version/7.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -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) {
ServerWorld world = Sponge.server().worldManager().world(DefaultWorldKeys.DEFAULT).orElseThrow();
org.spongepowered.api.block.BlockState equivalent = SpongeAdapter.adapt(state);
return OptionalInt.of(Block.getId(
(net.minecraft.world.level.block.state.BlockState) equivalent
));

return world.blockPalette().get(equivalent);
}
}
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 @@ -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 @@ -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