From 827cd18f6ce25b91f3fe061eb51d434437042356 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Mon, 23 Oct 2023 23:38:03 -0400 Subject: [PATCH] hopefully working reach effect --- .../frozenblock/wilderwild/WilderWild.java | 2 + .../client/crab/MultiPlayerGameModeMixin.java | 30 ++++++++++++ .../crab/ServerPlayerGameModeMixin.java | 27 +++++++++++ .../registry/RegisterMobEffects.java | 43 ++++++++++++++++++ .../assets/wilderwild/lang/en_us.json | 1 + .../textures/mob_effect/reach_boost.png | Bin 0 -> 280 bytes src/main/resources/wilderwild.mixins.json | 2 + 7 files changed, 105 insertions(+) create mode 100644 src/main/java/net/frozenblock/wilderwild/mixin/client/crab/MultiPlayerGameModeMixin.java create mode 100644 src/main/java/net/frozenblock/wilderwild/mixin/entity/crab/ServerPlayerGameModeMixin.java create mode 100644 src/main/java/net/frozenblock/wilderwild/registry/RegisterMobEffects.java create mode 100644 src/main/resources/assets/wilderwild/textures/mob_effect/reach_boost.png diff --git a/src/main/java/net/frozenblock/wilderwild/WilderWild.java b/src/main/java/net/frozenblock/wilderwild/WilderWild.java index 84bd681876..4d2e651d18 100644 --- a/src/main/java/net/frozenblock/wilderwild/WilderWild.java +++ b/src/main/java/net/frozenblock/wilderwild/WilderWild.java @@ -49,6 +49,7 @@ import net.frozenblock.wilderwild.registry.RegisterItems; import net.frozenblock.wilderwild.registry.RegisterLootTables; import net.frozenblock.wilderwild.registry.RegisterMemoryModuleTypes; +import net.frozenblock.wilderwild.registry.RegisterMobEffects; import net.frozenblock.wilderwild.registry.RegisterParticles; import net.frozenblock.wilderwild.registry.RegisterProperties; import net.frozenblock.wilderwild.registry.RegisterResources; @@ -163,6 +164,7 @@ public void onInitialize(String modId, ModContainer container) { RegisterParticles.registerParticles(); RegisterResources.register(container); RegisterProperties.init(); + RegisterMobEffects.init(); RegisterCriteria.init(); RegisterFeatures.init(); diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/client/crab/MultiPlayerGameModeMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/client/crab/MultiPlayerGameModeMixin.java new file mode 100644 index 0000000000..370cbeb20b --- /dev/null +++ b/src/main/java/net/frozenblock/wilderwild/mixin/client/crab/MultiPlayerGameModeMixin.java @@ -0,0 +1,30 @@ +package net.frozenblock.wilderwild.mixin.client.crab; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.frozenblock.wilderwild.registry.RegisterMobEffects; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; +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; + +@Environment(EnvType.CLIENT) +@Mixin(MultiPlayerGameMode.class) +public class MultiPlayerGameModeMixin { + + @Shadow @Final + private Minecraft minecraft; + + @ModifyReturnValue(method = "getPickRange", at = @At("RETURN")) + public float wilderWild$getPickRange(float original) { + if (this.minecraft.player != null && this.minecraft.player.hasEffect(RegisterMobEffects.REACH)) { + int amplifier = this.minecraft.player.getEffect(RegisterMobEffects.REACH).getAmplifier() + 1; + return original + (amplifier * 0.75F); + } + return original; + } + +} diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/entity/crab/ServerPlayerGameModeMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/entity/crab/ServerPlayerGameModeMixin.java new file mode 100644 index 0000000000..24488eb001 --- /dev/null +++ b/src/main/java/net/frozenblock/wilderwild/mixin/entity/crab/ServerPlayerGameModeMixin.java @@ -0,0 +1,27 @@ +package net.frozenblock.wilderwild.mixin.entity.crab; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.frozenblock.wilderwild.registry.RegisterMobEffects; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerPlayerGameMode; +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; + +@Mixin(ServerPlayerGameMode.class) +public class ServerPlayerGameModeMixin { + + @Shadow @Final + protected ServerPlayer player; + + @ModifyExpressionValue(method = "handleBlockBreakAction", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;MAX_INTERACTION_DISTANCE:D")) + public double wilderWild$handleBlockBreakAction(double original) { + if (this.player != null && this.player.hasEffect(RegisterMobEffects.REACH)) { + int amplifier = this.player.getEffect(RegisterMobEffects.REACH).getAmplifier() + 1; + return original + (amplifier * 0.75); + } + return original; + } + +} diff --git a/src/main/java/net/frozenblock/wilderwild/registry/RegisterMobEffects.java b/src/main/java/net/frozenblock/wilderwild/registry/RegisterMobEffects.java new file mode 100644 index 0000000000..bca591e6d8 --- /dev/null +++ b/src/main/java/net/frozenblock/wilderwild/registry/RegisterMobEffects.java @@ -0,0 +1,43 @@ +/* + * Copyright 2023 FrozenBlock + * This file is part of Wilder Wild. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, see . + */ + +package net.frozenblock.wilderwild.registry; + +import net.frozenblock.wilderwild.misc.WilderSharedConstants; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectCategory; +import org.jetbrains.annotations.NotNull; + +public final class RegisterMobEffects { + + public static final MobEffect REACH = register("reach_boost", new MobEffect(MobEffectCategory.BENEFICIAL, 16646020)); + + private RegisterMobEffects() { + throw new UnsupportedOperationException("RegisterMobEffects contains only static declarations."); + } + + public static void init() { + WilderSharedConstants.logWild("Registering MobEffects for", WilderSharedConstants.UNSTABLE_LOGGING); + } + + private static @NotNull MobEffect register(String id, MobEffect entry) { + return Registry.register(BuiltInRegistries.MOB_EFFECT, WilderSharedConstants.id(id), entry); + } +} diff --git a/src/main/resources/assets/wilderwild/lang/en_us.json b/src/main/resources/assets/wilderwild/lang/en_us.json index de9f0e18c1..720ed61226 100644 --- a/src/main/resources/assets/wilderwild/lang/en_us.json +++ b/src/main/resources/assets/wilderwild/lang/en_us.json @@ -238,6 +238,7 @@ "item.wilderwild.yellow_firefly_bottle": "Yellow Firefly in a Bottle", "item.wilderwild.split_coconut": "Split Coconut", "item.wilderwild.prickly_pear": "Prickly Pear", + "effect.wilderwild.reach_boost": "Reach Boost", "option.wilderwild.component.title": "Wilder Wild Options", "option.wilderwild.block": "Block", "option.wilderwild.entity": "Entity", diff --git a/src/main/resources/assets/wilderwild/textures/mob_effect/reach_boost.png b/src/main/resources/assets/wilderwild/textures/mob_effect/reach_boost.png new file mode 100644 index 0000000000000000000000000000000000000000..87eb2389ae52f93c003139558c1df21e836a2cbd GIT binary patch literal 280 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+3?vf;>QaG}Wq?nJYyO_Qr8~|=tv?^UkOMF;MWRrtdAFC|^mC zUoenH0;^u+g#)<_o-U3d6}LjqUF15Vz~d4)JL>K$x5+>M_s8C4jDD_KpipqQ+$S{E zXXgRsgSID>x+HsDBE_a%@F?E;67Iql#r(;+s6zVl zW7&)9Uv(G#-R>HZzxH<5gem$yhqk&#yg%0ATFie`B3pOqm0z8Kq4iQ9_#+F05*~w` N=IQF^vd$@?2>>cvZiN5< literal 0 HcmV?d00001 diff --git a/src/main/resources/wilderwild.mixins.json b/src/main/resources/wilderwild.mixins.json index ed9fc3bb3f..8d4f8ad1f9 100644 --- a/src/main/resources/wilderwild.mixins.json +++ b/src/main/resources/wilderwild.mixins.json @@ -36,6 +36,7 @@ "entity.boat.BoatDropsMixin", "entity.boat.BoatTypeMixin", "entity.boat.ChestBoatDropsMixin", + "entity.crab.ServerPlayerGameModeMixin", "entity.crab.VibrationSystemTickerMixin", "entity.crab.WallClimberNavigationMixin", "entity.easter.EntityMixin", @@ -89,6 +90,7 @@ "client": [ "client.allay.AllayModelMixin", "client.brush.LevelRendererMixin", + "client.crab.MultiPlayerGameModeMixin", "client.easter.MerpSlimeRenderer", "client.easter.ScottTheWozMixin", "client.easter.StellaWardenModel",