-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added player.activePostShader = null/'shader id' method. Persists ove…
…r deaths and dimension change but not when disconnected from world/server
- Loading branch information
1 parent
77be99a
commit 4d40014
Showing
16 changed files
with
180 additions
and
5 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/dev/latvian/mods/kubejs/core/ClientPacketListenerKJS.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,10 @@ | ||
package dev.latvian.mods.kubejs.core; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import org.apache.commons.lang3.mutable.Mutable; | ||
|
||
public interface ClientPacketListenerKJS { | ||
default Mutable<ResourceLocation> kjs$activePostShader() { | ||
throw new NoMixinException(); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/dev/latvian/mods/kubejs/core/mixin/ClientPacketListenerMixin.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,20 @@ | ||
package dev.latvian.mods.kubejs.core.mixin; | ||
|
||
import dev.latvian.mods.kubejs.core.ClientPacketListenerKJS; | ||
import net.minecraft.client.multiplayer.ClientPacketListener; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.apache.commons.lang3.mutable.Mutable; | ||
import org.apache.commons.lang3.mutable.MutableObject; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@Mixin(ClientPacketListener.class) | ||
public class ClientPacketListenerMixin implements ClientPacketListenerKJS { | ||
@Unique | ||
private final Mutable<ResourceLocation> kjs$activePostShader = new MutableObject<>(null); | ||
|
||
@Override | ||
public Mutable<ResourceLocation> kjs$activePostShader() { | ||
return kjs$activePostShader; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/main/java/dev/latvian/mods/kubejs/core/mixin/GameRendererMixin.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,41 @@ | ||
package dev.latvian.mods.kubejs.core.mixin; | ||
|
||
import dev.latvian.mods.kubejs.core.ClientPacketListenerKJS; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import net.minecraft.client.renderer.PostChain; | ||
import net.minecraft.resources.ResourceLocation; | ||
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.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@Mixin(GameRenderer.class) | ||
public abstract class GameRendererMixin { | ||
@Shadow | ||
@Final | ||
Minecraft minecraft; | ||
|
||
@Shadow | ||
@Nullable | ||
PostChain postEffect; | ||
|
||
@Shadow | ||
public abstract void loadEffect(ResourceLocation resourceLocation); | ||
|
||
@Inject(method = "checkEntityPostEffect", at = @At("HEAD"), cancellable = true) | ||
private void kjs$checkEntityPostEffect(CallbackInfo ci) { | ||
if (minecraft.getConnection() instanceof ClientPacketListenerKJS connection && connection.kjs$activePostShader().getValue() != null) { | ||
if (postEffect != null) { | ||
postEffect.close(); | ||
} | ||
|
||
loadEffect(connection.kjs$activePostShader().getValue()); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/dev/latvian/mods/kubejs/net/SetActivePostShaderPayload.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,23 @@ | ||
package dev.latvian.mods.kubejs.net; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.neoforged.neoforge.network.handling.IPayloadContext; | ||
|
||
import java.util.Optional; | ||
|
||
public record SetActivePostShaderPayload(Optional<ResourceLocation> id) implements CustomPacketPayload { | ||
public static final StreamCodec<ByteBuf, SetActivePostShaderPayload> STREAM_CODEC = ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC).map(SetActivePostShaderPayload::new, SetActivePostShaderPayload::id); | ||
|
||
@Override | ||
public Type<?> type() { | ||
return KubeJSNet.SET_ACTIVE_POST_SHADER; | ||
} | ||
|
||
public void handle(IPayloadContext ctx) { | ||
ctx.enqueueWork(() -> ctx.player().kjs$setActivePostShader(id.orElse(null))); | ||
} | ||
} |
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