Skip to content

Commit

Permalink
Update to 24w44a
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Oct 30, 2024
1 parent 08ec14b commit e9ab976
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 263 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ org.gradle.jvmargs=-Xmx4G
# Fabric Properties
# check these on https://fabricmc.net/use

minecraft_version=1.21.3
yarn_mappings=1.21.3+build.1
loader_version=0.16.7
minecraft_version=24w44a
yarn_mappings=24w44a+build.1
loader_version=0.16.9

# Fabric API
fabric_version=0.106.1+1.21.3
fabric_version=0.107.0+1.21.4

maven_group = eu.pb4

mod_version = 0.10.1
mod_version = 0.11.0-alpha.1

minecraft_version_supported = ">=1.21.2-"
minecraft_version_supported = ">=1.21.4-"

packet_tweaker_version = 0.6.0-pre.1+1.21.2-pre3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.block.entity.BannerPattern;
import net.minecraft.component.type.MapIdComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.boss.dragon.EnderDragonPart;
import net.minecraft.entity.damage.DamageScaling;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageSources;
Expand Down Expand Up @@ -332,6 +333,11 @@ public Entity getEntityById(int id) {
return null;
}

@Override
public Collection<EnderDragonPart> method_65097() {
return List.of();
}

@Override
public TickManager getTickManager() {
return this.tickManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public static ItemStack createItemStack(ItemStack itemStack, TooltipType tooltip
}

try {
var tooltip = itemStack.getTooltip(context.getPlayer() != null ? Item.TooltipContext.create(context.getPlayer().getWorld()) : Item.TooltipContext.DEFAULT, context.getPlayer(), tooltipContext);
var tooltip = itemStack.getTooltip(context.getPlayer() != null ? Item.TooltipContext.create(context.getPlayer().getRegistryManager()) : Item.TooltipContext.DEFAULT, context.getPlayer(), tooltipContext);
if (!tooltip.isEmpty()) {
tooltip.removeFirst();

Expand Down
33 changes: 0 additions & 33 deletions polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ public static void register(LiteralArgumentBuilder<ServerCommandSource> command,
.requires(CommonImplUtils.permission("command.target-item", 3))
.executes(Commands::targetItem)
)
.then(literal("pick")
.requires(CommonImplUtils.permission("command.pick", 0))
.executes((ctx) -> Commands.pickTarget(ctx, false))
.then(
literal("withnbt").executes((ctx) -> Commands.pickTarget(ctx, true))
)

)
.then(literal("creative")
.requires(CommonImplUtils.permission("command.creative", 0))
.then(argument("itemGroup", IdentifierArgumentType.identifier())
Expand All @@ -127,31 +119,6 @@ public static void register(LiteralArgumentBuilder<ServerCommandSource> command,
.executes(Commands::creativeTab));
}

private static int pickTarget(CommandContext<ServerCommandSource> serverCommandSourceCommandContext, boolean withNbt) throws CommandSyntaxException {
var player = serverCommandSourceCommandContext.getSource().getPlayerOrThrow();
var range = player.getEntityInteractionRange();

var min = player.getCameraPosVec(0);
var rot = player.getRotationVec(0);
var max = min.add(rot.x * range, rot.y * range, rot.z * range);

var box = player.getBoundingBox().stretch(rot.multiply(range)).expand(1.0, 1.0, 1.0);
var entityHit = ProjectileUtil.raycast(player, min, max, box, entity -> !player.isSpectator() && entity.canHit(), range);

if (entityHit != null) {
PolymerImplUtils.pickEntity(player, entityHit.getEntity());
return 1;
}

var hit = player.raycast(player.getBlockInteractionRange(), 0, false);
if (hit instanceof BlockHitResult result && hit.getType() != HitResult.Type.MISS) {
PolymerImplUtils.pickBlock(player, result.getBlockPos(), withNbt);
return 2;
}

return 0;
}

public static void registerDev(LiteralArgumentBuilder<ServerCommandSource> dev) {
dev
.then(literal("reload-world")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,75 +247,6 @@ public static ItemStack convertStack(ItemStack representation, ServerPlayerEntit
return ServerTranslationUtils.parseFor(player.networkHandler, PolyMcUtils.toVanilla(PolymerItemUtils.getPolymerItemStack(representation, context, PacketContext.create(player)), player));
}

public static void pickBlock(ServerPlayerEntity player, BlockPos pos, boolean withNbt) {
var isCreative = player.isCreative();

BlockState blockState = player.getWorld().getBlockState(pos);
if (blockState.isAir()) {
return;
}

Block block = blockState.getBlock();
var itemStack = block.getPickStack(player.getWorld(), pos, blockState);
if (itemStack.isEmpty()) {
return;
}

if (isCreative && withNbt && blockState.hasBlockEntity()) {
var blockEntity = player.getWorld().getBlockEntity(pos);
if (blockEntity != null && (!blockEntity.copyItemDataRequiresOperator() || player.isCreativeLevelTwoOp())) {
NbtCompound nbtCompound = blockEntity.createComponentlessNbtWithIdentifyingData(player.getRegistryManager());
//noinspection deprecation
blockEntity.removeFromCopiedStackNbt(nbtCompound);
BlockItem.setBlockEntityData(itemStack, blockEntity.getType(), nbtCompound);
itemStack.applyComponentsFrom(blockEntity.createComponentMap());
}
}


PlayerInventory playerInventory = player.getInventory();


int i = playerInventory.getSlotWithStack(itemStack);
if (isCreative) {
playerInventory.addPickBlock(itemStack);
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(playerInventory.selectedSlot));
} else if (i != -1) {
if (PlayerInventory.isValidHotbarIndex(i)) {
playerInventory.selectedSlot = i;
} else {
player.getInventory().swapSlotWithHotbar(i);
player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(-2, 0, playerInventory.selectedSlot, playerInventory.getStack(playerInventory.selectedSlot)));
player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(-2, 0, i, playerInventory.getStack(i)));
}
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(playerInventory.selectedSlot));
}
}

public static void pickEntity(ServerPlayerEntity player, Entity entity) {
var isCreative = player.isCreative();

var itemStack = entity.getPickBlockStack();

if (itemStack != null && !itemStack.isEmpty()) {
PlayerInventory playerInventory = player.getInventory();
int i = playerInventory.getSlotWithStack(itemStack);
if (isCreative) {
playerInventory.addPickBlock(itemStack);
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(playerInventory.selectedSlot));
} else if (i != -1) {
if (PlayerInventory.isValidHotbarIndex(i)) {
playerInventory.selectedSlot = i;
} else {
player.getInventory().swapSlotWithHotbar(i);
player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(-2, 0, playerInventory.selectedSlot, playerInventory.getStack(playerInventory.selectedSlot)));
player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(-2, 0, i, playerInventory.getStack(i)));
}
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(playerInventory.selectedSlot));
}
}
}

public static void callItemGroupEvents(Identifier id, ItemGroup itemGroup, List<ItemStack> parentTabStacks, List<ItemStack> searchTabStacks, ItemGroup.DisplayContext context) {
if (CompatStatus.FABRIC_ITEM_GROUP) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public IElement getIcon(BlockAccessor accessor, snownee.jade.api.config.IPluginC

var itemStack = block.block().displayStack();
if (itemStack.isEmpty()) {
itemStack = state.getBlock().getPickStack(accessor.getLevel(), accessor.getPosition(), state);
itemStack = state.method_65171(accessor.getLevel(), accessor.getPosition());
if (!itemStack.isEmpty() && state.hasBlockEntity()) {
var blockEntity = accessor.getLevel().getBlockEntity(accessor.getPosition());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static class BlockOverride implements IBlockComponentProvider {

var itemStack = block.block().displayStack();
if (itemStack.isEmpty()) {
itemStack = state.getBlock().getPickStack(accessor.getWorld(), accessor.getPosition(), state);
itemStack = state.method_65171(accessor.getWorld(), accessor.getPosition());
if (!itemStack.isEmpty() && state.hasBlockEntity()) {
var blockEntity = accessor.getWorld().getBlockEntity(accessor.getPosition());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import eu.pb4.polymer.core.impl.client.InternalClientRegistry;
import eu.pb4.polymer.core.impl.networking.C2SPackets;
import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerChangeTooltipC2SPayload;
import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerPickBlockC2SPayload;
import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerPickEntityC2SPayload;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
Expand All @@ -18,23 +16,11 @@
@ApiStatus.Internal
@Environment(EnvType.CLIENT)
public class PolymerClientProtocol {
public static void sendPickBlock(ClientPlayNetworkHandler handler, BlockPos pos) {
if (InternalClientRegistry.getClientProtocolVer(C2SPackets.WORLD_PICK_BLOCK) != -1) {
handler.sendPacket(new CustomPayloadC2SPacket(new PolymerPickBlockC2SPayload(pos, Screen.hasControlDown())));
}
}

public static void sendTooltipContext(ClientPlayNetworkHandler handler) {
if (InternalClientRegistry.getClientProtocolVer(C2SPackets.CHANGE_TOOLTIP) != -1) {
InternalClientRegistry.delayAction(C2SPackets.CHANGE_TOOLTIP.toString(), 200, () -> {
handler.sendPacket(new CustomPayloadC2SPacket(new PolymerChangeTooltipC2SPayload(MinecraftClient.getInstance().options.advancedItemTooltips)));
});
}
}

public static void sendPickEntity(ClientPlayNetworkHandler handler, int id) {
if (InternalClientRegistry.getClientProtocolVer(C2SPackets.WORLD_PICK_ENTITY) != -1) {
handler.sendPacket(new CustomPayloadC2SPacket(new PolymerPickEntityC2SPayload(id, Screen.hasControlDown())));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package eu.pb4.polymer.core.impl.networking;

import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerPickBlockC2SPayload;
import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerPickEntityC2SPayload;
import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerChangeTooltipC2SPayload;
import eu.pb4.polymer.networking.api.ContextByteBuf;
import eu.pb4.polymer.networking.api.PolymerNetworking;
Expand All @@ -22,8 +20,6 @@ public static <T extends CustomPayload> void register(Identifier id, PacketCodec
}

static {
register(WORLD_PICK_BLOCK, PolymerPickBlockC2SPayload.CODEC, 6);
register(WORLD_PICK_ENTITY, PolymerPickEntityC2SPayload.CODEC, 6);
register(CHANGE_TOOLTIP, PolymerChangeTooltipC2SPayload.CODEC, 6);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,10 @@

import eu.pb4.polymer.core.api.utils.PolymerSyncUtils;
import eu.pb4.polymer.core.api.utils.PolymerUtils;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import eu.pb4.polymer.core.impl.ServerMetadataKeys;
import eu.pb4.polymer.core.impl.interfaces.PolymerPlayNetworkHandlerExtension;
import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerChangeTooltipC2SPayload;
import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerPickBlockC2SPayload;
import eu.pb4.polymer.core.impl.networking.payloads.c2s.PolymerPickEntityC2SPayload;
import eu.pb4.polymer.networking.api.server.PolymerServerNetworking;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.PlayerHeadItem;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -28,8 +14,6 @@
public class PolymerServerProtocolHandler {
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void register() {
PolymerServerNetworking.registerPlayHandler(PolymerPickBlockC2SPayload.class, PolymerServerProtocolHandler::handlePickBlock);
PolymerServerNetworking.registerPlayHandler(PolymerPickEntityC2SPayload.class, PolymerServerProtocolHandler::handlePickEntity);
PolymerServerNetworking.registerPlayHandler(PolymerChangeTooltipC2SPayload.class, PolymerServerProtocolHandler::handleTooltipChange);

PolymerServerNetworking.ON_PLAY_SYNC.register((handler, x) -> {
Expand All @@ -51,26 +35,4 @@ private static void handleTooltipChange(MinecraftServer server, ServerPlayNetwor
}
});
}

private static void handlePickBlock(MinecraftServer server, ServerPlayNetworkHandler handler, PolymerPickBlockC2SPayload payload) {
var pos = payload.pos();
var ctr = payload.control();


server.execute(() -> {
if (pos.getManhattanDistance(handler.player.getBlockPos()) <= 32) {
PolymerImplUtils.pickBlock(handler.player, pos, ctr);
}
});
}

private static void handlePickEntity(MinecraftServer server, ServerPlayNetworkHandler handler, PolymerPickEntityC2SPayload payload) {
server.execute(() -> {
var entity = handler.player.getServerWorld().getEntityById(payload.entityId());

if (entity != null && entity.getPos().relativize(handler.player.getPos()).lengthSquared() < 1024) {
PolymerImplUtils.pickEntity(handler.player, entity);
}
});
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit e9ab976

Please sign in to comment.