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
This commit is contained in:
dordsor21 2020-05-03 17:50:09 +01:00 committed by GitHub
parent a6f2cd0fb5
commit 0ca81e9d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 49 deletions

View File

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

View File

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

View File

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

View File

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