Skip to content

Commit

Permalink
[NeoForge] Port chunk section editing
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Sep 12, 2024
1 parent 1a06c36 commit 6c85b7b
Show file tree
Hide file tree
Showing 24 changed files with 765 additions and 197 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target
forge-download
out
run
runs/
.jqwik-database

/dependency-reduced-pom.xml
Expand Down
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[plugins]
codecov = "org.enginehub.codecov:0.2.0"
neogradle-userdev = "net.neoforged.gradle.userdev:7.0.142"
neogradle-userdev = { id = "net.neoforged.gradle.userdev", version.ref = "neogradle" }
fabric-loom = "fabric-loom:1.7.3"
sponge-spongegradle = "org.spongepowered.gradle.plugin:2.2.0"
sponge-vanillagradle = { id = "org.spongepowered.gradle.vanilla", version.ref = "sponge-vanillagradle" }
Expand All @@ -14,6 +14,7 @@ antlr = "4.13.1"
fabric-api = "0.100.3+1.21"

neoforge-minecraft = "1.21"
neogradle = "7.0.163"

sponge-minecraft = "1.21"
# https://repo.spongepowered.org/service/rest/repository/browse/maven-public/org/spongepowered/spongeapi/
Expand All @@ -36,7 +37,7 @@ lang-worldeditBase = "7.3.4"
lang-version = "1450"

[libraries]
neogradle-neoform = "net.neoforged.gradle:neoform:7.0.142"
neogradle-neoform = { module = "net.neoforged.gradle:neoform", version.ref = "neogradle" }
sponge-vanillagradle = { module = "org.spongepowered:vanillagradle", version.ref = "sponge-vanillagradle" }

licenser = "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1"
Expand Down Expand Up @@ -90,7 +91,7 @@ fabric-minecraft = "com.mojang:minecraft:1.21"
fabric-loader = "net.fabricmc:fabric-loader:0.15.11"
fabric-permissions-api = "me.lucko:fabric-permissions-api:0.3.1"

neoforge = "net.neoforged:neoforge:21.0.16-beta"
neoforge = "net.neoforged:neoforge:21.0.167"

# Mojang-provided libraries, CHECK AGAINST MINECRAFT for versions
guava = "com.google.guava:guava:32.1.3-jre!!"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.collection;

import it.unimi.dsi.fastutil.shorts.AbstractShortCollection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.wna;

import com.sk89q.worldedit.world.block.BlockState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.wna;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.wna;

import com.sk89q.worldedit.internal.util.collection.ChunkSectionMask;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.wna;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public class WNASharedImpl {
public static <B extends BlockStateHolder<B>> boolean setBlock(
NativeAdapter adapter, NativeWorld nativeWorld, BlockVector3 position, B block, SideEffectSet sideEffects
NativeWorld nativeWorld, BlockVector3 position, B block, SideEffectSet sideEffects
) throws WorldEditException {
checkNotNull(position);
checkNotNull(block);
Expand All @@ -49,9 +49,9 @@ public static <B extends BlockStateHolder<B>> boolean setBlock(

// First set the block
NativeChunk chunk = nativeWorld.getChunk(x >> 4, z >> 4);
NativePosition pos = adapter.newBlockPos(x, y, z);
NativePosition pos = nativeWorld.getAdapter().newBlockPos(x, y, z);
NativeBlockState old = chunk.getBlockState(pos);
NativeBlockState newState = adapter.toNative(block.toImmutableState());
NativeBlockState newState = nativeWorld.getAdapter().toNative(block.toImmutableState());
// change block prior to placing if it should be fixed
if (sideEffects.shouldApply(SideEffect.VALIDATION)) {
newState = newState.updateFromNeighbourShapes(nativeWorld, pos);
Expand Down Expand Up @@ -100,12 +100,11 @@ public static String extractNbtId(LinCompoundTag tag) {
}

public static void applySideEffects(
NativeAdapter adapter, NativeWorld nativeWorld, SideEffectSet sideEffectSet, BlockVector3 position,
BlockState previousType
NativeWorld nativeWorld, SideEffectSet sideEffectSet, BlockVector3 position, BlockState previousType
) {
NativePosition pos = adapter.newBlockPos(position.x(), position.y(), position.z());
NativePosition pos = nativeWorld.getAdapter().newBlockPos(position.x(), position.y(), position.z());
NativeChunk chunk = nativeWorld.getChunk(position.x() >> 4, position.z() >> 4);
NativeBlockState oldData = adapter.toNative(previousType);
NativeBlockState oldData = nativeWorld.getAdapter().toNative(previousType);
NativeBlockState newData = chunk.getBlockState(pos);

applySideEffectsNoLookups(nativeWorld, chunk, sideEffectSet, pos, oldData, newData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ public Path getStoragePath() {
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, SideEffectSet sideEffects) throws WorldEditException {
clearContainerBlockContents(position);
return WNASharedImpl.setBlock(FabricAdapter.asNativeAdapter(), getNativeInterface(), position, block, sideEffects);
return WNASharedImpl.setBlock(getNativeInterface(), position, block, sideEffects);
}

@Override
public Set<SideEffect> applySideEffects(BlockVector3 position, BlockState previousType, SideEffectSet sideEffectSet) {
WNASharedImpl.applySideEffects(FabricAdapter.asNativeAdapter(), getNativeInterface(), sideEffectSet, position, previousType);
WNASharedImpl.applySideEffects(getNativeInterface(), sideEffectSet, position, previousType);
return Sets.intersection(FabricWorldEdit.inst.getPlatform().getSupportedSideEffects(), sideEffectSet.getSideEffectsToApply());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.mixin;

import com.mojang.serialization.MapCodec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.mixin;

import com.google.common.base.Preconditions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.mixin;

import com.sk89q.worldedit.internal.wna.NativePosition;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.mixin;

import com.sk89q.worldedit.fabric.FabricAdapter;
Expand Down
4 changes: 2 additions & 2 deletions worldedit-neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ runs {
runtime(apiClasspath)
}
}
named("client").configure(runConfig)
named("server").configure(runConfig)
register("client", runConfig)
register("server", runConfig)
}

subsystems {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.NativeAdapter;
import com.sk89q.worldedit.internal.wna.NativeBlockState;
import com.sk89q.worldedit.internal.wna.NativePosition;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.neoforge.internal.NBTConverter;
Expand Down Expand Up @@ -68,6 +71,26 @@
import static com.google.common.base.Preconditions.checkNotNull;

public final class NeoForgeAdapter {
private static final NativeAdapter NATIVE_ADAPTER = new NativeAdapter() {
@Override
public NativeBlockState toNative(BlockState state) {
return (NativeBlockState) NeoForgeAdapter.adapt(state);
}

@Override
public BlockState fromNative(NativeBlockState state) {
return NeoForgeAdapter.adapt((net.minecraft.world.level.block.state.BlockState) state);
}

@Override
public NativePosition newBlockPos(int x, int y, int z) {
return (NativePosition) new BlockPos(x, y, z);
}
};

public static NativeAdapter asNativeAdapter() {
return NATIVE_ADAPTER;
}

private NeoForgeAdapter() {
}
Expand Down
Loading

0 comments on commit 6c85b7b

Please sign in to comment.