3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-03 01:50:07 +01:00

Fix FAWE killing chunk ticks. Also allow ticking for set blocks. (#439)

* Fix FAWE killing chunk ticks. Also allow ticking for set blocks.

* Reduce for-loop to being one loop in createPalette

* set the value in the set array and break so we don't continue onwards in the set's ordinal switch statement
Dieser Commit ist enthalten in:
dordsor21 2020-05-03 17:50:09 +01:00 committet von GitHub
Ursprung a6f2cd0fb5
Commit 0ca81e9d67
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 121 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -1,21 +1,35 @@
package com.boydti.fawe.bukkit.adapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.Map;
import java.util.function.Function;
public class NMSAdapter {
public static int createPalette(int[] blockToPalette, int[] paletteToBlock, int[] blocksCopy, int[] num_palette_buffer, char[] set) {
public static int createPalette(int[] blockToPalette, int[] paletteToBlock, int[] blocksCopy,
int[] num_palette_buffer, char[] set, Map<BlockVector3, Integer> ticking_blocks) {
int air = 0;
int num_palette = 0;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
switch (ordinal) {
case 0:
case BlockID.__RESERVED__:
ordinal = BlockID.AIR;
case BlockID.AIR:
case BlockID.CAVE_AIR:
case BlockID.VOID_AIR:
air++;
break;
default:
BlockState state = BlockState.getFromOrdinal(ordinal);
if (state.getMaterial().isTicksRandomly()) {
ticking_blocks.put(BlockVector3.at(i & 15, (i >> 8) & 15, (i >> 4) & 15),
WorldEditPlugin.getInstance().getBukkitImplAdapter()
.getInternalBlockStateId(state).orElse(0));
}
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
@ -29,35 +43,19 @@ public class NMSAdapter {
return air;
}
public static int createPalette(int layer, int[] blockToPalette, int[] paletteToBlock, int[] blocksCopy, int[] num_palette_buffer, Function<Integer, char[]> get, char[] set) {
public static int createPalette(int layer, int[] blockToPalette, int[] paletteToBlock,
int[] blocksCopy, int[] num_palette_buffer, Function<Integer, char[]> get, char[] set,
Map<BlockVector3, Integer> ticking_blocks) {
int air = 0;
int num_palette = 0;
int i = 0;
outer:
for (; i < 4096; i++) {
char[] getArr = null;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
switch (ordinal) {
case BlockID.__RESERVED__:
break outer;
case BlockID.AIR:
case BlockID.CAVE_AIR:
case BlockID.VOID_AIR:
air++;
case BlockID.__RESERVED__: {
if (getArr == null) {
getArr = get.apply(layer);
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = palette = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
blocksCopy[i] = palette;
}
if (i != 4096) {
char[] getArr = get.apply(layer);
for (; i < 4096; i++) {
char ordinal = set[i];
switch (ordinal) {
case BlockID.__RESERVED__:
ordinal = getArr[i];
switch (ordinal) {
case BlockID.__RESERVED__:
@ -66,14 +64,22 @@ public class NMSAdapter {
case BlockID.CAVE_AIR:
case BlockID.VOID_AIR:
air++;
default:
set[i] = ordinal;
}
break;
}
set[i] = ordinal;
break;
}
case BlockID.AIR:
case BlockID.CAVE_AIR:
case BlockID.VOID_AIR:
air++;
break;
}
BlockState state = BlockState.getFromOrdinal(ordinal);
if (state.getMaterial().isTicksRandomly()) {
ticking_blocks.put(BlockVector3.at(i & 15, (i >> 8) & 15, (i >> 4) & 15),
WorldEditPlugin.getInstance().getBukkitImplAdapter()
.getInternalBlockStateId(state).orElse(0));
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
@ -83,7 +89,47 @@ public class NMSAdapter {
}
blocksCopy[i] = palette;
}
}
//Keeping this here for reference.
//if (setblocks != 4096) {
// char[] getArr = get.apply(layer);
// for (i = setblocks; i < 4096; i++) {
// char ordinal = set[i];
// switch (ordinal) {
// case BlockID.__RESERVED__:
// ordinal = getArr[i];
// switch (ordinal) {
// case BlockID.__RESERVED__:
// ordinal = BlockID.AIR;
// case BlockID.AIR:
// case BlockID.CAVE_AIR:
// case BlockID.VOID_AIR:
// air++;
// break;
// default:
// BlockState state = BlockState.getFromOrdinal(ordinal);
// if (state.getMaterial().isTicksRandomly()) {
// ticking_blocks
// .put(BlockVector3.at(i & 15, (i >> 8) & 15, (i >> 4) & 15),
// WorldEditPlugin.getInstance().getBukkitImplAdapter()
// .getInternalBlockStateId(state).orElse(0));
// }
// set[i] = ordinal;
// }
// break;
// case BlockID.AIR:
// case BlockID.CAVE_AIR:
// case BlockID.VOID_AIR:
// air++;
// }
// int palette = blockToPalette[ordinal];
// if (palette == Integer.MAX_VALUE) {
// blockToPalette[ordinal] = palette = num_palette;
// paletteToBlock[num_palette] = ordinal;
// num_palette++;
// }
// blocksCopy[i] = palette;
// }
//}
num_palette_buffer[0] = num_palette;
return air;

Datei anzeigen

@ -9,12 +9,15 @@ import com.boydti.fawe.object.collection.BitArray;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import net.jpountz.util.UnsafeUtils;
import net.minecraft.server.v1_14_R1.Block;
@ -210,11 +213,12 @@ public final class BukkitAdapter_1_14 extends NMSAdapter {
final int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get();
try {
int[] num_palette_buffer = new int[1];
Map<BlockVector3, Integer> ticking_blocks = new HashMap<>();
int air;
if (get == null) {
air = createPalette(blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, set);
air = createPalette(blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, set, ticking_blocks);
} else {
air = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, get, set);
air = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, get, set, ticking_blocks);
}
int num_palette = num_palette_buffer[0];
// BlockStates
@ -256,7 +260,11 @@ public final class BukkitAdapter_1_14 extends NMSAdapter {
fieldBits.set(dataPaletteBlocks, nmsBits);
fieldPalette.set(dataPaletteBlocks, palette);
fieldSize.set(dataPaletteBlocks, bitsPerEntry);
setCount(0, 4096 - air, section);
setCount(ticking_blocks.size(), 4096 - air, section);
ticking_blocks.forEach((pos, ordinal) -> {
section.setType(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(),
Block.getByCombinedId(ordinal));
});
} catch (final IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}

Datei anzeigen

@ -9,12 +9,15 @@ import com.boydti.fawe.object.collection.BitArray;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import net.jpountz.util.UnsafeUtils;
import net.minecraft.server.v1_15_R1.*;
@ -197,11 +200,12 @@ public final class BukkitAdapter_1_15 extends NMSAdapter {
final int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get();
try {
int[] num_palette_buffer = new int[1];
Map<BlockVector3, Integer> ticking_blocks = new HashMap<>();
int air;
if (get == null) {
air = createPalette(blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, set);
air = createPalette(blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, set, ticking_blocks);
} else {
air = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, get, set);
air = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, get, set, ticking_blocks);
}
int num_palette = num_palette_buffer[0];
// BlockStates
@ -243,7 +247,11 @@ public final class BukkitAdapter_1_15 extends NMSAdapter {
fieldBits.set(dataPaletteBlocks, nmsBits);
fieldPalette.set(dataPaletteBlocks, palette);
fieldSize.set(dataPaletteBlocks, bitsPerEntry);
setCount(0, 4096 - air, section);
setCount(ticking_blocks.size(), 4096 - air, section);
ticking_blocks.forEach((pos, ordinal) -> {
section.setType(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(),
Block.getByCombinedId(ordinal));
});
} catch (final IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}

Datei anzeigen

@ -9,12 +9,15 @@ import com.boydti.fawe.object.collection.BitArray;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import net.jpountz.util.UnsafeUtils;
import net.minecraft.server.v1_15_R1.*;
@ -198,11 +201,14 @@ public final class BukkitAdapter_1_15_2 extends NMSAdapter {
final int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get();
try {
int[] num_palette_buffer = new int[1];
Map<BlockVector3, Integer> ticking_blocks = new HashMap<>();
int air;
if (get == null) {
air = createPalette(blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, set);
air = createPalette(blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer,
set, ticking_blocks);
} else {
air = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, num_palette_buffer, get, set);
air = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy,
num_palette_buffer, get, set, ticking_blocks);
}
int num_palette = num_palette_buffer[0];
// BlockStates
@ -244,7 +250,11 @@ public final class BukkitAdapter_1_15_2 extends NMSAdapter {
fieldBits.set(dataPaletteBlocks, nmsBits);
fieldPalette.set(dataPaletteBlocks, palette);
fieldSize.set(dataPaletteBlocks, bitsPerEntry);
setCount(0, 4096 - air, section);
setCount(ticking_blocks.size(), 4096 - air, section);
ticking_blocks.forEach((pos, ordinal) -> {
section.setType(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(),
Block.getByCombinedId(ordinal));
});
} catch (final IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}