3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-20 01:40:06 +01:00
Dieser Commit ist enthalten in:
dordsor21 2023-10-24 17:46:40 +01:00
Ursprung 594527f356
Commit 5a39197e3e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
10 geänderte Dateien mit 26 neuen und 243 gelöschten Zeilen

Datei anzeigen

@ -137,6 +137,7 @@ import org.bukkit.generator.ChunkGenerator;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -158,7 +159,6 @@ import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;

Datei anzeigen

@ -21,7 +21,6 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R2.PaperweightServerLevelDelegateProxy;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.regen.PaperweightRegen;
import com.sk89q.worldedit.entity.BaseEntity;
@ -74,7 +73,6 @@ import net.minecraft.util.StringRepresentable;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -103,7 +101,6 @@ import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -111,7 +108,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -120,7 +116,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.OptionalInt;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Datei anzeigen

@ -291,6 +291,8 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param session The EditSession
* @param pt The location
* @return If it succeeded
*
* @since TODO
*/
default boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession session, BlockVector3 pt) {
throw new UnsupportedOperationException("This adapter does not support generating features.");
@ -304,6 +306,8 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param session The EditSession
* @param pt The location
* @return If it succeeded
*
* @since TODO
*/
default boolean generateStructure(StructureType feature, World world, EditSession session, BlockVector3 pt) {
throw new UnsupportedOperationException("This adapter does not support generating features.");

Datei anzeigen

@ -17,7 +17,7 @@ import com.sk89q.worldedit.world.generation.StructureType;
import javax.annotation.Nullable;
/**
* Places a feature
* Places a structure
*
* @since TODO
*/

Datei anzeigen

@ -6,6 +6,11 @@ import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.generation.StructureType;
/**
* Generate a structure at the given location
*
* @since TODO
*/
public class StructureGenerator implements RegionFunction {
private final StructureType structureType;
@ -16,6 +21,8 @@ public class StructureGenerator implements RegionFunction {
*
* @param editSession the edit session
* @param structureType the structure type
*
* @since TODO
*/
public StructureGenerator(EditSession editSession, StructureType structureType) {
this.editSession = editSession;

Datei anzeigen

@ -4026,6 +4026,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param feature feature to generate
* @param position position to generate at
* @return blocks affected
*
* @since TODO
*/
public int generateFeature(ConfiguredFeatureType feature, BlockVector3 position) {
feature.place(this, position);
@ -4038,6 +4040,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param structure structure to generate
* @param position position to generate at
* @return blocks affected
*
* @since TODO
*/
public int generateStructure(StructureType structure, BlockVector3 position) {
structure.place(this, position);

Datei anzeigen

@ -26,8 +26,9 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
/**
* Generates forests by searching for the ground starting from the given upper Y
* coordinate for every column given.
* Generate a feature at the given location
*
* @since TODO
*/
public class FeatureGenerator implements RegionFunction {
@ -39,6 +40,8 @@ public class FeatureGenerator implements RegionFunction {
*
* @param editSession the edit session
* @param featureType the feature type
*
* @since TODO
*/
public FeatureGenerator(EditSession editSession, ConfiguredFeatureType featureType) {
this.editSession = editSession;

Datei anzeigen

@ -320,6 +320,8 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
* @param editSession The {@link EditSession}
* @param position The position
* @return True if the generation was successful
*
* @since TODO
*/
default boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) {
return false;
@ -332,6 +334,8 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
* @param editSession The {@link EditSession}
* @param position The position
* @return True if the generation was successful
*
* @since TODO
*/
default boolean generateFeature(ConfiguredFeatureType type, EditSession editSession, BlockVector3 position) {
return false;

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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);
}
}