Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-17 00:20:09 +01:00
cleanup
Dieser Commit ist enthalten in:
Ursprung
d66f5c82fb
Commit
c12fa04955
@ -333,6 +333,8 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
|
|||||||
* @param session The EditSession
|
* @param session The EditSession
|
||||||
* @param pt The location
|
* @param pt The location
|
||||||
* @return If it succeeded
|
* @return If it succeeded
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
default boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession session, BlockVector3 pt) {
|
default boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession session, BlockVector3 pt) {
|
||||||
throw new UnsupportedOperationException("This adapter does not support generating features.");
|
throw new UnsupportedOperationException("This adapter does not support generating features.");
|
||||||
@ -346,6 +348,8 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
|
|||||||
* @param session The EditSession
|
* @param session The EditSession
|
||||||
* @param pt The location
|
* @param pt The location
|
||||||
* @return If it succeeded
|
* @return If it succeeded
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
default boolean generateStructure(StructureType feature, World world, EditSession session, BlockVector3 pt) {
|
default boolean generateStructure(StructureType feature, World world, EditSession session, BlockVector3 pt) {
|
||||||
throw new UnsupportedOperationException("This adapter does not support generating features.");
|
throw new UnsupportedOperationException("This adapter does not support generating features.");
|
||||||
|
@ -17,7 +17,7 @@ import com.sk89q.worldedit.world.generation.StructureType;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a feature
|
* Places a structure
|
||||||
*
|
*
|
||||||
* @since TODO
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,11 @@ import com.sk89q.worldedit.function.RegionFunction;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.world.generation.StructureType;
|
import com.sk89q.worldedit.world.generation.StructureType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a structure at the given location
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
public class StructureGenerator implements RegionFunction {
|
public class StructureGenerator implements RegionFunction {
|
||||||
|
|
||||||
private final StructureType structureType;
|
private final StructureType structureType;
|
||||||
@ -16,6 +21,8 @@ public class StructureGenerator implements RegionFunction {
|
|||||||
*
|
*
|
||||||
* @param editSession the edit session
|
* @param editSession the edit session
|
||||||
* @param structureType the structure type
|
* @param structureType the structure type
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
public StructureGenerator(EditSession editSession, StructureType structureType) {
|
public StructureGenerator(EditSession editSession, StructureType structureType) {
|
||||||
this.editSession = editSession;
|
this.editSession = editSession;
|
||||||
|
@ -4019,6 +4019,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
* @param feature feature to generate
|
* @param feature feature to generate
|
||||||
* @param position position to generate at
|
* @param position position to generate at
|
||||||
* @return blocks affected
|
* @return blocks affected
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
public int generateFeature(ConfiguredFeatureType feature, BlockVector3 position) {
|
public int generateFeature(ConfiguredFeatureType feature, BlockVector3 position) {
|
||||||
feature.place(this, position);
|
feature.place(this, position);
|
||||||
@ -4031,6 +4033,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
* @param structure structure to generate
|
* @param structure structure to generate
|
||||||
* @param position position to generate at
|
* @param position position to generate at
|
||||||
* @return blocks affected
|
* @return blocks affected
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
public int generateStructure(StructureType structure, BlockVector3 position) {
|
public int generateStructure(StructureType structure, BlockVector3 position) {
|
||||||
structure.place(this, position);
|
structure.place(this, position);
|
||||||
|
@ -26,8 +26,9 @@ import com.sk89q.worldedit.math.BlockVector3;
|
|||||||
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates forests by searching for the ground starting from the given upper Y
|
* Generate a feature at the given location
|
||||||
* coordinate for every column given.
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
public class FeatureGenerator implements RegionFunction {
|
public class FeatureGenerator implements RegionFunction {
|
||||||
|
|
||||||
@ -39,6 +40,8 @@ public class FeatureGenerator implements RegionFunction {
|
|||||||
*
|
*
|
||||||
* @param editSession the edit session
|
* @param editSession the edit session
|
||||||
* @param featureType the feature type
|
* @param featureType the feature type
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
public FeatureGenerator(EditSession editSession, ConfiguredFeatureType featureType) {
|
public FeatureGenerator(EditSession editSession, ConfiguredFeatureType featureType) {
|
||||||
this.editSession = editSession;
|
this.editSession = editSession;
|
||||||
|
@ -320,6 +320,8 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
|
|||||||
* @param editSession The {@link EditSession}
|
* @param editSession The {@link EditSession}
|
||||||
* @param position The position
|
* @param position The position
|
||||||
* @return True if the generation was successful
|
* @return True if the generation was successful
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
default boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) {
|
default boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) {
|
||||||
return false;
|
return false;
|
||||||
@ -332,6 +334,8 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
|
|||||||
* @param editSession The {@link EditSession}
|
* @param editSession The {@link EditSession}
|
||||||
* @param position The position
|
* @param position The position
|
||||||
* @return True if the generation was successful
|
* @return True if the generation was successful
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
default boolean generateFeature(ConfiguredFeatureType type, EditSession editSession, BlockVector3 position) {
|
default boolean generateFeature(ConfiguredFeatureType type, EditSession editSession, BlockVector3 position) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.fabric.internal;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
|
||||||
import com.sk89q.worldedit.fabric.FabricAdapter;
|
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
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;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class FabricServerLevelDelegateProxy implements InvocationHandler {
|
|
||||||
|
|
||||||
private final EditSession editSession;
|
|
||||||
private final ServerLevel serverLevel;
|
|
||||||
|
|
||||||
private FabricServerLevelDelegateProxy(EditSession editSession, ServerLevel serverLevel) {
|
|
||||||
this.editSession = editSession;
|
|
||||||
this.serverLevel = serverLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WorldGenLevel newInstance(EditSession editSession, ServerLevel serverLevel) {
|
|
||||||
return (WorldGenLevel) Proxy.newProxyInstance(
|
|
||||||
serverLevel.getClass().getClassLoader(),
|
|
||||||
serverLevel.getClass().getInterfaces(),
|
|
||||||
new FabricServerLevelDelegateProxy(editSession, serverLevel)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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(NBTConverter.toNative(this.editSession.getFullBlock(FabricAdapter.adapt(blockPos)).getNbtReference().getValue()));
|
|
||||||
|
|
||||||
return newEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlockState getBlockState(BlockPos blockPos) {
|
|
||||||
return FabricAdapter.adapt(this.editSession.getBlock(FabricAdapter.adapt(blockPos)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean setBlock(BlockPos blockPos, BlockState blockState) {
|
|
||||||
try {
|
|
||||||
return editSession.setBlock(FabricAdapter.adapt(blockPos), FabricAdapter.adapt(blockState));
|
|
||||||
} catch (MaxChangedBlocksException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean removeBlock(BlockPos blockPos, boolean bl) {
|
|
||||||
try {
|
|
||||||
return editSession.setBlock(FabricAdapter.adapt(blockPos), 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 "getBlockState", "method_8320" -> {
|
|
||||||
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
|
||||||
return getBlockState(blockPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getBlockEntity", "method_8321" -> {
|
|
||||||
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
|
||||||
return getBlockEntity(blockPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "setBlock", "method_8652" -> {
|
|
||||||
if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof BlockState blockState) {
|
|
||||||
return setBlock(blockPos, blockState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "removeBlock", "destroyBlock", "method_8650", "method_8651" -> {
|
|
||||||
if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof Boolean bl) {
|
|
||||||
return removeBlock(blockPos, bl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default -> { }
|
|
||||||
}
|
|
||||||
|
|
||||||
return method.invoke(this.serverLevel, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.forge.internal;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
|
||||||
import com.sk89q.worldedit.forge.ForgeAdapter;
|
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
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;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class ForgeServerLevelDelegateProxy implements InvocationHandler {
|
|
||||||
|
|
||||||
private final EditSession editSession;
|
|
||||||
private final ServerLevel serverLevel;
|
|
||||||
|
|
||||||
private ForgeServerLevelDelegateProxy(EditSession editSession, ServerLevel serverLevel) {
|
|
||||||
this.editSession = editSession;
|
|
||||||
this.serverLevel = serverLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WorldGenLevel newInstance(EditSession editSession, ServerLevel serverLevel) {
|
|
||||||
return (WorldGenLevel) Proxy.newProxyInstance(
|
|
||||||
serverLevel.getClass().getClassLoader(),
|
|
||||||
serverLevel.getClass().getInterfaces(),
|
|
||||||
new ForgeServerLevelDelegateProxy(editSession, serverLevel)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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(NBTConverter.toNative(this.editSession.getFullBlock(ForgeAdapter.adapt(blockPos)).getNbtReference().getValue()));
|
|
||||||
|
|
||||||
return newEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlockState getBlockState(BlockPos blockPos) {
|
|
||||||
return ForgeAdapter.adapt(this.editSession.getBlock(ForgeAdapter.adapt(blockPos)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean setBlock(BlockPos blockPos, BlockState blockState) {
|
|
||||||
try {
|
|
||||||
return editSession.setBlock(ForgeAdapter.adapt(blockPos), ForgeAdapter.adapt(blockState));
|
|
||||||
} catch (MaxChangedBlocksException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean removeBlock(BlockPos blockPos, boolean bl) {
|
|
||||||
try {
|
|
||||||
return editSession.setBlock(ForgeAdapter.adapt(blockPos), 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 "getBlockState", "m_8055_" -> {
|
|
||||||
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
|
||||||
return getBlockState(blockPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getBlockEntity", "m_7702_" -> {
|
|
||||||
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
|
||||||
return getBlockEntity(blockPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "setBlock", "m_7731_" -> {
|
|
||||||
if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof BlockState blockState) {
|
|
||||||
return setBlock(blockPos, blockState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "removeBlock", "destroyBlock", "m_7471_", "m_7740_" -> {
|
|
||||||
if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof Boolean bl) {
|
|
||||||
return removeBlock(blockPos, bl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default -> { }
|
|
||||||
}
|
|
||||||
|
|
||||||
return method.invoke(this.serverLevel, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren