Play around with SpongeForge (#2107)

This commit is contained in:
Maddy Miller 2022-06-04 16:10:50 +10:00 committed by GitHub
parent 92dfdcb88b
commit c83f6ecd88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 52 deletions

View File

@ -18,7 +18,7 @@
version("1.16.5")
}
val spongeApiVersion = "8.0.0";
val spongeApiVersion = "8.1.0";
sponge {
apiVersion(spongeApiVersion)

View File

@ -21,24 +21,23 @@
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockCategoryRegistry;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.Tag;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.registry.RegistryTypes;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class SpongeBlockCategoryRegistry implements BlockCategoryRegistry {
@Override
public Set<BlockType> getCategorisedByName(String category) {
return Optional.ofNullable(BlockTags.getAllTags().getTag(new ResourceLocation(category)))
.map(Tag::getValues)
return Sponge.game().registry(RegistryTypes.BLOCK_TYPE_TAGS)
.findValue(ResourceKey.resolve(category))
.map(org.spongepowered.api.tag.Tag::values)
.orElse(Collections.emptyList())
.stream()
.map(b -> BlockType.REGISTRY.get(Registry.BLOCK.getKey(b).toString()))
.map(b -> BlockType.REGISTRY.get(Sponge.game().registry(RegistryTypes.BLOCK_TYPE).valueKey(b).formatted()))
.collect(Collectors.toSet());
}
}

View File

@ -21,24 +21,23 @@
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.ItemCategoryRegistry;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.registry.RegistryTypes;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class SpongeItemCategoryRegistry implements ItemCategoryRegistry {
@Override
public Set<ItemType> getCategorisedByName(String category) {
return Optional.ofNullable(ItemTags.getAllTags().getTag(new ResourceLocation(category)))
.map(Tag::getValues)
return Sponge.game().registry(RegistryTypes.ITEM_TYPE_TAGS)
.findValue(ResourceKey.resolve(category))
.map(org.spongepowered.api.tag.Tag::values)
.orElse(Collections.emptyList())
.stream()
.map(b -> ItemType.REGISTRY.get(Registry.ITEM.getKey(b).toString()))
.map(b -> ItemType.REGISTRY.get(Sponge.game().registry(RegistryTypes.ITEM_TYPE).valueKey(b).formatted()))
.collect(Collectors.toSet());
}
}

View File

@ -40,9 +40,6 @@
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.Keys;
@ -87,7 +84,6 @@ public String getName() {
return this.player.name();
}
@SuppressWarnings("deprecation")
@Override
public String getDisplayName() {
return LegacyComponentSerializer.legacySection().serialize(player.displayName().get());
@ -234,20 +230,15 @@ public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B bl
if (block == null) {
player.resetBlockChange(pos.getX(), pos.getY(), pos.getZ());
} else {
net.minecraft.server.level.ServerPlayer mcPlayer =
((net.minecraft.server.level.ServerPlayer) player);
final ClientboundBlockUpdatePacket packetOut = new ClientboundBlockUpdatePacket(
new BlockPos(pos.getX(), pos.getY(), pos.getZ()),
(net.minecraft.world.level.block.state.BlockState)
SpongeAdapter.adapt(block.toImmutableState())
);
mcPlayer.connection.send(packetOut);
player.sendBlockChange(pos.getX(), pos.getY(), pos.getZ(), SpongeAdapter.adapt(block.toImmutableState()));
if (block instanceof BaseBlock && block.getBlockType().equals(com.sk89q.worldedit.world.block.BlockTypes.STRUCTURE_BLOCK)) {
final BaseBlock baseBlock = (BaseBlock) block;
final CompoundTag nbtData = baseBlock.getNbtData();
if (nbtData != null) {
mcPlayer.connection.send(new ClientboundBlockEntityDataPacket(
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
net.minecraft.server.level.ServerPlayer mcPlayer =
((net.minecraft.server.level.ServerPlayer) player);
mcPlayer.connection.send(new net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket(
new net.minecraft.core.BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
STRUCTURE_BLOCK_PACKET_ID,
NbtAdapter.adaptNMSToWorldEdit(nbtData))
);

View File

@ -19,19 +19,14 @@
package com.sk89q.worldedit.sponge;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -64,8 +59,6 @@
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.entity.BlockEntityArchetype;
import org.spongepowered.api.block.entity.BlockEntityType;
import org.spongepowered.api.data.persistence.DataContainer;
import org.spongepowered.api.data.persistence.DataView;
import org.spongepowered.api.entity.EntityArchetype;
import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.EntityTypes;
@ -85,10 +78,7 @@
import java.lang.ref.WeakReference;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;

View File

@ -40,9 +40,6 @@
import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.item.ItemCategory;
import net.kyori.adventure.audience.Audience;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import org.apache.logging.log4j.Logger;
import org.bstats.sponge.Metrics;
import org.spongepowered.api.ResourceKey;
@ -193,16 +190,18 @@ public void serverStarted(StartedEngineEvent<Server> event) {
});
}
for (ResourceLocation name : BlockTags.getAllTags().getAvailableTags()) {
if (BlockCategory.REGISTRY.get(name.toString()) == null) {
BlockCategory.REGISTRY.register(name.toString(), new BlockCategory(name.toString()));
event.game().registry(RegistryTypes.BLOCK_TYPE_TAGS).streamEntries().forEach(blockTypeTag -> {
String id = blockTypeTag.key().asString();
if (!BlockCategory.REGISTRY.keySet().contains(id)) {
BlockCategory.REGISTRY.register(id, new BlockCategory(id));
}
}
for (ResourceLocation name : ItemTags.getAllTags().getAvailableTags()) {
if (ItemCategory.REGISTRY.get(name.toString()) == null) {
ItemCategory.REGISTRY.register(name.toString(), new ItemCategory(name.toString()));
});
event.game().registry(RegistryTypes.ITEM_TYPE_TAGS).streamEntries().forEach(itemTypeTag -> {
String id = itemTypeTag.key().asString();
if (!ItemCategory.REGISTRY.keySet().contains(id)) {
ItemCategory.REGISTRY.register(id, new ItemCategory(id));
}
}
});
config.load();
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));