Merge branch 'version/7.2.x'

This commit is contained in:
Octavia Togami 2021-03-10 01:59:36 -08:00
commit 3194af3aa7
No known key found for this signature in database
GPG Key ID: 36855DB2BA11CF6C
26 changed files with 516 additions and 171 deletions

4
.gitattributes vendored
View File

@ -1,6 +1,6 @@
* text=lf
* text=auto eol=lf
# Force Batch files to CRLF
*.bat text=crlf
*.bat eol=crlf -text
# Java sources
*.java text diff=java

View File

@ -1,3 +1,11 @@
7.2.3
- [Forge/Fabric] Added -mod jar file containing both Fabric and Forge
- [Forge/Fabric] Speed up WorldEdit<->Native block translation layer in some cases
- [Fabric] Disable support for the UPDATE side effect when Carpet or QuickCarpet are available, due to conflict
- Improve performance when working with tile entities
- [Bukkit] Further tile entity performance improvements when using Paper (not Spigot)
- Speed up initialisation from registries at startup, especially when many mods are in use
7.2.2
- [Bukkit] Add support for MC 1.16.5.
- [Fabric] Add support for Lucko's Fabric Permissions API.

View File

@ -5,6 +5,26 @@
jacoco
}
if (!project.hasProperty("gitCommitHash")) {
apply(plugin = "org.ajoberstar.grgit")
ext["gitCommitHash"] = try {
extensions.getByName<Grgit>("grgit").head()?.abbreviatedId
} catch (e: Exception) {
logger.warn("Error getting commit hash", e)
"no.git.id"
}
}
// Work around https://github.com/gradle/gradle/issues/4823
subprojects {
if (buildscript.sourceFile?.extension?.toLowerCase() == "kts"
&& parent != rootProject) {
generateSequence(parent) { project -> project.parent.takeIf { it != rootProject } }
.forEach { evaluationDependsOn(it.path) }
}
}
logger.lifecycle("""
*******************************************
You are building WorldEdit!
@ -53,14 +73,3 @@
codecov {
reportTask.set(totalReport)
}
if (!project.hasProperty("gitCommitHash")) {
apply(plugin = "org.ajoberstar.grgit")
ext["gitCommitHash"] = try {
extensions.getByName<Grgit>("grgit").head()?.abbreviatedId
} catch (e: Exception) {
logger.warn("Error getting commit hash", e)
"no.git.id"
}
}

View File

@ -1,8 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.minecrell.gradle.licenser.LicenseExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.quality.CheckstyleExtension
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile
@ -40,6 +37,7 @@
options.compilerArgs.addAll(listOf("-Xlint:all") + disabledLint.map { "-Xlint:-$it" })
options.isDeprecation = true
options.encoding = "UTF-8"
options.compilerArgs.add("-parameters")
}
configure<CheckstyleExtension> {
@ -130,12 +128,24 @@
.flatMap { listOf(it, "WorldEdit/$it") }
.joinToString(separator = " ")
fun Project.addJarManifest(includeClasspath: Boolean = false) {
sealed class WorldEditKind(
val name: String,
val mainClass: String = "com.sk89q.worldedit.internal.util.InfoEntryPoint"
) {
class Standalone(mainClass: String) : WorldEditKind("STANDALONE", mainClass)
object Mod : WorldEditKind("MOD")
object Plugin : WorldEditKind("PLUGIN")
}
fun Project.addJarManifest(kind: WorldEditKind, includeClasspath: Boolean = false) {
tasks.named<Jar>("jar") {
val version = project(":worldedit-core").version
inputs.property("version", version)
val attributes = mutableMapOf(
"WorldEdit-Version" to version
"Implementation-Version" to version,
"WorldEdit-Version" to version,
"WorldEdit-Kind" to kind.name,
"Main-Class" to kind.mainClass
)
if (includeClasspath) {
attributes["Class-Path"] = CLASSPATH

View File

@ -60,7 +60,13 @@ Checks based on Google Checks, modified for EngineHub.
<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. (4.1.3)"/>
</module>
<module name="NoWhitespaceBefore"/>
<module name="NoWhitespaceBefore">
<property name="tokens" value="COMMA, POST_INC, POST_DEC, ELLIPSIS, LABELED_STAT"/>
</module>
<module name="NoWhitespaceBefore">
<property name="tokens" value="SEMI"/>
<property name="allowLineBreaks" value="true"/>
</module>
<module name="OneStatementPerLine"/>
<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>

View File

@ -4,5 +4,5 @@ version=7.3.0-SNAPSHOT
org.gradle.jvmargs=-Xmx1512M
org.gradle.parallel=true
loom.version=0.5.43
mixin.version=0.8.1+build.21
loom.version=0.6.50
mixin.version=0.9.2+mixin.0.8.2

View File

@ -44,7 +44,7 @@
exclude("**/worldedit-adapters.jar")
}
addJarManifest(includeClasspath = true)
addJarManifest(WorldEditKind.Plugin, includeClasspath = true)
tasks.named<ShadowJar>("shadowJar") {
from(zipTree("src/main/resources/worldedit-adapters.jar").matching {

View File

@ -245,7 +245,7 @@ private Inventory getBlockInventory(Chest chest) {
@Override
public boolean clearContainerBlockContents(BlockVector3 pt) {
checkNotNull(pt);
if (getBlock(pt).getBlockType().getMaterial().hasContainer()) {
if (!getBlock(pt).getBlockType().getMaterial().hasContainer()) {
return false;
}

View File

@ -6,6 +6,7 @@
applyPlatformAndCoreConfiguration()
applyShadowConfiguration()
addJarManifest(WorldEditKind.Standalone("com.sk89q.worldedit.cli.CLIWorldEdit"))
dependencies {
"api"(project(":worldedit-core"))
@ -17,15 +18,6 @@
"implementation"("com.google.code.gson:gson")
}
tasks.named<Jar>("jar") {
manifest {
attributes(
"Implementation-Version" to project.version,
"Main-Class" to "com.sk89q.worldedit.cli.CLIWorldEdit"
)
}
}
tasks.named<ShadowJar>("shadowJar") {
dependencies {
include { true }

View File

@ -34,11 +34,32 @@
public class WorldEditManifest {
public static final String WORLD_EDIT_VERSION = "WorldEdit-Version";
public static final String WORLD_EDIT_KIND = "WorldEdit-Kind";
public enum Kind {
MOD("mods"),
PLUGIN("plugins"),
UNKNOWN("mods/plugins"),
;
public final String folderName;
Kind(String folderName) {
this.folderName = folderName;
}
}
public static WorldEditManifest load() {
Attributes attributes = readAttributes();
Kind kind;
try {
kind = Kind.valueOf(readAttribute(attributes, WORLD_EDIT_KIND, () -> "UNKNOWN"));
} catch (IllegalArgumentException e) {
kind = Kind.UNKNOWN;
}
return new WorldEditManifest(
readAttribute(attributes, WORLD_EDIT_VERSION, () -> "(unknown)")
readAttribute(attributes, WORLD_EDIT_VERSION, () -> "(unknown)"),
kind
);
}
@ -70,12 +91,18 @@ private static String readAttribute(@Nullable Attributes attributes, String name
}
private final String worldEditVersion;
private final Kind worldEditKind;
private WorldEditManifest(String worldEditVersion) {
private WorldEditManifest(String worldEditVersion, Kind worldEditKind) {
this.worldEditVersion = worldEditVersion;
this.worldEditKind = worldEditKind;
}
public String getWorldEditVersion() {
return worldEditVersion;
}
public Kind getWorldEditKind() {
return worldEditKind;
}
}

View File

@ -0,0 +1,90 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.internal.util;
import com.sk89q.worldedit.WorldEditManifest;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
public class InfoEntryPoint {
private static final String INSTALL_URL = "https://worldedit.enginehub.org/en/latest/install/";
private static final String SUPPORT_URL = "https://discord.gg/enginehub";
private static String getMessage(boolean html) {
WorldEditManifest manifest = WorldEditManifest.load();
return "To install WorldEdit, place it in the "
+ manifest.getWorldEditKind().folderName + " folder.\n"
+ "For more detailed instructions, see " + formatLink(INSTALL_URL, html) + "\n"
+ "For further help, check out our support Discord at "
+ formatLink(SUPPORT_URL, html) + "\n"
+ "\n"
+ "Version: " + manifest.getWorldEditVersion() + "\n";
}
private static String formatLink(String url, boolean html) {
return html ? String.format("<a href=\"%1$s\">%1$s</a>", url) : url;
}
public static void main(String[] args) {
if (System.console() != null) {
System.err.println(getMessage(false));
} else {
System.setProperty("awt.useSystemAAFontSettings", "lcd");
JOptionPane.showMessageDialog(
null,
new NavigableEditorPane(getMessage(true)),
"WorldEdit",
JOptionPane.INFORMATION_MESSAGE
);
}
System.exit(1);
}
private static class NavigableEditorPane extends JTextPane {
public NavigableEditorPane(String htmlBody) {
super(new HTMLDocument());
setEditorKit(new HTMLEditorKit());
setText(htmlBody.replace("\n", "<br>"));
setBackground(UIManager.getColor("Panel.background"));
addHyperlinkListener(e -> {
if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (IOException | URISyntaxException ex) {
ex.printStackTrace();
}
}
});
setEditable(false);
setBorder(null);
}
}
}

View File

@ -19,12 +19,14 @@
package com.sk89q.worldedit.world.block;
import com.google.common.collect.ArrayTable;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Watchdog;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.concurrency.LazyReference;
@ -79,7 +81,7 @@ public void setInternalId(BlockState blockState, int internalId) {
}
static Map<Map<Property<?>, Object>, BlockState> generateStateMap(BlockType blockType) {
Map<Map<Property<?>, Object>, BlockState> stateMap = new LinkedHashMap<>();
ImmutableMap.Builder<Map<Property<?>, Object>, BlockState> stateMapBuilder = ImmutableMap.builder();
List<? extends Property<?>> properties = blockType.getProperties();
if (!properties.isEmpty()) {
@ -99,29 +101,38 @@ static Map<Map<Property<?>, Object>, BlockState> generateStateMap(BlockType bloc
valueMap.put(property, value);
stateMaker.setState(property, value);
}
stateMap.put(valueMap, stateMaker);
stateMapBuilder.put(ImmutableMap.copyOf(valueMap), stateMaker);
}
}
ImmutableMap<Map<Property<?>, Object>, BlockState> stateMap = stateMapBuilder.build();
if (stateMap.isEmpty()) {
// No properties.
stateMap.put(new LinkedHashMap<>(), new BlockState(blockType));
stateMap = ImmutableMap.of(ImmutableMap.of(), new BlockState(blockType));
}
for (BlockState state : stateMap.values()) {
state.populate(stateMap);
}
// Sometimes loading can take a while. This is the perfect spot to let MC know we're working.
Watchdog watchdog = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
.getWatchdog();
if (watchdog != null) {
watchdog.tick();
}
return stateMap;
}
private void populate(Map<Map<Property<?>, Object>, BlockState> stateMap) {
final Table<Property<?>, Object, BlockState> states = HashBasedTable.create();
final ImmutableTable.Builder<Property<?>, Object, BlockState> states = ImmutableTable.builder();
for (final Map.Entry<Property<?>, Object> entry : this.values.entrySet()) {
final Property<Object> property = (Property<Object>) entry.getKey();
property.getValues().forEach(value -> {
for (Object value : property.getValues()) {
if (value != entry.getValue()) {
BlockState modifiedState = stateMap.get(this.withValue(property, value));
if (modifiedState != null) {
@ -131,16 +142,22 @@ private void populate(Map<Map<Property<?>, Object>, BlockState> stateMap) {
WorldEdit.logger.warn("Found a null state at " + this.withValue(property, value));
}
}
});
}
}
this.states = states.isEmpty() ? states : ArrayTable.create(states);
this.states = states.build();
}
private <V> Map<Property<?>, Object> withValue(final Property<V> property, final V value) {
final Map<Property<?>, Object> values = Maps.newHashMap(this.values);
values.put(property, value);
return values;
final ImmutableMap.Builder<Property<?>, Object> values = ImmutableMap.builder();
for (Map.Entry<Property<?>, Object> entry : this.values.entrySet()) {
if (entry.getKey().equals(property)) {
values.put(entry.getKey(), value);
} else {
values.put(entry);
}
}
return values.build();
}
@Override

View File

@ -131,7 +131,7 @@
}
}
addJarManifest(includeClasspath = true)
addJarManifest(WorldEditKind.Mod, includeClasspath = true)
tasks.named<ShadowJar>("shadowJar") {
archiveClassifier.set("dist-dev")

View File

@ -21,7 +21,9 @@
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.fabric.internal.FabricTransmogrifier;
import com.sk89q.worldedit.fabric.internal.NBTConverter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.registry.state.BooleanProperty;
@ -48,7 +50,6 @@
import net.minecraft.nbt.Tag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.util.Identifier;
import net.minecraft.util.StringIdentifiable;
@ -143,28 +144,20 @@ public static BlockPos toBlockPos(BlockVector3 vector) {
return new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}
/**
* Adapts property.
* @deprecated without replacement, use the block adapter methods
*/
@Deprecated
public static Property<?> adaptProperty(net.minecraft.state.property.Property<?> property) {
if (property instanceof net.minecraft.state.property.BooleanProperty) {
return new BooleanProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.property.BooleanProperty) property).getValues()));
}
if (property instanceof net.minecraft.state.property.IntProperty) {
return new IntegerProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.property.IntProperty) property).getValues()));
}
if (property instanceof DirectionProperty) {
return new DirectionalProperty(property.getName(), ((DirectionProperty) property).getValues().stream()
.map(FabricAdapter::adaptEnumFacing)
.collect(Collectors.toList()));
}
if (property instanceof net.minecraft.state.property.EnumProperty) {
// Note: do not make x.asString a method reference.
// It will cause runtime bootstrap exceptions.
return new EnumProperty(property.getName(), ((net.minecraft.state.property.EnumProperty<?>) property).getValues().stream()
.map(x -> x.asString())
.collect(Collectors.toList()));
}
return new PropertyAdapter<>(property);
return FabricTransmogrifier.transmogToWorldEditProperty(property);
}
/**
* Adapts properties.
* @deprecated without replacement, use the block adapter methods
*/
@Deprecated
public static Map<Property<?>, Object> adaptProperties(BlockType block, Map<net.minecraft.state.property.Property<?>, Comparable<?>> mcProps) {
Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName));
for (Map.Entry<net.minecraft.state.property.Property<?>, Comparable<?>> prop : mcProps.entrySet()) {
@ -179,38 +172,21 @@ public static Map<Property<?>, Object> adaptProperties(BlockType block, Map<net.
return props;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private static net.minecraft.block.BlockState applyProperties(StateManager<Block, net.minecraft.block.BlockState> stateContainer,
net.minecraft.block.BlockState newState, Map<Property<?>, Object> states) {
for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
net.minecraft.state.property.Property property = stateContainer.getProperty(state.getKey().getName());
Comparable value = (Comparable) state.getValue();
// we may need to adapt this value, depending on the source prop
if (property instanceof DirectionProperty) {
Direction dir = (Direction) value;
value = adapt(dir);
} else if (property instanceof net.minecraft.state.property.EnumProperty) {
String enumName = (String) value;
value = ((net.minecraft.state.property.EnumProperty<?>) property).parse((String) value).orElseGet(() -> {
throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName);
});
}
newState = newState.with(property, value);
}
return newState;
}
public static net.minecraft.block.BlockState adapt(BlockState blockState) {
Block mcBlock = adapt(blockState.getBlockType());
net.minecraft.block.BlockState newState = mcBlock.getDefaultState();
Map<Property<?>, Object> states = blockState.getStates();
return applyProperties(mcBlock.getStateManager(), newState, states);
int blockStateId = BlockStateIdAccess.getBlockStateId(blockState);
if (!BlockStateIdAccess.isValidInternalId(blockStateId)) {
return FabricTransmogrifier.transmogToMinecraft(blockState);
}
return Block.getStateFromRawId(blockStateId);
}
public static BlockState adapt(net.minecraft.block.BlockState blockState) {
BlockType blockType = adapt(blockState.getBlock());
return blockType.getState(adaptProperties(blockType, blockState.getEntries()));
int blockStateId = Block.getRawIdFromState(blockState);
BlockState worldEdit = BlockStateIdAccess.getBlockStateById(blockStateId);
if (worldEdit == null) {
return FabricTransmogrifier.transmogToWorldEdit(blockState);
}
return worldEdit;
}
public static Block adapt(BlockType blockType) {

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.fabric;
import com.sk89q.worldedit.fabric.internal.FabricTransmogrifier;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
@ -60,7 +61,7 @@ public BlockMaterial getMaterial(BlockType blockType) {
.getDefaultState()
.getProperties();
for (net.minecraft.state.property.Property<?> key : propertyKeys) {
map.put(key.getName(), FabricAdapter.adaptProperty(key));
map.put(key.getName(), FabricTransmogrifier.transmogToWorldEditProperty(key));
}
return map;
}

View File

@ -590,11 +590,6 @@ public BlockState getBlock(BlockVector3 position) {
.getChunk(position.getBlockX() >> 4, position.getBlockZ() >> 4)
.getBlockState(FabricAdapter.toBlockPos(position));
BlockState matchingBlock = BlockStateIdAccess.getBlockStateById(Block.getRawIdFromState(mcState));
if (matchingBlock != null) {
return matchingBlock;
}
return FabricAdapter.adapt(mcState);
}

View File

@ -0,0 +1,119 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.fabric.internal;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.fabric.FabricAdapter;
import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty;
import com.sk89q.worldedit.registry.state.EnumProperty;
import com.sk89q.worldedit.registry.state.IntegerProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.block.BlockType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.util.StringIdentifiable;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
/**
* Raw, un-cached transformations.
*/
public class FabricTransmogrifier {
public static Property<?> transmogToWorldEditProperty(net.minecraft.state.property.Property<?> property) {
if (property instanceof net.minecraft.state.property.BooleanProperty) {
return new BooleanProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.property.BooleanProperty) property).getValues()));
}
if (property instanceof net.minecraft.state.property.IntProperty) {
return new IntegerProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.property.IntProperty) property).getValues()));
}
if (property instanceof DirectionProperty) {
return new DirectionalProperty(property.getName(), ((DirectionProperty) property).getValues().stream()
.map(FabricAdapter::adaptEnumFacing)
.collect(Collectors.toList()));
}
if (property instanceof net.minecraft.state.property.EnumProperty) {
// Note: do not make x.asString a method reference.
// It will cause runtime bootstrap exceptions.
return new EnumProperty(property.getName(), ((net.minecraft.state.property.EnumProperty<?>) property).getValues().stream()
.map(x -> x.asString())
.collect(Collectors.toList()));
}
return new PropertyAdapter<>(property);
}
private static Map<Property<?>, Object> transmogToWorldEditProperties(BlockType block, Map<net.minecraft.state.property.Property<?>, Comparable<?>> mcProps) {
Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName));
for (Map.Entry<net.minecraft.state.property.Property<?>, Comparable<?>> prop : mcProps.entrySet()) {
Object value = prop.getValue();
if (prop.getKey() instanceof DirectionProperty) {
value = FabricAdapter.adaptEnumFacing((net.minecraft.util.math.Direction) value);
} else if (prop.getKey() instanceof net.minecraft.state.property.EnumProperty) {
value = ((StringIdentifiable) value).asString();
}
props.put(block.getProperty(prop.getKey().getName()), value);
}
return props;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private static net.minecraft.block.BlockState transmogToMinecraftProperties(StateManager<Block, BlockState> stateContainer,
net.minecraft.block.BlockState newState, Map<Property<?>, Object> states) {
for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
net.minecraft.state.property.Property property = stateContainer.getProperty(state.getKey().getName());
Comparable value = (Comparable) state.getValue();
// we may need to adapt this value, depending on the source prop
if (property instanceof DirectionProperty) {
Direction dir = (Direction) value;
value = FabricAdapter.adapt(dir);
} else if (property instanceof net.minecraft.state.property.EnumProperty) {
String enumName = (String) value;
value = ((net.minecraft.state.property.EnumProperty<?>) property).parse((String) value).orElseGet(() -> {
throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName);
});
}
newState = newState.with(property, value);
}
return newState;
}
public static net.minecraft.block.BlockState transmogToMinecraft(com.sk89q.worldedit.world.block.BlockState blockState) {
Block mcBlock = FabricAdapter.adapt(blockState.getBlockType());
net.minecraft.block.BlockState newState = mcBlock.getDefaultState();
Map<Property<?>, Object> states = blockState.getStates();
return transmogToMinecraftProperties(mcBlock.getStateManager(), newState, states);
}
public static com.sk89q.worldedit.world.block.BlockState transmogToWorldEdit(net.minecraft.block.BlockState blockState) {
BlockType blockType = FabricAdapter.adapt(blockState.getBlock());
return blockType.getState(transmogToWorldEditProperties(blockType, blockState.getEntries()));
}
private FabricTransmogrifier() {
}
}

View File

@ -20,15 +20,18 @@
package com.sk89q.worldedit.fabric.internal;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import org.objectweb.asm.tree.ClassNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class MixinConfigPlugin implements IMixinConfigPlugin {
private static final Logger LOGGER = LoggerFactory.getLogger(MixinConfigPlugin.class);
@ -45,11 +48,18 @@ public String getRefMapperConfig() {
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (mixinClassName.equals("com.sk89q.worldedit.fabric.mixin.MixinWorldChunkSetBlockHook")) {
boolean carpet = FabricLoader.getInstance().getModContainer("carpet").isPresent();
if (carpet) {
LOGGER.warn("Carpet detected, disabling UPDATE mixin " + mixinClassName);
List<ModContainer> conflictingContainers = Stream.of("carpet", "quickcarpet")
.map(FabricLoader.getInstance()::getModContainer)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
if (!conflictingContainers.isEmpty()) {
List<String> conflictingIds = conflictingContainers.stream()
.map(mc -> mc.getMetadata().getId())
.collect(Collectors.toList());
LOGGER.warn("{} detected, disabling UPDATE mixin {}", conflictingIds, mixinClassName);
}
return !carpet;
return conflictingContainers.isEmpty();
}
return true;
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.fabric;
package com.sk89q.worldedit.fabric.internal;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.registry.state.Property;

View File

@ -91,7 +91,7 @@
from(project(":worldedit-core").tasks.named("processResources"))
}
addJarManifest(includeClasspath = false)
addJarManifest(WorldEditKind.Mod, includeClasspath = false)
tasks.named<ShadowJar>("shadowJar") {
dependencies {

View File

@ -19,15 +19,12 @@
package com.sk89q.worldedit.forge;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.forge.internal.ForgeTransmogrifier;
import com.sk89q.worldedit.forge.internal.NBTConverter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty;
import com.sk89q.worldedit.registry.state.EnumProperty;
import com.sk89q.worldedit.registry.state.IntegerProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.concurrency.LazyReference;
@ -46,7 +43,6 @@
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
@ -60,7 +56,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
@ -135,30 +130,20 @@ public static BlockPos toBlockPos(BlockVector3 vector) {
return new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}
/**
* Adapts property.
* @deprecated without replacement, use the block adapter methods
*/
@Deprecated
public static Property<?> adaptProperty(net.minecraft.state.Property<?> property) {
if (property instanceof net.minecraft.state.BooleanProperty) {
return new BooleanProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.BooleanProperty) property).getAllowedValues()));
}
if (property instanceof net.minecraft.state.IntegerProperty) {
return new IntegerProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.IntegerProperty) property).getAllowedValues()));
}
if (property instanceof DirectionProperty) {
return new DirectionalProperty(property.getName(), ((DirectionProperty) property).getAllowedValues().stream()
.map(ForgeAdapter::adaptEnumFacing)
.collect(Collectors.toList()));
}
if (property instanceof net.minecraft.state.EnumProperty) {
// Note: do not make x.getName a method reference.
// It will cause runtime bootstrap exceptions.
// Temporary: func_176610_l == getName
//noinspection Convert2MethodRef
return new EnumProperty(property.getName(), ((net.minecraft.state.EnumProperty<?>) property).getAllowedValues().stream()
.map(x -> x.func_176610_l())
.collect(Collectors.toList()));
}
return new IPropertyAdapter<>(property);
return ForgeTransmogrifier.transmogToWorldEditProperty(property);
}
/**
* Adapts properties.
* @deprecated without replacement, use the block adapter methods
*/
@Deprecated
public static Map<Property<?>, Object> adaptProperties(BlockType block, Map<net.minecraft.state.Property<?>, Comparable<?>> mcProps) {
Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName));
for (Map.Entry<net.minecraft.state.Property<?>, Comparable<?>> prop : mcProps.entrySet()) {
@ -173,37 +158,21 @@ public static Map<Property<?>, Object> adaptProperties(BlockType block, Map<net.
return props;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static net.minecraft.block.BlockState applyProperties(StateContainer<Block, net.minecraft.block.BlockState> stateContainer, net.minecraft.block.BlockState newState, Map<Property<?>, Object> states) {
for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
net.minecraft.state.Property property = stateContainer.getProperty(state.getKey().getName());
Comparable value = (Comparable) state.getValue();
// we may need to adapt this value, depending on the source prop
if (property instanceof DirectionProperty) {
Direction dir = (Direction) value;
value = adapt(dir);
} else if (property instanceof net.minecraft.state.EnumProperty) {
String enumName = (String) value;
value = ((net.minecraft.state.EnumProperty<?>) property).parseValue((String) value).orElseGet(() -> {
throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName);
});
}
newState = newState.with(property, value);
}
return newState;
}
public static net.minecraft.block.BlockState adapt(BlockState blockState) {
Block mcBlock = adapt(blockState.getBlockType());
net.minecraft.block.BlockState newState = mcBlock.getDefaultState();
Map<Property<?>, Object> states = blockState.getStates();
return applyProperties(mcBlock.getStateContainer(), newState, states);
int blockStateId = BlockStateIdAccess.getBlockStateId(blockState);
if (!BlockStateIdAccess.isValidInternalId(blockStateId)) {
return ForgeTransmogrifier.transmogToMinecraft(blockState);
}
return Block.getStateById(blockStateId);
}
public static BlockState adapt(net.minecraft.block.BlockState blockState) {
BlockType blockType = adapt(blockState.getBlock());
return blockType.getState(adaptProperties(blockType, blockState.getValues()));
int blockStateId = Block.getStateId(blockState);
BlockState worldEdit = BlockStateIdAccess.getBlockStateById(blockStateId);
if (worldEdit == null) {
return ForgeTransmogrifier.transmogToWorldEdit(blockState);
}
return worldEdit;
}
public static Block adapt(BlockType blockType) {

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.forge.internal.ForgeTransmogrifier;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
@ -64,7 +65,7 @@ public BlockMaterial getMaterial(BlockType blockType) {
// func_235904_r_ == getProperties
.func_235904_r_();
for (net.minecraft.state.Property<?> key : propertyKeys) {
map.put(key.getName(), ForgeAdapter.adaptProperty(key));
map.put(key.getName(), ForgeTransmogrifier.transmogToWorldEditProperty(key));
}
return map;
}

View File

@ -601,11 +601,6 @@ public BlockState getBlock(BlockVector3 position) {
.getChunk(position.getBlockX() >> 4, position.getBlockZ() >> 4)
.getBlockState(ForgeAdapter.toBlockPos(position));
BlockState matchingBlock = BlockStateIdAccess.getBlockStateById(Block.getStateId(mcState));
if (matchingBlock != null) {
return matchingBlock;
}
return ForgeAdapter.adapt(mcState);
}

View File

@ -0,0 +1,120 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge.internal;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.forge.ForgeAdapter;
import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty;
import com.sk89q.worldedit.registry.state.EnumProperty;
import com.sk89q.worldedit.registry.state.IntegerProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.block.BlockType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.IStringSerializable;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
/**
* Raw, un-cached transformations.
*/
public class ForgeTransmogrifier {
public static Property<?> transmogToWorldEditProperty(net.minecraft.state.Property<?> property) {
if (property instanceof net.minecraft.state.BooleanProperty) {
return new BooleanProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.BooleanProperty) property).getAllowedValues()));
}
if (property instanceof net.minecraft.state.IntegerProperty) {
return new IntegerProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.IntegerProperty) property).getAllowedValues()));
}
if (property instanceof DirectionProperty) {
return new DirectionalProperty(property.getName(), ((DirectionProperty) property).getAllowedValues().stream()
.map(ForgeAdapter::adaptEnumFacing)
.collect(Collectors.toList()));
}
if (property instanceof net.minecraft.state.EnumProperty) {
// Note: do not make x.getName a method reference.
// It will cause runtime bootstrap exceptions.
// Temporary: func_176610_l == getName
//noinspection Convert2MethodRef
return new EnumProperty(property.getName(), ((net.minecraft.state.EnumProperty<?>) property).getAllowedValues().stream()
.map(x -> x.func_176610_l())
.collect(Collectors.toList()));
}
return new IPropertyAdapter<>(property);
}
public static Map<Property<?>, Object> transmogToWorldEditProperties(BlockType block, Map<net.minecraft.state.Property<?>, Comparable<?>> mcProps) {
Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName));
for (Map.Entry<net.minecraft.state.Property<?>, Comparable<?>> prop : mcProps.entrySet()) {
Object value = prop.getValue();
if (prop.getKey() instanceof DirectionProperty) {
value = ForgeAdapter.adaptEnumFacing((net.minecraft.util.Direction) value);
} else if (prop.getKey() instanceof net.minecraft.state.EnumProperty) {
value = ((IStringSerializable) value).func_176610_l();
}
props.put(block.getProperty(prop.getKey().getName()), value);
}
return props;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static net.minecraft.block.BlockState transmogToMinecraftProperties(StateContainer<Block, BlockState> stateContainer, net.minecraft.block.BlockState newState, Map<Property<?>, Object> states) {
for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
net.minecraft.state.Property property = stateContainer.getProperty(state.getKey().getName());
Comparable value = (Comparable) state.getValue();
// we may need to adapt this value, depending on the source prop
if (property instanceof DirectionProperty) {
Direction dir = (Direction) value;
value = ForgeAdapter.adapt(dir);
} else if (property instanceof net.minecraft.state.EnumProperty) {
String enumName = (String) value;
value = ((net.minecraft.state.EnumProperty<?>) property).parseValue((String) value).orElseGet(() -> {
throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName);
});
}
newState = newState.with(property, value);
}
return newState;
}
public static net.minecraft.block.BlockState transmogToMinecraft(com.sk89q.worldedit.world.block.BlockState blockState) {
Block mcBlock = ForgeAdapter.adapt(blockState.getBlockType());
net.minecraft.block.BlockState newState = mcBlock.getDefaultState();
Map<Property<?>, Object> states = blockState.getStates();
return transmogToMinecraftProperties(mcBlock.getStateContainer(), newState, states);
}
public static com.sk89q.worldedit.world.block.BlockState transmogToWorldEdit(net.minecraft.block.BlockState blockState) {
BlockType blockType = ForgeAdapter.adapt(blockState.getBlock());
return blockType.getState(transmogToWorldEditProperties(blockType, blockState.getValues()));
}
private ForgeTransmogrifier() {
}
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge;
package com.sk89q.worldedit.forge.internal;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.registry.state.Property;

View File

@ -25,7 +25,7 @@
testImplementation("org.mockito:mockito-core:1.9.0-rc1")
}
addJarManifest(includeClasspath = true)
addJarManifest(WorldEditKind.Mod, includeClasspath = true)
tasks.named<ShadowJar>("shadowJar") {
dependencies {