-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
160 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
polymer-core/src/main/java/eu/pb4/polymer/core/impl/TransformingComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package eu.pb4.polymer.core.impl; | ||
|
||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import xyz.nucleoid.packettweaker.PacketContext; | ||
|
||
public interface TransformingComponent { | ||
Object polymer$getTransformed(ServerPlayerEntity player); | ||
boolean polymer$requireModification(ServerPlayerEntity player); | ||
Object polymer$getTransformed(PacketContext context); | ||
boolean polymer$requireModification(PacketContext context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...src/main/java/eu/pb4/polymer/core/mixin/item/component/DebugStickStateComponentMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package eu.pb4.polymer.core.mixin.item.component; | ||
|
||
import eu.pb4.polymer.core.api.utils.PolymerSyncedObject; | ||
import eu.pb4.polymer.core.impl.TransformingComponent; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.component.type.DebugStickStateComponent; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.state.property.Property; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import xyz.nucleoid.packettweaker.PacketContext; | ||
|
||
import java.util.Map; | ||
|
||
@Mixin(DebugStickStateComponent.class) | ||
public class DebugStickStateComponentMixin implements TransformingComponent { | ||
@Shadow @Final private Map<RegistryEntry<Block>, Property<?>> properties; | ||
|
||
@Override | ||
public Object polymer$getTransformed(PacketContext context) { | ||
if (polymer$requireModification(context)) { | ||
return DebugStickStateComponent.DEFAULT; | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean polymer$requireModification(PacketContext context) { | ||
for (var key : this.properties.keySet()) { | ||
if (!PolymerSyncedObject.canSyncRawToClient(Registries.BLOCK, key.value(), context.getPlayer())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
polymer-core/src/main/java/eu/pb4/polymer/core/mixin/other/ComponentChangesMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package eu.pb4.polymer.core.mixin.other; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.mojang.serialization.Codec; | ||
import eu.pb4.polymer.common.api.PolymerCommonUtils; | ||
import eu.pb4.polymer.core.api.other.PolymerComponent; | ||
import eu.pb4.polymer.core.impl.TransformingComponent; | ||
import eu.pb4.polymer.core.impl.networking.TransformingPacketCodec; | ||
import net.minecraft.component.ComponentChanges; | ||
import net.minecraft.component.ComponentType; | ||
import net.minecraft.network.RegistryByteBuf; | ||
import net.minecraft.network.codec.PacketCodec; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import xyz.nucleoid.packettweaker.PacketContext; | ||
|
||
import java.util.function.Function; | ||
|
||
@Mixin(ComponentChanges.class) | ||
public class ComponentChangesMixin { | ||
@Mutable | ||
@Shadow @Final public static PacketCodec<RegistryByteBuf, ComponentChanges> PACKET_CODEC; | ||
|
||
@ModifyExpressionValue(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/Codec;xmap(Ljava/util/function/Function;Ljava/util/function/Function;)Lcom/mojang/serialization/Codec;")) | ||
private static Codec<ComponentChanges> patchCodec(Codec<ComponentChanges> codec) { | ||
return codec.xmap(Function.identity(), content -> { // Encode | ||
if (PolymerCommonUtils.isServerNetworkingThread()) { | ||
return transformContent(content); | ||
} | ||
return content; | ||
}); | ||
} | ||
|
||
@Inject(method = "<clinit>", at = @At("TAIL")) | ||
private static void patchNetCodec(CallbackInfo ci) { | ||
PACKET_CODEC = TransformingPacketCodec.encodeOnly(PACKET_CODEC, ((byteBuf, content) -> transformContent(content))); | ||
} | ||
|
||
@Unique | ||
private static ComponentChanges transformContent(ComponentChanges content) { | ||
var player = PacketContext.get(); | ||
var builder = ComponentChanges.builder(); | ||
for (var entry : content.entrySet()) { | ||
if (!PolymerComponent.canSync(entry.getKey(), entry.getValue().orElse(null), player)) { | ||
continue; | ||
} else if (entry.getValue().isPresent() && entry.getValue().get() instanceof TransformingComponent t) { | ||
//noinspection unchecked | ||
builder.add((ComponentType<Object>) entry.getKey(), t.polymer$getTransformed(player)); | ||
} | ||
|
||
if (entry.getValue().isPresent()) { | ||
//noinspection unchecked | ||
builder.add((ComponentType<Object>) entry.getKey(), entry.getValue().get()); | ||
} else { | ||
builder.remove(entry.getKey()); | ||
} | ||
} | ||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.