Skip to content

Commit

Permalink
Bring back vanilla methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsu221 committed Feb 4, 2025
1 parent a5d6e3a commit 4fb1fd6
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@

import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
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 net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;

import javax.annotation.Nullable;

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

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

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

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

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

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

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

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

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

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

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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
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 @@ -42,36 +41,40 @@
public class SpongeBlockRegistry extends BundledBlockRegistry {

private final Map<org.spongepowered.api.block.BlockState, SpongeBlockMaterial> materialMap =
new HashMap<>();
new HashMap<>();

@Override
public Component getRichName(BlockType blockType) {
return SpongeTextAdapter.convert(Sponge.game().registry(RegistryTypes.BLOCK_TYPE)
.value(ResourceKey.resolve(blockType.id())).asComponent());
.value(ResourceKey.resolve(blockType.id())).asComponent());
}

@Override
public BlockMaterial getMaterial(BlockType blockType) {
org.spongepowered.api.block.BlockType spongeBlockType =
Sponge.game().registry(RegistryTypes.BLOCK_TYPE)
.value(ResourceKey.resolve(blockType.id()));
Sponge.game().registry(RegistryTypes.BLOCK_TYPE)
.value(ResourceKey.resolve(blockType.id()));
return materialMap.computeIfAbsent(
spongeBlockType.defaultState(),
blockState -> new SpongeBlockMaterial(
blockState,
super.getMaterial(blockType)
)
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)
);
}
);
}

@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
org.spongepowered.api.block.BlockType spongeBlockType =
Sponge.game().registry(RegistryTypes.BLOCK_TYPE)
.value(ResourceKey.resolve(blockType.id()));
Sponge.game().registry(RegistryTypes.BLOCK_TYPE)
.value(ResourceKey.resolve(blockType.id()));
Map<String, Property<?>> map = new TreeMap<>();
Collection<StateProperty<?>> propertyKeys = spongeBlockType
.defaultState().stateProperties();
.defaultState().stateProperties();
for (StateProperty<?> key : propertyKeys) {
map.put(key.name(), SpongeTransmogrifier.transmogToWorldEditProperty(key));
}
Expand All @@ -80,9 +83,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 world.blockPalette().get(equivalent);
return OptionalInt.of(Block.getId(
(net.minecraft.world.level.block.state.BlockState) equivalent
));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.sponge.internal;

import com.sk89q.worldedit.util.SideEffect;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;

import javax.annotation.Nullable;

public interface ExtendedChunk {
/**
* {@link LevelChunk#setBlockState(BlockPos, BlockState, boolean)} with the extra
* {@link SideEffect#UPDATE} flag.
*
* @param pos the position to set
* @param state the state to set
* @param moved I honestly have no idea and can't be bothered to investigate, we pass {@code
* false}
* @param update the update flag, see side-effect for details
* @return the old block state, or {@code null} if unchanged
*/
@Nullable
BlockState setBlockState(BlockPos pos, BlockState state, boolean moved, boolean update);
}
Loading

0 comments on commit 4fb1fd6

Please sign in to comment.