fabric-1.20: update code to 1.20

This commit is contained in:
Kosma Moczek 2023-05-23 01:11:00 +02:00
parent 1450a57aba
commit 05b751a60e
7 changed files with 35 additions and 27 deletions

View File

@ -10,9 +10,9 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.FluidBlock;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.server.MinecraftServer;
@ -53,6 +53,7 @@ import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.regex.Pattern;
public class DynmapPlugin {
// FIXME: Fix package-private fields after splitting is done
DynmapCore core;
@ -155,7 +156,6 @@ public class DynmapPlugin {
String bn = ui.getNamespace() + ":" + ui.getPath();
// Only do defined names, and not "air"
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
Material mat = bs.getMaterial();
String statename = "";
for (net.minecraft.state.property.Property<?> p : bs.getProperties()) {
if (statename.length() > 0) {
@ -166,11 +166,11 @@ public class DynmapPlugin {
int lightAtten = bs.isOpaqueFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 15 : (bs.isTransparent(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 0 : 1);
//Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
// Fill in base attributes
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
if (mat.isSolid()) { bld.setSolid(); }
if (mat == Material.AIR) { bld.setAir(); }
if (mat == Material.WOOD) { bld.setLog(); }
if (mat == Material.LEAVES) { bld.setLeaves(); }
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
if (bs.isSolid()) { bld.setSolid(); }
if (bs.isAir()) { bld.setAir(); }
if (bs.isIn(BlockTags.LOGS)) { bld.setLog(); }
if (bs.isIn(BlockTags.LEAVES)) { bld.setLeaves(); }
if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FluidBlock)) {
bld.setWaterlogged();
}
@ -634,7 +634,7 @@ public class DynmapPlugin {
ChunkSection[] sections = chunk.getSectionArray();
for (int i = 0; i < sections.length; i++) {
if ((sections[i] != null) && (!sections[i].isEmpty())) {
int sy = sections[i].getYOffset();
int sy = chunk.getBottomY() + i * ChunkSection.field_31407 /* Mojmap: SECTION_HEIGHT */;
if (sy < ymin) ymin = sy;
if ((sy+16) > ymax) ymax = sy + 16;
}

View File

@ -25,8 +25,7 @@ public class FabricCommandSender implements DynmapCommandSender {
@Override
public void sendMessage(String msg) {
if (sender != null) {
Text ichatcomponent = Text.literal(msg);
sender.sendFeedback(ichatcomponent, false);
sender.sendFeedback(() -> Text.literal(msg), false);
}
}

View File

@ -16,6 +16,7 @@ import net.minecraft.text.LiteralTextContent;
import net.minecraft.text.Text;
import net.minecraft.util.Util;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.dynmap.DynmapLocation;
import org.dynmap.common.DynmapPlayer;
@ -100,7 +101,7 @@ public class FabricPlayer extends FabricCommandSender implements DynmapPlayer {
}
Vec3d pos = player.getPos();
return FabricAdapter.toDynmapLocation(plugin, player.getWorld(), pos.getX(), pos.getY(), pos.getZ());
return FabricAdapter.toDynmapLocation(plugin, player.getServerWorld(), pos.getX(), pos.getY(), pos.getZ());
}
@Override
@ -109,8 +110,9 @@ public class FabricPlayer extends FabricCommandSender implements DynmapPlayer {
return null;
}
if (player.world != null) {
return plugin.getWorld(player.world).getName();
World world = player.getWorld();
if (world != null) {
return plugin.getWorld(world).getName();
}
return null;

View File

@ -271,7 +271,7 @@ public class FabricServer extends DynmapServerInterface {
break;
case SIGN_CHANGE:
BlockEvents.SIGN_CHANGE_EVENT.register((world, pos, lines, material, player) -> {
BlockEvents.SIGN_CHANGE_EVENT.register((world, pos, lines, player, front) -> {
plugin.core.processSignChange("fabric", FabricWorld.getWorldName(plugin, world),
pos.getX(), pos.getY(), pos.getZ(), lines, player.getName().getString());
});

View File

@ -2,7 +2,6 @@ package org.dynmap.fabric_1_20.event;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.block.Material;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
@ -21,9 +20,9 @@ public class BlockEvents {
);
public static Event<SignChangeCallback> SIGN_CHANGE_EVENT = EventFactory.createArrayBacked(SignChangeCallback.class,
(listeners) -> (world, pos, lines, material, player) -> {
(listeners) -> (world, pos, lines, player, front) -> {
for (SignChangeCallback callback : listeners) {
callback.onSignChange(world, pos, lines, material, player);
callback.onSignChange(world, pos, lines, player, front);
}
}
);
@ -35,6 +34,6 @@ public class BlockEvents {
@FunctionalInterface
public interface SignChangeCallback {
void onSignChange(ServerWorld world, BlockPos pos, String[] lines, Material material, ServerPlayerEntity player);
void onSignChange(ServerWorld world, BlockPos pos, String[] lines, ServerPlayerEntity player, boolean front);
}
}

View File

@ -3,6 +3,7 @@ package org.dynmap.fabric_1_20.mixin;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.network.message.FilterMask;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket;
import net.minecraft.server.filter.FilteredMessage;
@ -14,6 +15,7 @@ import net.minecraft.text.LiteralTextContent;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import java.util.Arrays;
import java.util.List;
import org.dynmap.fabric_1_20.event.BlockEvents;
import org.dynmap.fabric_1_20.event.ServerChatEvents;
@ -43,13 +45,14 @@ public abstract class ServerPlayNetworkHandlerMixin {
method = "onSignUpdate",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/entity/SignBlockEntity;markDirty()V",
target = "Lnet/minecraft/block/entity/SignBlockEntity;tryChangeText(Lnet/minecraft/entity/player/PlayerEntity;ZLjava/util/List;)V",
shift = At.Shift.BEFORE
),
locals = LocalCapture.CAPTURE_FAILHARD
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true
)
public void onSignUpdate(UpdateSignC2SPacket packet, List<FilteredMessage> signText, CallbackInfo info,
ServerWorld serverWorld, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity, SignBlockEntity signBlockEntity)
public void onSignUpdate(UpdateSignC2SPacket packet, List<FilteredMessage> signText, CallbackInfo ci,
ServerWorld serverWorld, BlockPos blockPos, BlockEntity blockEntity, SignBlockEntity signBlockEntity)
{
// Pull the raw text from the input.
String[] rawTexts = new String[4];
@ -57,10 +60,15 @@ public abstract class ServerPlayNetworkHandlerMixin {
rawTexts[i] = signText.get(i).raw();
// Fire the event.
BlockEvents.SIGN_CHANGE_EVENT.invoker().onSignChange(serverWorld, blockPos, rawTexts, blockState.getMaterial(), player);
BlockEvents.SIGN_CHANGE_EVENT.invoker().onSignChange(serverWorld, blockPos, rawTexts, player, packet.isFront());
// Put the (possibly updated) texts in the sign. Ignore filtering (is this OK?).
for (int i=0; i<signText.size(); i++)
signBlockEntity.setTextOnRow(i, Text.literal(rawTexts[i]));
// Rebuild the signText list with the new values.
List<FilteredMessage> newSignText = Arrays.stream(rawTexts).map((raw) -> new FilteredMessage(raw, FilterMask.PASS_THROUGH)).toList();
// Execute the setting of the texts with the edited values.
signBlockEntity.tryChangeText(this.player, packet.isFront(), newSignText);
// Cancel the original tryChangeText() since we're calling it ourselves above.
ci.cancel();
}
}

View File

@ -15,7 +15,7 @@ public class ServerPlayerEntityMixin {
@Inject(method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDFF)V", at = @At("RETURN"))
public void teleport(ServerWorld targetWorld, double x, double y, double z, float yaw, float pitch, CallbackInfo info) {
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
if (targetWorld != player.world) {
if (targetWorld != player.getServerWorld()) {
PlayerEvents.PLAYER_CHANGED_DIMENSION.invoker().onPlayerChangedDimension(player);
}
}