Skip to content

Commit

Permalink
First stab at getting lin-bus integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Jul 11, 2022
1 parent a8b5268 commit d1ebde0
Show file tree
Hide file tree
Showing 95 changed files with 1,464 additions and 1,837 deletions.
19 changes: 17 additions & 2 deletions buildSrc/src/main/kotlin/CommonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ fun Project.applyCommonConfiguration() {
version = rootProject.version

repositories {
mavenCentral()
mavenCentral {
mavenContent {
releasesOnly()
}
}
maven { url = uri("https://maven.enginehub.org/repo/") }
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") }
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
mavenContent {
snapshotsOnly()
}
}
mavenLocal {
content {
includeGroup("org.enginehub.lin-bus")
includeGroup("org.enginehub.lin-bus.format")
}
}
}

configurations.all {
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/LibsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ fun Project.applyLibrariesConfiguration() {
configurations = listOf(project.configurations["shade"])
archiveClassifier.set("")

// Yeet module-info's
exclude("module-info.class")

dependencies {
exclude(dependency("com.google.guava:guava"))
exclude(dependency("com.google.code.gson:gson"))
exclude(dependency("com.google.errorprone:error_prone_annotations"))
exclude(dependency("org.checkerframework:checker-qual"))
exclude(dependency("org.jetbrains:annotations"))
exclude(dependency("org.apache.logging.log4j:log4j-api"))
exclude(dependency("com.google.code.findbugs:jsr305"))
exclude {
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object Versions {
const val GUAVA = "31.0.1-jre"
const val GSON = "2.8.9"
const val LOG4J = "2.17.0"
const val LIN_BUS = "0.1.0-SNAPSHOT"
}

// Properties that need a project reference to resolve:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.common.util.concurrent.Futures;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Lifecycle;
import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
Expand Down Expand Up @@ -68,7 +67,6 @@
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
Expand Down Expand Up @@ -134,6 +132,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.generator.ChunkGenerator;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;

Expand Down Expand Up @@ -536,11 +535,11 @@ public Property<?> load(net.minecraft.world.level.block.state.properties.Propert
}

@Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
public void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
((CraftPlayer) player).getHandle().networkManager.send(new ClientboundBlockEntityDataPacket(
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
7,
(net.minecraft.nbt.CompoundTag) fromNative(AdventureNBTConverter.fromAdventure(nbtData))
(net.minecraft.nbt.CompoundTag) fromNative(new CompoundTag(nbtData))
));
}

Expand Down Expand Up @@ -817,7 +816,7 @@ Tag toNative(net.minecraft.nbt.Tag foreign) {
return null;
}
if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, Tag> values = new HashMap<>();
Map<String, Tag<?, ?>> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();

for (String str : foreignKeys) {
Expand Down Expand Up @@ -885,13 +884,13 @@ private ListTag toNativeList(net.minecraft.nbt.ListTag foreign) throws SecurityE
* @param foreign structure to convert
* @return non-native structure
*/
net.minecraft.nbt.Tag fromNative(Tag foreign) {
net.minecraft.nbt.Tag fromNative(Tag<?, ?> foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign)
for (Map.Entry<String, Tag<?, ?>> entry : ((CompoundTag) foreign)
.getValue().entrySet()) {
tag.put(entry.getKey(), fromNative(entry.getValue()));
}
Expand All @@ -910,10 +909,9 @@ net.minecraft.nbt.Tag fromNative(Tag foreign) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayTag) foreign).getValue());
} else if (foreign instanceof LongArrayTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayTag) foreign).getValue());
} else if (foreign instanceof ListTag) {
} else if (foreign instanceof ListTag<?, ?> foreignList) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListTag foreignList = (ListTag) foreign;
for (Tag t : foreignList.getValue()) {
for (Tag<?, ?> t : foreignList.getValue()) {
tag.add(fromNative(t));
}
return tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

package com.sk89q.worldedit.bukkit.adapter.impl.v1_17_R1_2;

import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
Expand All @@ -38,6 +36,7 @@
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;

import java.lang.ref.WeakReference;
import java.util.Objects;
Expand Down Expand Up @@ -105,13 +104,13 @@ public void updateLightingForBlock(BlockPos position) {
}

@Override
public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
// We will assume that the tile entity was created for us
BlockEntity tileEntity = getWorld().getBlockEntity(position);
if (tileEntity == null) {
return false;
}
Tag nativeTag = adapter.fromNative(AdventureNBTConverter.fromAdventure(tag));
Tag nativeTag = adapter.fromNative(new CompoundTag(tag));
PaperweightAdapter.readTagIntoTileEntity((net.minecraft.nbt.CompoundTag) nativeTag, tileEntity);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.common.util.concurrent.Futures;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Lifecycle;
import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
Expand Down Expand Up @@ -68,7 +67,6 @@
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
Expand Down Expand Up @@ -134,6 +132,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.generator.ChunkGenerator;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;

Expand Down Expand Up @@ -527,13 +526,13 @@ public Property<?> load(net.minecraft.world.level.block.state.properties.Propert
}

@Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
public void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
((CraftPlayer) player).getHandle().networkManager.send(ClientboundBlockEntityDataPacket.create(
new StructureBlockEntity(
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
Blocks.STRUCTURE_BLOCK.defaultBlockState()
),
__ -> (net.minecraft.nbt.CompoundTag) fromNative(AdventureNBTConverter.fromAdventure(nbtData))
__ -> (net.minecraft.nbt.CompoundTag) fromNative(new CompoundTag(nbtData))
));
}

