-
-
Notifications
You must be signed in to change notification settings - Fork 931
Add a feature generator and allow undoing of feature placement #2239
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...com/sk89q/worldedit/bukkit/adapter/impl/v1_19_R2/PaperweightServerLevelDelegateProxy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * 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.bukkit.adapter.impl.v1_19_R2; | ||
|
|
||
| import com.sk89q.worldedit.EditSession; | ||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||
| import com.sk89q.worldedit.math.BlockVector3; | ||
| import com.sk89q.worldedit.world.block.BlockTypes; | ||
| import net.minecraft.core.BlockPos; | ||
| import net.minecraft.nbt.CompoundTag; | ||
| import net.minecraft.server.level.ServerLevel; | ||
| import net.minecraft.world.level.WorldGenLevel; | ||
| import net.minecraft.world.level.block.entity.BlockEntity; | ||
| import net.minecraft.world.level.block.state.BlockState; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.lang.reflect.InvocationHandler; | ||
| import java.lang.reflect.Method; | ||
| import java.lang.reflect.Proxy; | ||
|
|
||
| public class PaperweightServerLevelDelegateProxy implements InvocationHandler { | ||
|
|
||
| private final EditSession editSession; | ||
| private final ServerLevel serverLevel; | ||
| private final PaperweightAdapter adapter; | ||
|
|
||
| private PaperweightServerLevelDelegateProxy(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) { | ||
| this.editSession = editSession; | ||
| this.serverLevel = serverLevel; | ||
| this.adapter = adapter; | ||
| } | ||
|
|
||
| public static WorldGenLevel newInstance(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) { | ||
| return (WorldGenLevel) Proxy.newProxyInstance( | ||
| serverLevel.getClass().getClassLoader(), | ||
| serverLevel.getClass().getInterfaces(), | ||
| new PaperweightServerLevelDelegateProxy(editSession, serverLevel, adapter) | ||
| ); | ||
| } | ||
|
|
||
| @Nullable | ||
| private BlockEntity getBlockEntity(BlockPos blockPos) { | ||
| BlockEntity tileEntity = this.serverLevel.getChunkAt(blockPos).getBlockEntity(blockPos); | ||
| if (tileEntity == null) { | ||
| return null; | ||
| } | ||
| BlockEntity newEntity = tileEntity.getType().create(blockPos, getBlockState(blockPos)); | ||
| newEntity.load((CompoundTag) adapter.fromNative(this.editSession.getFullBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ())).getNbtReference().getValue())); | ||
|
|
||
| return newEntity; | ||
| } | ||
|
|
||
| private BlockState getBlockState(BlockPos blockPos) { | ||
| return adapter.adapt(this.editSession.getBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()))); | ||
| } | ||
|
|
||
| private boolean setBlock(BlockPos blockPos, BlockState blockState) { | ||
| try { | ||
| return editSession.setBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()), adapter.adapt(blockState)); | ||
| } catch (MaxChangedBlocksException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| private boolean removeBlock(BlockPos blockPos, boolean bl) { | ||
| try { | ||
| return editSession.setBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()), BlockTypes.AIR.getDefaultState()); | ||
| } catch (MaxChangedBlocksException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
| switch (method.getName()) { | ||
| case "a_", "getBlockState" -> { | ||
| if (args.length == 1 && args[0] instanceof BlockPos blockPos) { | ||
| // getBlockState | ||
| return getBlockState(blockPos); | ||
| } | ||
| } | ||
| case "c_", "getBlockEntity" -> { | ||
| if (args.length == 1 && args[0] instanceof BlockPos blockPos) { | ||
| // getBlockEntity | ||
| return getBlockEntity(blockPos); | ||
| } | ||
| } | ||
| case "a", "setBlock", "removeBlock", "destroyBlock" -> { | ||
| if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof BlockState blockState) { | ||
| // setBlock | ||
| return setBlock(blockPos, blockState); | ||
| } else if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof Boolean bl) { | ||
| // removeBlock (and also matches destroyBlock) | ||
|
me4502 marked this conversation as resolved.
|
||
| return removeBlock(blockPos, bl); | ||
| } | ||
| } | ||
| default -> { } | ||
| } | ||
|
|
||
| return method.invoke(this.serverLevel, args); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.