mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00: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
This commit is contained in:
parent
a6f2cd0fb5
commit
0ca81e9d67
@ -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,35 +43,19 @@ 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) {
|
||||||
case BlockID.AIR:
|
getArr = get.apply(layer);
|
||||||
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;
|
|
||||||
}
|
|
||||||
if (i != 4096) {
|
|
||||||
char[] getArr = get.apply(layer);
|
|
||||||
for (; i < 4096; i++) {
|
|
||||||
char ordinal = set[i];
|
|
||||||
switch (ordinal) {
|
|
||||||
case BlockID.__RESERVED__:
|
|
||||||
ordinal = getArr[i];
|
ordinal = getArr[i];
|
||||||
switch (ordinal) {
|
switch (ordinal) {
|
||||||
case BlockID.__RESERVED__:
|
case BlockID.__RESERVED__:
|
||||||
@ -66,14 +64,22 @@ public class NMSAdapter {
|
|||||||
case BlockID.CAVE_AIR:
|
case BlockID.CAVE_AIR:
|
||||||
case BlockID.VOID_AIR:
|
case BlockID.VOID_AIR:
|
||||||
air++;
|
air++;
|
||||||
default:
|
|
||||||
set[i] = ordinal;
|
|
||||||
}
|
|
||||||
break;
|
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) {
|
||||||
@ -83,7 +89,47 @@ public class NMSAdapter {
|
|||||||
}
|
}
|
||||||
blocksCopy[i] = palette;
|
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;
|
num_palette_buffer[0] = num_palette;
|
||||||
return air;
|
return air;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user