Skip to content

Commit

Permalink
Remove useless anvil renaming mixin for polymer items, fix recipes no…
Browse files Browse the repository at this point in the history
…t using correct player language
  • Loading branch information
Patbox committed Jun 24, 2023
1 parent 329713d commit ea23baa
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 62 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.83.0+1.20.1

maven_group = eu.pb4

mod_version = 0.5.2
mod_version = 0.5.3

minecraft_version_supported = ">=1.20-"

Expand Down
1 change: 1 addition & 0 deletions polymer-autohost/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {

compileOnly (project(path: ':polymer-virtual-entity', configuration: 'namedElements'))
localRuntime (project(path: ':polymer-virtual-entity', configuration: 'namedElements'))
modLocalRuntime("xyz.nucleoid:server-translations-api:2.0.0-beta.2+1.19.4-pre2")


project(":polymer-core").afterEvaluate {
Expand Down
3 changes: 3 additions & 0 deletions polymer-common/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"minecraft": ">=1.20",
"fabricloader": ">=0.14.4"
},
"conflicts": {
"banner": "*"
},
"custom": {
"modmenu": {
"badges": [ "library" ],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.pb4.polymer.core.api.utils;

/**
* This interface marks blocks and items to be decoded on client.
* This interface marks blocks and entities to be decoded on client.
* Can be useful if you want to use companion client side mod
*/
public interface PolymerClientDecoded {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ServerPackets {
public static final Identifier SYNC_ITEM_GROUP_CONTENTS_CLEAR= id("sync/item_group/contents/clear");
public static final Identifier SYNC_BLOCKSTATE= id("sync/blockstate");
public static final Identifier SYNC_TAGS= id("sync/tags");
public static final Identifier SYNC_ITEM_GROUP_APPLY_UPDATE= id("sync/item_group/apply_update");
public static final Identifier SYNC_ITEM_GROUP_APPLY_UPDATE = id("sync/item_group/apply_update");
public static final Identifier SYNC_CLEAR= id("sync/clear_all");
public static final Identifier WORLD_SET_BLOCK_UPDATE= id("world/set_block");
public static final Identifier WORLD_CHUNK_SECTION_UPDATE= id("world/section");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
import net.fabricmc.api.Environment;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Set;
import java.util.stream.Stream;

@Mixin(ItemGroups.class)
Expand All @@ -22,4 +27,12 @@ public class ItemGroupsMixin {
cir.setReturnValue(Stream.concat(cir.getReturnValue(), InternalClientRegistry.ITEM_GROUPS.stream()));
}
}

@Environment(EnvType.CLIENT)
@Inject(method = "method_51316", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemGroup$Entries;addAll(Ljava/util/Collection;)V", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILSOFT)
private static void polymerCore$injectClientSearch(Registry<ItemGroup> registry, ItemGroup.DisplayContext displayContext, ItemGroup.Entries entries, CallbackInfo ci, Set<ItemStack> set) {
for (var group : InternalClientRegistry.ITEM_GROUPS) {
set.addAll(group.getSearchTabStacks());
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@
@Mixin(value = ItemGroup.class, priority = 3000)
public abstract class ItemGroupMixin implements ItemGroupExtra {
@Shadow private Collection<ItemStack> displayStacks;


@Shadow private Set<ItemStack> searchTabStacks;

@Shadow @Nullable private Consumer<List<ItemStack>> searchProviderReloader;


@Shadow public abstract void updateEntries(ItemGroup.DisplayContext arg);

@Shadow public abstract void reloadSearchProvider();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
import net.fabricmc.api.Environment;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Set;
import java.util.stream.Stream;

@Mixin(ItemGroups.class)
Expand All @@ -21,4 +26,12 @@ public class ItemGroupsMixin {
cir.setReturnValue(Stream.concat(cir.getReturnValue(), PolymerItemGroupUtils.REGISTRY.stream()));
}
}

@Environment(EnvType.SERVER)
@Inject(method = "method_51316", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemGroup$Entries;addAll(Ljava/util/Collection;)V", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILSOFT)
private static void polymerCore$injectServerSearch(Registry<ItemGroup> registry, ItemGroup.DisplayContext displayContext, ItemGroup.Entries entries, CallbackInfo ci, Set<ItemStack> set) {
for (var group : PolymerItemGroupUtils.REGISTRY) {
set.addAll(group.getSearchTabStacks());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import eu.pb4.polymer.core.api.item.PolymerItem;
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
import eu.pb4.polymer.core.impl.PolymerImpl;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Equipment;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket;
import net.minecraft.network.packet.c2s.play.ClientSettingsC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Hand;
Expand All @@ -31,17 +32,24 @@

@Mixin(ServerPlayNetworkHandler.class)
public abstract class ServerPlayNetworkHandlerMixin {

@Unique
private final List<ItemStack> armorItems = new ArrayList<>();
@Shadow
public ServerPlayerEntity player;

@Shadow
public abstract void sendPacket(Packet<?> packet);

@Shadow
public abstract void onPlayerInteractItem(PlayerInteractItemC2SPacket packet);
@Unique
private final List<ItemStack> polymerCore$armorItems = new ArrayList<>();
@Unique
private String polymerCore$language = "en_us";

@Inject(method = "onClientSettings", at = @At("TAIL"))
private void polymerCore$resendLanguage(ClientSettingsC2SPacket packet, CallbackInfo ci) {
if (!this.polymerCore$language.equals(packet.language())) {
this.polymerCore$language = packet.language();
this.sendPacket(new SynchronizeRecipesS2CPacket(this.player.getServerWorld().getRecipeManager().values()));
this.player.getRecipeBook().sendInitRecipesPacket(this.player);
}
}

@Inject(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V", shift = At.Shift.AFTER))
private void polymer$resendHandOnPlace(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) {
Expand Down Expand Up @@ -102,7 +110,7 @@ public abstract class ServerPlayNetworkHandlerMixin {
private void polymer$storeArmor(ClickSlotC2SPacket packet, CallbackInfo ci) {
if (this.player.currentScreenHandler == this.player.playerScreenHandler) {
for (ItemStack stack : this.player.getInventory().armor) {
armorItems.add(stack.copy());
polymerCore$armorItems.add(stack.copy());
}
}
}
Expand All @@ -112,7 +120,7 @@ public abstract class ServerPlayNetworkHandlerMixin {
if (this.player.currentScreenHandler == this.player.playerScreenHandler && packet.getSlot() != -999) {
int x = 0;
for (ItemStack stack : this.player.getInventory().armor) {
if (stack.getItem() instanceof PolymerItem && !ItemStack.areEqual(this.armorItems.get(x), stack)) {
if (stack.getItem() instanceof PolymerItem && !ItemStack.areEqual(this.polymerCore$armorItems.get(x), stack)) {
this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId,
this.player.playerScreenHandler.nextRevision(),
8 - x,
Expand All @@ -135,6 +143,6 @@ public abstract class ServerPlayNetworkHandlerMixin {
}
}

this.armorItems.clear();
this.polymerCore$armorItems.clear();
}
}
1 change: 0 additions & 1 deletion polymer-core/src/main/resources/polymer-core.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"entity.PlayerSpawnS2CPacketAccessor",
"entity.ServerWorldAccessor",
"entity.TrackedDataHandlerRegistryBlockStateMixin",
"item.AnvilScreenHandlerMixin",
"item.ItemGroupMixin",
"item.ItemGroupsMixin",
"item.ItemStackContentMixin",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"key": {
"#": {
"item": "minecraft:stick"
},
"X": {
"item": "test:block"
}
},
"pattern": [
"XXX",
" # ",
" # "
],
"result": {
"item": "test:potato_block"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package eu.pb4.polymer.virtualentity.api.tracker;

import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class WrappingDataTracker implements DataTrackerLike {
private final DataTrackerLike dataTracker;

public WrappingDataTracker(DataTrackerLike tracker) {
this.dataTracker = tracker;
}

@Override
public <T> @Nullable T get(TrackedData<T> data) {
return dataTracker.get(data);
}

@Override
public <T> void set(TrackedData<T> key, T value, boolean forceDirty) {
dataTracker.set(key, value, forceDirty);
}

@Override
public <T> void setDirty(TrackedData<T> key, boolean isDirty) {
dataTracker.set(key, dataTracker.get(key), isDirty);
}

@Override
public boolean isDirty() {
return dataTracker.isDirty();
}

@Override
public @Nullable List<DataTracker.SerializedEntry<?>> getDirtyEntries() {
return dataTracker.getDirtyEntries();
}

@Override
public @Nullable List<DataTracker.SerializedEntry<?>> getChangedEntries() {
return dataTracker.getChangedEntries();
}

@Override
public boolean isEmpty() {
return dataTracker.isEmpty();
}
}

0 comments on commit ea23baa

Please sign in to comment.