Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shadow (Echo?) Ploy #12

Merged
merged 25 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2dcd740
Pinned nixpkgs to avoid re-download
StellarWitch7 Jul 2, 2024
6c7f829
Pain
StellarWitch7 Jul 3, 2024
bb0c322
Hell, what am I even doing
StellarWitch7 Jul 3, 2024
31bf14d
Begone! Out of my sight, filthy bug
StellarWitch7 Jul 3, 2024
f3ecdaa
Sigh... I'll commit this at least
enjarai Jul 3, 2024
b9019eb
Fuckin works! (still need siodum coompat tho...)
enjarai Jul 3, 2024
d9ae92b
A little cleaning up in advance
enjarai Jul 3, 2024
80234ef
Merge branch 'master' into master
StellarWitch7 Jul 3, 2024
c830474
State changes now dispel shadow blocks
StellarWitch7 Jul 3, 2024
506c8f1
Begone! You are no longer needed.
StellarWitch7 Jul 3, 2024
7368974
Support maps with shadowy shenanigans
enjarai Jul 3, 2024
d177aa2
By mine wand I say, show yourself, fragile thing!
StellarWitch7 Jul 3, 2024
b24d8df
Added Iteration Stratagem
StellarWitch7 Jul 4, 2024
af0aa30
Right it gets funky without this
StellarWitch7 Jul 4, 2024
1593326
Progress... or so you'd think!
StellarWitch7 Jul 4, 2024
75f145d
Sododium compattata workerini!
enjarai Jul 4, 2024
c216d39
Slight performance bettterinations?
enjarai Jul 4, 2024
ada4787
These should be slashes apparently
enjarai Jul 4, 2024
780d241
Removed varargs for list iterator
StellarWitch7 Jul 4, 2024
e032e25
We love packet spam
enjarai Jul 4, 2024
62e51a4
Where is my source of truth, did I leave it in the car?
StellarWitch7 Jul 4, 2024
74cc097
A realm of biting cold and hollow darkness
StellarWitch7 Jul 4, 2024
b1b59fc
Merge branch 'master' into master
StellarWitch7 Jul 4, 2024
2843c6d
This is something i was doing by the way, ill just throw it in here c…
enjarai Jul 4, 2024
d5467eb
Performance fixes and solid block check, dont want flowers making us …
enjarai Jul 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ repositories {
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.

maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}

maven {
url 'https://maven.wispforest.io'
}
Expand Down Expand Up @@ -50,6 +58,40 @@ loom {
}
}

runs {
client_mixin {
client()
ideConfigGenerated true
name = "Minecraft Client - (Mixin Swap)"
source sourceSets.main
source sourceSets.client
vmArg "-Dmixin.debug.export=true"

try {
afterEvaluate {
def mixinDep = this.configurations.compileClasspath
.allDependencies
.findAll { it.name == "sponge-mixin" }
.first()

if (mixin != null) {
def mixinPath = this.configurations.compileClasspath.files(mixinDep).first().path;

println(mixinPath)

vmArg("-javaagent:\"${mixinPath}\"")

println("[Info]: Mixin Hotswap Run should be working")
} else {
println("[Warning]: Unable to locate file path for Mixin Jar, HotSwap Run will not work!!!")
}
}
} catch (Exception e) {
println("[Error]: MixinHotswap Run had a issue!")
e.printStackTrace()
}
}
}
}

dependencies {
Expand All @@ -73,9 +115,11 @@ dependencies {
}

include modImplementation("org.ladysnake.cardinal-components-api:cardinal-components-base:${property('deps.cardinal-components-api')}")
include modImplementation("org.ladysnake.cardinal-components-api:cardinal-components-chunk:${property('deps.cardinal-components-api')}")
include modImplementation("org.ladysnake.cardinal-components-api:cardinal-components-entity:${property('deps.cardinal-components-api')}")

modImplementation "com.terraformersmc:modmenu:${property('deps.modmenu')}"
modClientImplementation "maven.modrinth:sodium:${property('deps.sodium')}"
}

processResources {
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ deps.owo-lib=0.12.10+1.21
deps.lavender=0.1.10+1.21
deps.cicada=0.8.0+1.21-and-above
deps.cardinal-components-api=6.1.0
deps.modmenu=11.0.1
deps.modmenu=11.0.1

# Optional
deps.sodium=mc1.21-0.5.11
4 changes: 2 additions & 2 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let
nixpkgsVer = "24.05";
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-${nixpkgsVer}") { config = {}; overlays = []; };
nixpkgsVer = "7069932e560daa85506f65ec7f63e4bbc5e0d22a";
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/${nixpkgsVer}.tar.gz") { config = {}; overlays = []; };
libs = with pkgs; [
libpulseaudio
libGL
Expand Down
4 changes: 4 additions & 0 deletions src/client/java/dev/enjarai/trickster/DisguiseUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import com.mojang.authlib.GameProfile;
import dev.enjarai.trickster.cca.DisguiseCumponent;
import dev.enjarai.trickster.cca.ModChunkCumponents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk;
import org.jetbrains.annotations.Nullable;

public class DisguiseUtil {
Expand Down
14 changes: 8 additions & 6 deletions src/client/java/dev/enjarai/trickster/TricksterClient.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.enjarai.trickster;

import dev.enjarai.trickster.block.ModBlocks;
import dev.enjarai.trickster.cca.ModCumponents;
import dev.enjarai.trickster.cca.ModEntityCumponents;
import dev.enjarai.trickster.net.IsEditingScrollPacket;
import dev.enjarai.trickster.net.MladyPacket;
import dev.enjarai.trickster.net.ModClientNetworking;
import dev.enjarai.trickster.net.ModNetworking;
import dev.enjarai.trickster.particle.ModParticles;
import dev.enjarai.trickster.particle.ProtectedBlockParticle;
Expand All @@ -13,17 +13,16 @@
import dev.enjarai.trickster.screen.owo.GlyphComponent;
import io.wispforest.owo.ui.parsing.UIParsing;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;

public class TricksterClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ModHandledScreens.register();
ModKeyBindings.register();
ModClientNetworking.register();

BlockEntityRendererFactories.register(ModBlocks.SPELL_CIRCLE_ENTITY, SpellCircleBlockEntityRenderer::new);

Expand All @@ -34,8 +33,11 @@ public void onInitializeClient() {

ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (client.player != null) {
var is_editing = client.currentScreen instanceof ScrollAndQuillScreen;
ModNetworking.CHANNEL.clientHandle().send(new IsEditingScrollPacket(is_editing));
var editing = client.currentScreen instanceof ScrollAndQuillScreen;
var serverEditing = ModEntityCumponents.IS_EDITING_SCROLL.get(client.player).isEditing();
if (editing != serverEditing) {
ModNetworking.CHANNEL.clientHandle().send(new IsEditingScrollPacket(editing));
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.mojang.authlib.GameProfile;
import dev.enjarai.trickster.DisguiseUtil;
import dev.enjarai.trickster.Trickster;
import dev.enjarai.trickster.cca.ModCumponents;
import dev.enjarai.trickster.cca.ModEntityCumponents;
import dev.enjarai.trickster.quack.DisguisePlayerQuack;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
Expand Down Expand Up @@ -32,7 +32,7 @@ protected AbstractClientPlayerEntityMixin(EntityType<? extends LivingEntity> ent
}

public PlayerListEntry trickster$getApplicableEntry() {
var disguise = getComponent(ModCumponents.DISGUISE);
var disguise = getComponent(ModEntityCumponents.DISGUISE);
if (disguise.getUuid() != null) {
if (disguisePlayerListEntry == null || !disguisePlayerListEntry.getProfile().getId().equals(disguise.getUuid())) {
// Update the entry if its out of date
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package dev.enjarai.trickster.mixin.client;


import dev.enjarai.trickster.cca.ModCumponents;
import dev.enjarai.trickster.item.ModItems;
import dev.enjarai.trickster.cca.ModEntityCumponents;
import dev.enjarai.trickster.item.component.ModComponents;
import dev.enjarai.trickster.render.SpellCircleRenderer;
import dev.enjarai.trickster.screen.ScrollAndQuillScreen;
import dev.enjarai.trickster.spell.SpellPart;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Hand;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -60,7 +55,7 @@ public abstract class PlayerRendererMixin {
var mainHandSpell = mainHandStack.get(ModComponents.SPELL);
var offHandSpell = offHandStack.get(ModComponents.SPELL);

if (entity.getComponent(ModCumponents.IS_EDITING_SCROLL).isEditing()) {
if (entity.getComponent(ModEntityCumponents.IS_EDITING_SCROLL).isEditing()) {
if (mainHandStack.get(ModComponents.SPELL) != null && mainHandSpell != null) {
return Optional.of(mainHandSpell.spell());
} else if (mainHandStack.get(ModComponents.SPELL) != null && offHandSpell != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.enjarai.trickster.mixin.client;

import com.google.common.base.Suppliers;
import dev.enjarai.trickster.cca.ModChunkCumponents;
import dev.enjarai.trickster.cca.ShadowDisguiseMapComponent;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.WorldChunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.function.Supplier;

@Mixin(targets = "net/minecraft/client/render/chunk/RenderedChunk")
public class RenderedChunkMixin {
@Shadow
@Final
private WorldChunk chunk;
@Unique
private final Supplier<ShadowDisguiseMapComponent> disguises =
Suppliers.memoize(() -> ModChunkCumponents.SHADOW_DISGUISE_MAP.getNullable(chunk));

@Inject(
method = "getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;",
at = @At("HEAD"),
cancellable = true
)
private void disguiseBlockState(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
if (disguises.get() != null) {
var funnyState = disguises.get().getFunnyState(pos);
if (funnyState != null) {
cir.setReturnValue(funnyState);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.enjarai.trickster.mixin.client;

import net.minecraft.client.render.WorldRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(WorldRenderer.class)
public interface WorldRendererAccessor {
@Invoker("scheduleChunkRender")
void trickster$scheduleChunkRender(int x, int y, int z, boolean important);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.enjarai.trickster.mixin.client.sodium;

import dev.enjarai.trickster.cca.ModChunkCumponents;
import dev.enjarai.trickster.cca.ShadowDisguiseMapComponent;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import me.jellysquid.mods.sodium.client.world.WorldSlice;
import net.minecraft.block.BlockState;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.world.chunk.EmptyChunk;
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.CallbackInfoReturnable;

@Mixin(WorldSlice.class)
public abstract class WorldSliceMixin {
@Shadow
@Final
private ClientWorld world;
@Unique
private final Long2ObjectOpenHashMap<ShadowDisguiseMapComponent> componentCache = new Long2ObjectOpenHashMap<>();

@Inject(
method = "getBlockState(III)Lnet/minecraft/block/BlockState;",
at = @At(
value = "FIELD",
target = "Lme/jellysquid/mods/sodium/client/world/WorldSlice;originX:I"
),
cancellable = true
)
private void disguiseBlockState(int x, int y, int z, CallbackInfoReturnable<BlockState> cir) {
var chunkX = x >> 4;
var chunkZ = z >> 4;
var chunkId = ((long) chunkX) << 32 | ((long) chunkZ);

var disguises = componentCache.get(chunkId);
if (disguises == null) {
var chunk = world.getChunk(chunkX, chunkZ);

if (chunk != null && !(chunk instanceof EmptyChunk)) {
disguises = ModChunkCumponents.SHADOW_DISGUISE_MAP.get(chunk);
componentCache.put(chunkId, disguises);
}
}

if (disguises != null) {
var funnyState = disguises.getFunnyState(x, y, z);

if (funnyState != null) {
cir.setReturnValue(funnyState);
}
}
}
}
22 changes: 22 additions & 0 deletions src/client/java/dev/enjarai/trickster/net/ModClientNetworking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.enjarai.trickster.net;

import dev.enjarai.trickster.mixin.client.WorldRendererAccessor;
import net.minecraft.util.math.ChunkSectionPos;

public class ModClientNetworking {
@SuppressWarnings("resource")
public static void register() {
ModNetworking.CHANNEL.registerClientbound(RebuildChunkPacket.class, (message, access) -> {
var pos = message.pos();

ChunkSectionPos.forEachChunkSectionAround(pos, chunk ->
((WorldRendererAccessor) access.runtime().worldRenderer)
.trickster$scheduleChunkRender(
ChunkSectionPos.unpackX(chunk),
ChunkSectionPos.unpackY(chunk),
ChunkSectionPos.unpackZ(chunk),
true
));
});
}
}
37 changes: 37 additions & 0 deletions src/client/java/dev/enjarai/trickster/screen/SignScrollScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.enjarai.trickster.screen;

import dev.enjarai.trickster.net.ModNetworking;
import dev.enjarai.trickster.net.SignScrollPacket;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;

public class SignScrollScreen extends Screen {
private final Hand hand;
private TextFieldWidget textField;

protected SignScrollScreen(Text title, Hand hand) {
super(title);
this.hand = hand;
}

@Override
protected void init() {
textField = addDrawableChild(new TextFieldWidget(
textRenderer, this.width / 2 - 100, 174, 200, 20,
Text.translatable("trickster.widget.scroll_name")
));

addDrawableChild(ButtonWidget.builder(Text.translatable("book.signButton"), button -> {
ModNetworking.CHANNEL.clientHandle().send(new SignScrollPacket(hand, textField.getText()));
this.client.setScreen(null);
}).dimensions(this.width / 2 - 100, 196, 98, 20).build());

addDrawableChild(ButtonWidget.builder(ScreenTexts.CANCEL, button -> {
this.client.setScreen(null);
}).dimensions(this.width / 2 + 2, 196, 98, 20).build());
}
}
8 changes: 6 additions & 2 deletions src/client/resources/trickster.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
"required": true,
"package": "dev.enjarai.trickster.mixin.client",
"compatibilityLevel": "JAVA_21",
"plugin": "dev.enjarai.trickster.ConditionalMixins",
"client": [
"AbstractClientPlayerEntityMixin",
"HeldItemRendererMixin",
"InGameHudMixin",
"PlayerRendererMixin",
"MouseMixin",
"SillyHairsFeatureRendererMixin"
"PlayerRendererMixin",
"RenderedChunkMixin",
"SillyHairsFeatureRendererMixin",
"WorldRendererAccessor",
"sodium.WorldSliceMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Loading