Expand Down Expand Up @@ -806,7 +805,7 @@ Tag toNative(net.minecraft.nbt.Tag foreign) {
return null;
}
if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, Tag> values = new HashMap<>();
Map<String, Tag<?, ?>> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();

for (String str : foreignKeys) {
Expand Down Expand Up @@ -880,7 +879,7 @@ net.minecraft.nbt.Tag fromNative(Tag foreign) {
}
if (foreign instanceof CompoundTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign)
for (Map.Entry<String, Tag<?, ?>> entry : ((CompoundTag) foreign)
.getValue().entrySet()) {
tag.put(entry.getKey(), fromNative(entry.getValue()));
}
Expand All @@ -899,10 +898,9 @@ net.minecraft.nbt.Tag fromNative(Tag foreign) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayTag) foreign).getValue());
} else if (foreign instanceof LongArrayTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayTag) foreign).getValue());
} else if (foreign instanceof ListTag) {
} else if (foreign instanceof ListTag<?, ?> foreignList) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListTag foreignList = (ListTag) foreign;
for (Tag t : foreignList.getValue()) {
for (Tag<?, ?> t : foreignList.getValue()) {
tag.add(fromNative(t));
}
return tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

package com.sk89q.worldedit.bukkit.adapter.impl.v1_18_R2;

import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
Expand All @@ -37,6 +36,7 @@
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;

import java.lang.ref.WeakReference;
import java.util.Objects;
Expand Down Expand Up @@ -104,13 +104,13 @@ public void updateLightingForBlock(BlockPos position) {
}

@Override
public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
// We will assume that the tile entity was created for us
BlockEntity tileEntity = getWorld().getBlockEntity(position);
if (tileEntity == null) {
return false;
}
Tag nativeTag = adapter.fromNative(AdventureNBTConverter.fromAdventure(tag));
Tag nativeTag = adapter.fromNative(new CompoundTag(tag));
PaperweightAdapter.readTagIntoTileEntity((net.minecraft.nbt.CompoundTag) nativeTag, tileEntity);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.common.util.concurrent.Futures;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Lifecycle;
import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
Expand Down Expand Up @@ -68,7 +67,6 @@
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
Expand Down Expand Up @@ -134,6 +132,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.generator.ChunkGenerator;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;

Expand Down Expand Up @@ -526,13 +525,13 @@ public Property<?> load(net.minecraft.world.level.block.state.properties.Propert
}

@Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
public void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
((CraftPlayer) player).getHandle().networkManager.send(ClientboundBlockEntityDataPacket.create(
new StructureBlockEntity(
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
Blocks.STRUCTURE_BLOCK.defaultBlockState()
),
__ -> (net.minecraft.nbt.CompoundTag) fromNative(AdventureNBTConverter.fromAdventure(nbtData))
__ -> (net.minecraft.nbt.CompoundTag) fromNative(new CompoundTag(nbtData))
));
}

Expand Down Expand Up @@ -808,7 +807,7 @@ Tag toNative(net.minecraft.nbt.Tag foreign) {
return null;
}
if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, Tag> values = new HashMap<>();
Map<String, Tag<?, ?>> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();

for (String str : foreignKeys) {
Expand Down Expand Up @@ -882,7 +881,7 @@ net.minecraft.nbt.Tag fromNative(Tag foreign) {
}
if (foreign instanceof CompoundTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign)
for (Map.Entry<String, Tag<?, ?>> entry : ((CompoundTag) foreign)
.getValue().entrySet()) {
tag.put(entry.getKey(), fromNative(entry.getValue()));
}
Expand All @@ -901,10 +900,9 @@ net.minecraft.nbt.Tag fromNative(Tag foreign) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayTag) foreign).getValue());
} else if (foreign instanceof LongArrayTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayTag) foreign).getValue());
} else if (foreign instanceof ListTag) {
} else if (foreign instanceof ListTag<?, ?> foreignList) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListTag foreignList = (ListTag) foreign;
for (Tag t : foreignList.getValue()) {
for (Tag<?, ?> t : foreignList.getValue()) {
tag.add(fromNative(t));
}
return tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

package com.sk89q.worldedit.bukkit.adapter.impl.v1_19_R1;

import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
Expand All @@ -37,6 +36,7 @@
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;

import java.lang.ref.WeakReference;
import java.util.Objects;
Expand Down Expand Up @@ -104,13 +104,13 @@ public void updateLightingForBlock(BlockPos position) {
}

@Override
public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
// We will assume that the tile entity was created for us
BlockEntity tileEntity = getWorld().getBlockEntity(position);
if (tileEntity == null) {
return false;
}
Tag nativeTag = adapter.fromNative(AdventureNBTConverter.fromAdventure(tag));
Tag nativeTag = adapter.fromNative(new CompoundTag(tag));
PaperweightAdapter.readTagIntoTileEntity((net.minecraft.nbt.CompoundTag) nativeTag, tileEntity);
return true;
}
Expand Down
Loading

0 comments on commit d1ebde0

Please sign in to comment.