mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
consistency changes
This commit is contained in:
@ -8,6 +8,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
public interface IChunkExtent<T extends IChunk> extends Extent {
|
||||
/**
|
||||
@ -20,7 +21,7 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
|
||||
T getOrCreateChunk(int chunkX, int chunkZ);
|
||||
|
||||
@Override
|
||||
default <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B state) {
|
||||
default <B extends BlockStateHolder<B>> boolean setBlock(int x, @Range(from = 0, to = 255) int y, int z, B state) {
|
||||
final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4);
|
||||
return chunk.setBlock(x & 15, y, z & 15, state);
|
||||
}
|
||||
|
@ -97,13 +97,13 @@ public abstract class CharBlocks implements IBlocks {
|
||||
return BlockTypesCache.states[get(x, y, z)];
|
||||
}
|
||||
|
||||
public char get(int x, int y, int z) {
|
||||
public char get(int x, @Range(from = 0, to = 255) int y, int z) {
|
||||
final int layer = y >> 4;
|
||||
final int index = (y & 15) << 8 | z << 4 | x;
|
||||
return sections[layer].get(this, layer, index);
|
||||
}
|
||||
|
||||
public void set(int x, int y, int z, char value) {
|
||||
public void set(int x, @Range(from = 0, to = 255) int y, int z, char value) {
|
||||
final int layer = y >> 4;
|
||||
final int index = (y & 15) << 8 | z << 4 | x;
|
||||
try {
|
||||
@ -130,13 +130,13 @@ public abstract class CharBlocks implements IBlocks {
|
||||
|
||||
public static abstract class Section {
|
||||
|
||||
public abstract char[] get(CharBlocks blocks, int layer);
|
||||
public abstract char[] get(CharBlocks blocks, @Range(from = 0, to = 15) int layer);
|
||||
|
||||
public final char get(CharBlocks blocks, int layer, int index) {
|
||||
public final char get(CharBlocks blocks, @Range(from = 0, to = 15) int layer, int index) {
|
||||
return get(blocks, layer)[index];
|
||||
}
|
||||
|
||||
public final void set(CharBlocks blocks, int layer, int index, char value) {
|
||||
public final void set(CharBlocks blocks, @Range(from = 0, to = 15) int layer, int index, char value) {
|
||||
get(blocks, layer)[index] = value;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.IntStream;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||
private static Pool<CharSetBlocks> POOL = FaweCache.INSTANCE.registerPool(CharSetBlocks.class, CharSetBlocks::new, Settings.IMP.QUEUE.POOL);
|
||||
@ -82,7 +83,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T holder) {
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, @Range(from = 0, to = 255) int y, int z, T holder) {
|
||||
set(x, y, z, holder.getOrdinalChar());
|
||||
holder.applyTileEntity(this, x, y, z);
|
||||
return true;
|
||||
|
@ -23,6 +23,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Future;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
/**
|
||||
* An abstract {@link IChunk} class that implements basic get/set blocks
|
||||
@ -208,7 +209,7 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(ChunkHolder chunk, int x, int y, int z, T block) {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(ChunkHolder chunk, int x, @Range(from = 0, to = 255) int y, int z, B block) {
|
||||
return chunk.chunkSet.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
|
@ -14,16 +14,16 @@ public class VisualQueue extends SingleThreadIntervalQueue<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operate(Player fp) {
|
||||
LocalSession session = fp.getSession();
|
||||
Tool tool = session.getTool(fp);
|
||||
public void operate(Player player) {
|
||||
LocalSession session = player.getSession();
|
||||
Tool tool = session.getTool(player);
|
||||
if (tool instanceof BrushTool) {
|
||||
BrushTool brushTool = (BrushTool) tool;
|
||||
if (brushTool.getVisualMode() != VisualMode.NONE) {
|
||||
try {
|
||||
brushTool.visualize(BrushTool.BrushAction.PRIMARY, fp);
|
||||
brushTool.visualize(BrushTool.BrushAction.PRIMARY, player);
|
||||
} catch (Throwable e) {
|
||||
WorldEdit.getInstance().getPlatformManager().handleThrowable(e, fp);
|
||||
WorldEdit.getInstance().getPlatformManager().handleThrowable(e, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard.ClipboardEntity;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
@ -20,17 +21,13 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MemoryOptimizedClipboard extends LinearClipboard {
|
||||
|
||||
@ -310,7 +307,9 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
|
||||
|
||||
@Override
|
||||
public void removeEntity(Entity entity) {
|
||||
this.entities.remove(entity);
|
||||
if (entity instanceof ClipboardEntity) {
|
||||
this.entities.remove(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -81,7 +80,7 @@ public abstract class ReadOnlyClipboard extends SimpleClipboard {
|
||||
public abstract List<? extends Entity> getEntities();
|
||||
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
|
||||
throw new UnsupportedOperationException("Clipboard is immutable");
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,10 @@ package com.boydti.fawe.object.clipboard;
|
||||
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
@ -65,8 +63,4 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
|
||||
return hasBiomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
package com.boydti.fawe.object.clipboard;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class WorldCutClipboard extends WorldCopyClipboard {
|
||||
public WorldCutClipboard(Supplier<Extent> supplier, Region region) {
|
||||
super(supplier, region);
|
||||
}
|
||||
|
||||
public WorldCutClipboard(Supplier<Extent> supplier, Region region, boolean hasEntities, boolean hasBiomes) {
|
||||
super(supplier, region, hasEntities, hasBiomes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(int x, int y, int z) {
|
||||
Extent extent = getExtent();
|
||||
BaseBlock block = extent.getFullBlock(x, y, z);
|
||||
extent.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
Extent extent = getExtent();
|
||||
BlockState block = extent.getBlock(x, y, z);
|
||||
extent.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
Extent extent = getExtent();
|
||||
if (extent instanceof EditSession) {
|
||||
((EditSession) extent).flushQueue();
|
||||
} else if (extent instanceof Closeable) {
|
||||
try {
|
||||
((Closeable) extent).close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
extent.commit();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ import java.io.FileNotFoundException;
|
||||
|
||||
public class CachedTextureUtil extends DelegateTextureUtil {
|
||||
private final TextureUtil parent;
|
||||
private transient Int2ObjectOpenHashMap<BlockType> colorBlockMap;
|
||||
private transient Int2ObjectOpenHashMap<Integer> colorBiomeMap;
|
||||
private transient Int2ObjectOpenHashMap<BlockType[]> colorLayerMap;
|
||||
private final transient Int2ObjectOpenHashMap<BlockType> colorBlockMap;
|
||||
private final transient Int2ObjectOpenHashMap<Integer> colorBiomeMap;
|
||||
private final transient Int2ObjectOpenHashMap<BlockType[]> colorLayerMap;
|
||||
|
||||
public CachedTextureUtil(TextureUtil parent) throws FileNotFoundException {
|
||||
super(parent);
|
||||
@ -39,7 +39,7 @@ public class CachedTextureUtil extends DelegateTextureUtil {
|
||||
}
|
||||
BiomeColor result = parent.getNearestBiome(color);
|
||||
if (result != null) {
|
||||
colorBiomeMap.put((int) color, (Integer) result.id);
|
||||
colorBiomeMap.put(color, (Integer) result.id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -52,7 +52,7 @@ public class CachedTextureUtil extends DelegateTextureUtil {
|
||||
}
|
||||
BlockType result = parent.getNearestBlock(color);
|
||||
if (result != null) {
|
||||
colorBlockMap.put((int) color, result);
|
||||
colorBlockMap.put(color, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ public class RandomTextureUtil extends CachedTextureUtil {
|
||||
}
|
||||
|
||||
private int index;
|
||||
private int[] biomeMixBuffer = new int[3];
|
||||
private Int2ObjectOpenHashMap<Integer> offsets = new Int2ObjectOpenHashMap<>();
|
||||
private Int2ObjectOpenHashMap<int[]> biomeMixes = new Int2ObjectOpenHashMap<>();
|
||||
private final int[] biomeMixBuffer = new int[3];
|
||||
private final Int2ObjectOpenHashMap<Integer> offsets = new Int2ObjectOpenHashMap<>();
|
||||
private final Int2ObjectOpenHashMap<int[]> biomeMixes = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
protected int addRandomColor(int c1, int c2) {
|
||||
int red1 = (c1 >> 16) & 0xFF;
|
||||
@ -81,7 +81,7 @@ public class RandomTextureUtil extends CachedTextureUtil {
|
||||
|
||||
@Override
|
||||
public BlockType getNearestBlock(int color) {
|
||||
int offsetColor = offsets.getOrDefault((Object) color, 0);
|
||||
int offsetColor = offsets.getOrDefault((Object)color, 0);
|
||||
if (offsetColor != 0) {
|
||||
offsetColor = addRandomColor(color, offsetColor);
|
||||
} else {
|
||||
|
@ -1,11 +1,6 @@
|
||||
package com.boydti.fawe.util;
|
||||
|
||||
import sun.reflect.ConstructorAccessor;
|
||||
import sun.reflect.FieldAccessor;
|
||||
import sun.reflect.ReflectionFactory;
|
||||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -24,80 +19,11 @@ public class ReflectionUtils {
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> T addEnum(Class<T> enumType, String enumName) {
|
||||
try {
|
||||
return addEnum(enumType, enumName, new Class<?>[]{}, new Object[]{});
|
||||
} catch (Throwable ignore) {
|
||||
return ReflectionUtils9.addEnum(enumType, enumName);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> T addEnum(Class<T> enumType, String enumName, Class<?>[] additionalTypes, Object[] additionalValues) {
|
||||
|
||||
// 0. Sanity checks
|
||||
if (!Enum.class.isAssignableFrom(enumType)) {
|
||||
throw new RuntimeException("class " + enumType + " is not an instance of Enum");
|
||||
}
|
||||
// 1. Lookup "$VALUES" holder in enum class and get previous enum instances
|
||||
Field valuesField = null;
|
||||
Field[] fields = enumType.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (field.getName().contains("$VALUES")) {
|
||||
valuesField = field;
|
||||
break;
|
||||
}
|
||||
}
|
||||
AccessibleObject.setAccessible(new Field[]{valuesField}, true);
|
||||
|
||||
try {
|
||||
|
||||
// 2. Copy it
|
||||
T[] previousValues = (T[]) valuesField.get(enumType);
|
||||
List<T> values = new ArrayList<>(Arrays.asList(previousValues));
|
||||
|
||||
// 3. build new enum
|
||||
T newValue = (T) makeEnum(enumType, // The target enum class
|
||||
enumName, // THE NEW ENUM INSTANCE TO BE DYNAMICALLY ADDED
|
||||
values.size(),
|
||||
additionalTypes, // can be used to pass values to the enum constructor
|
||||
additionalValues); // can be used to pass values to the enum constructor
|
||||
|
||||
// 4. add new value
|
||||
values.add(newValue);
|
||||
|
||||
// 5. Set new values field
|
||||
setFailsafeFieldValue(valuesField, null,
|
||||
values.toArray((T[]) Array.newInstance(enumType, 0)));
|
||||
|
||||
// 6. Clean enum cache
|
||||
cleanEnumCache(enumType);
|
||||
return newValue;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Object makeEnum(Class<?> enumClass, String value, int ordinal,
|
||||
Class<?>[] additionalTypes, Object[] additionalValues) throws Exception {
|
||||
Object[] parms = new Object[additionalValues.length + 2];
|
||||
parms[0] = value;
|
||||
parms[1] = ordinal;
|
||||
System.arraycopy(additionalValues, 0, parms, 2, additionalValues.length);
|
||||
return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes).newInstance(parms));
|
||||
}
|
||||
|
||||
private static ConstructorAccessor getConstructorAccessor(Class<?> enumClass,
|
||||
Class<?>[] additionalParameterTypes) throws NoSuchMethodException {
|
||||
Class<?>[] parameterTypes = new Class[additionalParameterTypes.length + 2];
|
||||
parameterTypes[0] = String.class;
|
||||
parameterTypes[1] = int.class;
|
||||
System.arraycopy(additionalParameterTypes, 0,
|
||||
parameterTypes, 2, additionalParameterTypes.length);
|
||||
return ReflectionFactory.getReflectionFactory().newConstructorAccessor(enumClass.getDeclaredConstructor(parameterTypes));
|
||||
return ReflectionUtils9.addEnum(enumType, enumName);
|
||||
}
|
||||
|
||||
public static void setAccessibleNonFinal(Field field)
|
||||
throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
||||
throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
||||
// let's make the field accessible
|
||||
field.setAccessible(true);
|
||||
|
||||
@ -134,12 +60,7 @@ public class ReflectionUtils {
|
||||
throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
||||
|
||||
setAccessibleNonFinal(field);
|
||||
try {
|
||||
FieldAccessor fa = ReflectionFactory.getReflectionFactory().newFieldAccessor(field, false);
|
||||
fa.set(target, value);
|
||||
} catch (NoSuchMethodError error) {
|
||||
field.set(target, value);
|
||||
}
|
||||
field.set(target,value);
|
||||
}
|
||||
|
||||
private static void blankField(Class<?> enumClass, String fieldName)
|
||||
|
Reference in New Issue
Block a user