mirror of https://github.com/webbukkit/dynmap.git
fabric-1.20: update code to 1.20
This commit is contained in:
parent
1450a57aba
commit
05b751a60e
|
@ -10,9 +10,9 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.FluidBlock;
|
import net.minecraft.block.FluidBlock;
|
||||||
import net.minecraft.block.Material;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.registry.tag.BlockTags;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.registry.Registry;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
@ -53,6 +53,7 @@ import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
public class DynmapPlugin {
|
public class DynmapPlugin {
|
||||||
// FIXME: Fix package-private fields after splitting is done
|
// FIXME: Fix package-private fields after splitting is done
|
||||||
DynmapCore core;
|
DynmapCore core;
|
||||||
|
@ -155,7 +156,6 @@ public class DynmapPlugin {
|
||||||
String bn = ui.getNamespace() + ":" + ui.getPath();
|
String bn = ui.getNamespace() + ":" + ui.getPath();
|
||||||
// Only do defined names, and not "air"
|
// Only do defined names, and not "air"
|
||||||
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
|
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
|
||||||
Material mat = bs.getMaterial();
|
|
||||||
String statename = "";
|
String statename = "";
|
||||||
for (net.minecraft.state.property.Property<?> p : bs.getProperties()) {
|
for (net.minecraft.state.property.Property<?> p : bs.getProperties()) {
|
||||||
if (statename.length() > 0) {
|
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);
|
int lightAtten = bs.isOpaqueFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 15 : (bs.isTransparent(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 0 : 1);
|
||||||
//Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
|
//Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
|
||||||
// Fill in base attributes
|
// Fill in base attributes
|
||||||
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
|
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
|
||||||
if (mat.isSolid()) { bld.setSolid(); }
|
if (bs.isSolid()) { bld.setSolid(); }
|
||||||
if (mat == Material.AIR) { bld.setAir(); }
|
if (bs.isAir()) { bld.setAir(); }
|
||||||
if (mat == Material.WOOD) { bld.setLog(); }
|
if (bs.isIn(BlockTags.LOGS)) { bld.setLog(); }
|
||||||
if (mat == Material.LEAVES) { bld.setLeaves(); }
|
if (bs.isIn(BlockTags.LEAVES)) { bld.setLeaves(); }
|
||||||
if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FluidBlock)) {
|
if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FluidBlock)) {
|
||||||
bld.setWaterlogged();
|
bld.setWaterlogged();
|
||||||
}
|
}
|
||||||
|
@ -634,7 +634,7 @@ public class DynmapPlugin {
|
||||||
ChunkSection[] sections = chunk.getSectionArray();
|
ChunkSection[] sections = chunk.getSectionArray();
|
||||||
for (int i = 0; i < sections.length; i++) {
|
for (int i = 0; i < sections.length; i++) {
|
||||||
if ((sections[i] != null) && (!sections[i].isEmpty())) {
|
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 < ymin) ymin = sy;
|
||||||
if ((sy+16) > ymax) ymax = sy + 16;
|
if ((sy+16) > ymax) ymax = sy + 16;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,7 @@ public class FabricCommandSender implements DynmapCommandSender {
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String msg) {
|
public void sendMessage(String msg) {
|
||||||
if (sender != null) {
|
if (sender != null) {
|
||||||
Text ichatcomponent = Text.literal(msg);
|
sender.sendFeedback(() -> Text.literal(msg), false);
|
||||||
sender.sendFeedback(ichatcomponent, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import net.minecraft.text.LiteralTextContent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import org.dynmap.DynmapLocation;
|
import org.dynmap.DynmapLocation;
|
||||||
import org.dynmap.common.DynmapPlayer;
|
import org.dynmap.common.DynmapPlayer;
|
||||||
|
|
||||||
|
@ -100,7 +101,7 @@ public class FabricPlayer extends FabricCommandSender implements DynmapPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3d pos = player.getPos();
|
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
|
@Override
|
||||||
|
@ -109,8 +110,9 @@ public class FabricPlayer extends FabricCommandSender implements DynmapPlayer {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.world != null) {
|
World world = player.getWorld();
|
||||||
return plugin.getWorld(player.world).getName();
|
if (world != null) {
|
||||||
|
return plugin.getWorld(world).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -271,7 +271,7 @@ public class FabricServer extends DynmapServerInterface {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SIGN_CHANGE:
|
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),
|
plugin.core.processSignChange("fabric", FabricWorld.getWorldName(plugin, world),
|
||||||
pos.getX(), pos.getY(), pos.getZ(), lines, player.getName().getString());
|
pos.getX(), pos.getY(), pos.getZ(), lines, player.getName().getString());
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.dynmap.fabric_1_20.event;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.block.Material;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@ -21,9 +20,9 @@ public class BlockEvents {
|
||||||
);
|
);
|
||||||
|
|
||||||
public static Event<SignChangeCallback> SIGN_CHANGE_EVENT = EventFactory.createArrayBacked(SignChangeCallback.class,
|
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) {
|
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
|
@FunctionalInterface
|
||||||
public interface SignChangeCallback {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.dynmap.fabric_1_20.mixin;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.block.entity.SignBlockEntity;
|
import net.minecraft.block.entity.SignBlockEntity;
|
||||||
|
import net.minecraft.network.message.FilterMask;
|
||||||
import net.minecraft.network.message.SignedMessage;
|
import net.minecraft.network.message.SignedMessage;
|
||||||
import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket;
|
import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket;
|
||||||
import net.minecraft.server.filter.FilteredMessage;
|
import net.minecraft.server.filter.FilteredMessage;
|
||||||
|
@ -14,6 +15,7 @@ import net.minecraft.text.LiteralTextContent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.dynmap.fabric_1_20.event.BlockEvents;
|
import org.dynmap.fabric_1_20.event.BlockEvents;
|
||||||
import org.dynmap.fabric_1_20.event.ServerChatEvents;
|
import org.dynmap.fabric_1_20.event.ServerChatEvents;
|
||||||
|
@ -43,13 +45,14 @@ public abstract class ServerPlayNetworkHandlerMixin {
|
||||||
method = "onSignUpdate",
|
method = "onSignUpdate",
|
||||||
at = @At(
|
at = @At(
|
||||||
value = "INVOKE",
|
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
|
shift = At.Shift.BEFORE
|
||||||
),
|
),
|
||||||
locals = LocalCapture.CAPTURE_FAILHARD
|
locals = LocalCapture.CAPTURE_FAILHARD,
|
||||||
|
cancellable = true
|
||||||
)
|
)
|
||||||
public void onSignUpdate(UpdateSignC2SPacket packet, List<FilteredMessage> signText, CallbackInfo info,
|
public void onSignUpdate(UpdateSignC2SPacket packet, List<FilteredMessage> signText, CallbackInfo ci,
|
||||||
ServerWorld serverWorld, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity, SignBlockEntity signBlockEntity)
|
ServerWorld serverWorld, BlockPos blockPos, BlockEntity blockEntity, SignBlockEntity signBlockEntity)
|
||||||
{
|
{
|
||||||
// Pull the raw text from the input.
|
// Pull the raw text from the input.
|
||||||
String[] rawTexts = new String[4];
|
String[] rawTexts = new String[4];
|
||||||
|
@ -57,10 +60,15 @@ public abstract class ServerPlayNetworkHandlerMixin {
|
||||||
rawTexts[i] = signText.get(i).raw();
|
rawTexts[i] = signText.get(i).raw();
|
||||||
|
|
||||||
// Fire the event.
|
// 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?).
|
// Rebuild the signText list with the new values.
|
||||||
for (int i=0; i<signText.size(); i++)
|
List<FilteredMessage> newSignText = Arrays.stream(rawTexts).map((raw) -> new FilteredMessage(raw, FilterMask.PASS_THROUGH)).toList();
|
||||||
signBlockEntity.setTextOnRow(i, Text.literal(rawTexts[i]));
|
|
||||||
|
// 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@ public class ServerPlayerEntityMixin {
|
||||||
@Inject(method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDFF)V", at = @At("RETURN"))
|
@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) {
|
public void teleport(ServerWorld targetWorld, double x, double y, double z, float yaw, float pitch, CallbackInfo info) {
|
||||||
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
|
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
|
||||||
if (targetWorld != player.world) {
|
if (targetWorld != player.getServerWorld()) {
|
||||||
PlayerEvents.PLAYER_CHANGED_DIMENSION.invoker().onPlayerChangedDimension(player);
|
PlayerEvents.PLAYER_CHANGED_DIMENSION.invoker().onPlayerChangedDimension(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue