Skip to content

Commit

Permalink
Fix chunk attachment being removed from player when it shouldn't, fix…
Browse files Browse the repository at this point in the history
… usage of custom items in Trim Material/Patter
  • Loading branch information
Patbox committed Apr 2, 2023
1 parent 0a19d55 commit e30e2af
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 4 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.74.2+1.19.4

maven_group = eu.pb4

mod_version = 0.4.3
mod_version = 0.4.4

minecraft_version_supported = ">=1.19.4-"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package eu.pb4.polymer.core.mixin.other;

import com.mojang.serialization.DynamicOps;
import eu.pb4.polymer.core.api.utils.PolymerSyncedObject;
import eu.pb4.polymer.core.api.utils.PolymerUtils;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.entry.RegistryFixedCodec;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(RegistryFixedCodec.class)
public class RegistryFixedCodecMixin {
@Shadow @Final private RegistryKey<Registry> registry;

@ModifyVariable(
method = "encode(Lnet/minecraft/registry/entry/RegistryEntry;Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;",
at = @At("HEAD")
)
private RegistryEntry<?> polymerCore$swapEntry(RegistryEntry<?> entry) {
var player = PolymerUtils.getPlayerContext();

if (player != null) {
try {
if (entry.value() instanceof PolymerSyncedObject polymerSyncedObject) {
return ((Registry<Registry>) (Object) Registries.REGISTRIES).get(this.registry).getEntry(polymerSyncedObject.getPolymerReplacement(player));
}
} catch (Throwable e) {
e.printStackTrace();
}
}

return entry;
}
}
1 change: 1 addition & 0 deletions polymer-core/src/main/resources/polymer-core.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"other.IndexedNetworkMixin",
"other.ItemGroupsAccessor",
"other.PacketByteBufMixin",
"other.RegistryFixedCodecMixin",
"other.RemoveEntityStatusEffectS2CPacketMixin",
"other.ServerPlayerEntityMixin",
"other.ServerPlayNetworkHandlerMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public void onInitialize() {
//PolymerResourcePackUtils.addModAsAssetsSource("promenade");
register(Registries.ITEM, new Identifier("bugged", "wooden_sword"), new BuggedItem(new Item.Settings()));

register(Registries.ITEM, new Identifier("test", "emerald"), new SimplePolymerItem(new Item.Settings(), Items.EMERALD));
register(Registries.ITEM, new Identifier("test", "item"), ITEM);
register(Registries.ITEM, new Identifier("test", "item2"), ITEM_2);
register(Registries.ITEM, new Identifier("test", "item3"), ITEM_3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"test:item"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"asset_name": "test",
"description": {
"color": "#6006ab",
"translate": "TEST"
},
"ingredient": "test:item",
"item_model_index": 0.193702
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"asset_id": "test",
"description": {
"color": "#6006ab",
"translate": "TEST"
},
"template_item": "test:item"
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ public void updateCurrentlyTracking(Collection<ServerPlayNetworkHandler> current

@Override
public void updateTracking(ServerPlayNetworkHandler tracking) {
if (tracking.player.world != this.chunk.getWorld() || tracking.player.isDead()) {
this.stopWatching(tracking);
return;
}

var tacs = tracking.player.getWorld().getChunkManager().threadedAnvilChunkStorage;
var section = tracking.getPlayer().getWatchedSection();
if (!tacs.isWithinDistance(this.chunk.getPos().x, this.chunk.getPos().z, section.getX(), section.getMaxZ(), ((ThreadedAnvilChunkStorageAccessor) tacs).getWatchDistance())) {
if (!tacs.isWithinDistance(this.chunk.getPos().x, this.chunk.getPos().z, section.getX(), section.getZ(), ((ThreadedAnvilChunkStorageAccessor) tacs).getWatchDistance())) {
this.stopWatching(tracking);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ServerPlayerEntityMixin {
}
}

@Inject(method = "onDeath", at = @At("HEAD"))
@Inject(method = "onDeath", at = @At("TAIL"))
private void polymerVE$removeOnDeath(DamageSource source, CallbackInfo ci) {
for (var holder : new ArrayList<>(((HolderHolder) this.networkHandler).polymer$getHolders())) {
if (holder.getAttachment() != null) {
Expand All @@ -54,7 +54,7 @@ public class ServerPlayerEntityMixin {
}
}

@Inject(method = "moveToWorld", at = @At("HEAD"))
@Inject(method = "moveToWorld", at = @At(value = "RETURN"))
private void polymerVE$removeOnWorldChange(ServerWorld destination, CallbackInfoReturnable<Entity> cir) {
for (var holder : new ArrayList<>(((HolderHolder) this.networkHandler).polymer$getHolders())) {
if (holder.getAttachment() != null) {
Expand Down

0 comments on commit e30e2af

Please sign in to comment.