CFI changeset

This commit is contained in:
Jesse Boyd 2019-11-08 05:27:04 +00:00
parent 82f5c4ebed
commit faa63b0c35
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
11 changed files with 88 additions and 53 deletions

View File

@ -8,6 +8,7 @@ import com.boydti.fawe.beta.implementation.cache.preloader.Preloader;
import com.boydti.fawe.bukkit.adapter.BukkitQueueHandler;
import com.boydti.fawe.bukkit.listener.BrushListener;
import com.boydti.fawe.bukkit.listener.BukkitImageListener;
import com.boydti.fawe.bukkit.listener.CFIPacketListener;
import com.boydti.fawe.bukkit.listener.ChunkListener_8;
import com.boydti.fawe.bukkit.listener.ChunkListener_9;
import com.boydti.fawe.bukkit.listener.RenderListener;
@ -62,8 +63,7 @@ public class FaweBukkit implements IFawe, Listener {
private boolean listeningImages;
private BukkitImageListener imageListener;
public static boolean PAPER;
private CFIPacketListener packetListener;
public VaultUtil getVault() {
return this.vault;
@ -71,13 +71,6 @@ public class FaweBukkit implements IFawe, Listener {
public FaweBukkit(Plugin plugin) {
this.plugin = plugin;
try {
Class.forName("com.destroystokyo.paper.Namespaced");
PAPER = true;
} catch (Throwable e) {
e.printStackTrace();
// TODO no paper
}
try {
Settings.IMP.TICK_LIMITER.ENABLED = !Bukkit.hasWhitelist();
Fawe.set(this);
@ -115,13 +108,13 @@ public class FaweBukkit implements IFawe, Listener {
});
}
// @Override // Please don't delete this again, it's WIP
// public void registerPacketListener() {
// PluginManager manager = Bukkit.getPluginManager();
// if (packetListener == null && manager.getPlugin("ProtocolLib") != null) {
// packetListener = new CFIPacketListener(plugin);
// }
// }
@Override // Please don't delete this again, it's WIP
public void registerPacketListener() {
PluginManager manager = Bukkit.getPluginManager();
if (packetListener == null && manager.getPlugin("ProtocolLib") != null) {
packetListener = new CFIPacketListener(plugin);
}
}
@Override
public QueueHandler getQueueHandler() {
@ -133,7 +126,7 @@ public class FaweBukkit implements IFawe, Listener {
if (listeningImages && imageListener == null) return null;
try {
listeningImages = true;
//registerPacketListener();
registerPacketListener();
PluginManager manager = Bukkit.getPluginManager();
if (manager.getPlugin("PacketListenerApi") == null) {
@ -408,7 +401,7 @@ public class FaweBukkit implements IFawe, Listener {
@Override
public Preloader getPreloader() {
if (PAPER) {
if (PaperLib.isPaper()) {
return new AsyncPreloader();
}
return null;

View File

@ -12,6 +12,7 @@ import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import net.jpountz.util.UnsafeUtils;
import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.Chunk;
@ -145,7 +146,7 @@ public final class BukkitAdapter_1_14 {
if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(X, Z);
}
if (FaweBukkit.PAPER) {
if (PaperLib.isPaper()) {
CraftWorld craftWorld = nmsWorld.getWorld();
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(X, Z, true);
try {

View File

@ -57,6 +57,7 @@ import java.util.Locale;
import java.util.Map;
import javax.annotation.Nullable;
import io.papermc.lib.PaperLib;
import org.bukkit.Effect;
import org.bukkit.TreeType;
import org.bukkit.World;
@ -328,7 +329,7 @@ public class BukkitWorld extends AbstractWorld {
if (Fawe.isMainThread()) {
world.getChunkAt(X, Z);
} else if (!world.isChunkLoaded(X, Z)) {
if (FaweBukkit.PAPER) {
if (PaperLib.isPaper()) {
world.getChunkAtAsync(X, Z, true);
} else {
Fawe.get().getQueueHandler().sync(() -> {

View File

@ -219,8 +219,6 @@ public enum FaweCache implements Trimable {
public final CleanableThreadLocal<byte[]> BYTE_BUFFER_8192 = new CleanableThreadLocal<>(() -> new byte[8192]);
public final CleanableThreadLocal<byte[]> BYTE_BUFFER_256 = new CleanableThreadLocal<>(() -> new byte[256]);
public final CleanableThreadLocal<int[]> BLOCK_TO_PALETTE = new CleanableThreadLocal<>(() -> {
int[] result = new int[BlockTypesCache.states.length];
Arrays.fill(result, Integer.MAX_VALUE);
@ -243,6 +241,8 @@ public enum FaweCache implements Trimable {
public final CleanableThreadLocal<int[]> INDEX_STORE = new CleanableThreadLocal<>(() -> new int[256]);
public final CleanableThreadLocal<int[]> HEIGHT_STORE = new CleanableThreadLocal<>(() -> new int[256]);
/**
* Holds data for a palette used in a chunk section
*/

View File

@ -36,6 +36,8 @@ public interface IFawe {
return null;
}
public default void registerPacketListener() {}
String getPlatformVersion();
boolean isOnlineMode();

View File

@ -1,9 +1,5 @@
package com.boydti.fawe.command;
import static com.boydti.fawe.util.image.ImageUtil.load;
import static com.sk89q.worldedit.command.MethodCommands.getArguments;
import static com.sk89q.worldedit.util.formatting.text.TextComponent.newline;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.beta.implementation.filter.block.SingleFilterBlock;
@ -19,6 +15,7 @@ import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.TextureUtil;
import com.boydti.fawe.util.image.ImageUtil;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.sk89q.minecraft.util.commands.CommandException;
@ -28,6 +25,7 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
@ -39,6 +37,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.registry.state.PropertyKey;
@ -48,6 +47,7 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TextComponent.Builder;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
@ -56,6 +56,18 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.CommandManagerService;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch;
import org.enginehub.piston.exception.StopExecutionException;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.part.SubCommandPart;
import org.jetbrains.annotations.NotNull;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.ByteArrayOutputStream;
@ -73,16 +85,12 @@ import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.imageio.ImageIO;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch;
import org.enginehub.piston.exception.StopExecutionException;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.jetbrains.annotations.NotNull;
import static com.boydti.fawe.util.image.ImageUtil.load;
import static com.sk89q.worldedit.command.MethodCommands.getArguments;
import static com.sk89q.worldedit.util.formatting.text.TextComponent.newline;
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class CFICommands {
@ -132,7 +140,7 @@ public class CFICommands {
desc = "Start CFI with an empty map as a base"
)
@CommandPermissions("worldedit.anvil.cfi")
public void heightMap(Player player, int width, int length) {
public void empty(Player player, @Arg(desc = "Map width (x)") int width, @Arg(desc = "Map length (z)") int length) {
HeightMapMCAGenerator generator = new HeightMapMCAGenerator(width, length, getFolder(generateName()));
setup(generator, player);
}
@ -148,6 +156,7 @@ public class CFICommands {
settings.setGenerator(generator).bind();
generator.setImageViewer(Fawe.imp().getImageViewer(player));
generator.update();
settings.bind();
mainMenu(player);
}
@ -588,7 +597,7 @@ public class CFICommands {
descFooter = "Set the terrain height either based on an image heightmap, or a numeric value."
)
@CommandPermissions("worldedit.anvil.cfi")
public void height(Player player, String imageStr) throws WorldEditException {
public void height(Player player, @Arg(name = "height", desc = "Int height, or image") String imageStr) throws WorldEditException {
HeightMapMCAGenerator gen = assertSettings(player).getGenerator();
if (!MathMan.isInteger(imageStr)) {
gen.setHeight(ImageUtil.getImage(imageStr));
@ -604,7 +613,7 @@ public class CFICommands {
desc = "Change the block used for water\ne.g. Lava"
)
@CommandPermissions("worldedit.anvil.cfi")
public void waterId(Player player, BlockStateHolder block) throws WorldEditException {
public void waterId(Player player, @Arg(desc = "block") BlockStateHolder block) throws WorldEditException {
CFISettings settings = assertSettings(player);
settings.getGenerator().setWater(block.toImmutableState());
@ -619,7 +628,7 @@ public class CFICommands {
desc = "Change the block used for the base\ne.g. Bedrock"
)
@CommandPermissions("worldedit.anvil.cfi")
public void baseId(Player player, BlockStateHolder block) throws WorldEditException {
public void baseId(Player player, @Arg(desc = "block") BlockStateHolder block) throws WorldEditException {
CFISettings settings = assertSettings(player);
settings.getGenerator().setBedrock(block.toImmutableState());
player.print(TextComponent.of("Set base id!"));

View File

@ -90,8 +90,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
int worldThickness;
boolean randomVariation = true;
int biomePriority;
char waterOrdinal = BlockID.WATER;
char bedrockOrdinal = BlockID.BEDROCK;
char waterOrdinal = BlockTypes.WATER.getDefaultState().getOrdinalChar();
char bedrockOrdinal = BlockTypes.BEDROCK.getDefaultState().getOrdinalChar();
boolean modifiedMain;
@Override
@ -232,10 +232,10 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
floor = new DifferentialArray<>(new char[getArea()]);
main = new DifferentialArray<>(new char[getArea()]);
char stone = BlockID.STONE;
char grass = BlockTypes.GRASS_BLOCK.getDefaultState().with(PropertyKey.SNOWY, false).getOrdinalChar();
Arrays.fill(overlay.getCharArray(), stone);
Arrays.fill(overlay.getCharArray(), grass);
char stone = BlockTypes.STONE.getDefaultState().getOrdinalChar();
char grass = BlockTypes.GRASS_BLOCK.getDefaultState().getOrdinalChar();
Arrays.fill(main.getCharArray(), stone);
Arrays.fill(floor.getCharArray(), grass);
}
public Metadatable getMetaData() {
@ -1584,7 +1584,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
int index;
int maxY = 0;
int minY = Integer.MAX_VALUE;
byte[] heightMap = FaweCache.IMP.BYTE_BUFFER_256.get();
int[] heightMap = FaweCache.IMP.HEIGHT_STORE.get();
int globalIndex;
for (int z = csz; z <= cez; z++) {
globalIndex = z * getWidth() + csx;
@ -1592,7 +1592,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int x = csx; x <= cex; x++, index++, globalIndex++) {
indexes[index] = globalIndex;
int height = heights[globalIndex] & 0xFF;
heightMap[index] = (byte) height;
heightMap[index] = height;
maxY = Math.max(maxY, height);
minY = Math.min(minY, height);
}
@ -1638,7 +1638,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
index = (z & 15) << 4;
for (int x = csx; x <= cex; x++, index++) {
globalIndex = indexes[index];
int height = heightMap[index] & 0xFF;
int height = heightMap[index];
int maxMainY = height;
int minMainY = minY;

View File

@ -726,7 +726,7 @@ public class LocalSession implements TextureHolder {
}
}
if (world != null) {
//TODO FIXME Fawe.imp().registerPacketListener();
Fawe.imp().registerPacketListener();
world.update();
}
}

View File

@ -84,12 +84,18 @@ public class ApplyBrushCommands {
);
builder.condition(new PermissionCondition(ImmutableSet.of("worldedit.brush.apply")));
builder.addParts(REGION_FACTORY, RADIUS);
builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), TextComponent.of("Type of brush to use"))
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
builder.addParts(REGION_FACTORY, RADIUS);
builder.action(new org.enginehub.piston.Command.Action() {
@Override
public Object run(CommandParameters commandParameters) throws Exception {
System.out.println("Action " + commandParameters);
return null;
}
});
});
}
@ -109,6 +115,7 @@ public class ApplyBrushCommands {
Player player, LocalSession localSession,
@Arg(desc = "The type of tree to plant")
TreeGenerator.TreeType type) throws WorldEditException {
System.out.println("FOREST");
setApplyBrush(parameters, player, localSession, new TreeGeneratorFactory(type));
}

View File

@ -26,6 +26,8 @@ import com.boydti.fawe.command.CFICommands;
import com.boydti.fawe.command.CFICommandsRegistration;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.brush.visualization.cfi.HeightMapMCAGenerator;
import com.boydti.fawe.object.changeset.CFIChangeSet;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.task.ThrowableSupplier;
import com.boydti.fawe.util.StringMan;
@ -140,6 +142,7 @@ import org.enginehub.piston.converter.ArgumentConverters;
import org.enginehub.piston.exception.CommandException;
import org.enginehub.piston.exception.CommandExecutionException;
import org.enginehub.piston.exception.ConditionFailedException;
import org.enginehub.piston.exception.StopExecutionException;
import org.enginehub.piston.exception.UsageException;
import org.enginehub.piston.gen.CommandRegistration;
import org.enginehub.piston.impl.CommandManagerServiceImpl;
@ -293,6 +296,9 @@ public final class PlatformCommandManager {
return editSession;
});
});
globalInjectedValues.injectValue(Key.of(CFICommands.CFISettings.class),
context -> context.injectedValue(Key.of(Actor.class))
.orElseThrow(() -> new IllegalStateException("No CFI Settings")).getMeta("CFISettings"));
globalInjectedValues.injectValue(Key.of(World.class),
context -> {
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
@ -742,6 +748,21 @@ public final class PlatformCommandManager {
worldEdit.flushBlockBag(actor, editSession);
}
Optional<CFICommands.CFISettings> cfiOpt = context.injectedValue(Key.of(CFICommands.CFISettings.class));
if (cfiOpt.isPresent()) {
CFICommands.CFISettings settings = cfiOpt.get();
HeightMapMCAGenerator gen = settings.getGenerator();
if (gen != null && gen.isModified()) {
try {
gen.update();
CFIChangeSet set = new CFIChangeSet(gen, actor.getUniqueId());
session.remember(actor, gen, set, actor.getLimit());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Request.reset();
}

View File

@ -1,5 +1,6 @@
package com.sk89q.worldedit.extension.platform.binding;
import com.boydti.fawe.command.CFICommands;
import com.boydti.fawe.util.TextureUtil;
import com.boydti.fawe.util.image.ImageUtil;
import com.sk89q.worldedit.EditSession;