|
| 1 | +package draylar.identity.forge.mixin; |
| 2 | + |
| 3 | +import com.github.alexthe666.alexsmobs.entity.EntityCockroach; |
| 4 | +import com.mojang.authlib.GameProfile; |
| 5 | +import draylar.identity.api.PlayerIdentity; |
| 6 | +import net.minecraft.client.network.AbstractClientPlayerEntity; |
| 7 | +import net.minecraft.client.network.ClientPlayerEntity; |
| 8 | +import net.minecraft.client.world.ClientWorld; |
| 9 | +import net.minecraft.entity.Entity; |
| 10 | +import net.minecraft.predicate.entity.EntityPredicates; |
| 11 | +import net.minecraft.server.world.ServerWorld; |
| 12 | +import net.minecraft.util.math.Box; |
| 13 | +import org.spongepowered.asm.mixin.Mixin; |
| 14 | +import org.spongepowered.asm.mixin.Unique; |
| 15 | +import org.spongepowered.asm.mixin.injection.At; |
| 16 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | + |
| 19 | +import javax.annotation.Nullable; |
| 20 | +import java.util.UUID; |
| 21 | + |
| 22 | +/** |
| 23 | + * Listens for entity‐status bytes 67 (start) and 68 (stop) |
| 24 | + * on the CLIENT’s player, then runs your debugForceDance logic. |
| 25 | + */ |
| 26 | +@Mixin(ClientPlayerEntity.class) |
| 27 | +public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity{ |
| 28 | + |
| 29 | + @Unique private boolean identity$forceDanceActive = false; |
| 30 | + |
| 31 | + @Unique private boolean identity$prevStand = false; |
| 32 | + |
| 33 | + @Unique private int identity$laCucarachaTimer = 0; |
| 34 | + @Unique private boolean identity$hasMaracas = false; |
| 35 | + @Unique private UUID identity$nearestMusicianId = null; |
| 36 | + |
| 37 | + public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) { |
| 38 | + super(world, profile); |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | + // 67 = start dance, 68 = stop dance |
| 43 | + @Inject(method="handleStatus", at=@At("HEAD")) |
| 44 | + private void identity$onHandleStatus(byte status, CallbackInfo ci) { |
| 45 | + if (status == 67) { |
| 46 | + identity$forceDanceActive = true; |
| 47 | + } else if (status == 68) { |
| 48 | + identity$forceDanceActive = false; |
| 49 | + identity$hasMaracas= false; |
| 50 | + } else if (status==69) { |
| 51 | + identity$hasMaracas= true; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + // Once per tick, if armed, do the dance and consume the flag |
| 56 | + @Inject(method="tick", at=@At("HEAD")) |
| 57 | + private void identity$tickDance(CallbackInfo ci) { |
| 58 | + ClientPlayerEntity player = (ClientPlayerEntity)(Object)this; |
| 59 | + var morph = PlayerIdentity.getIdentity(player); |
| 60 | + if (!(morph instanceof EntityCockroach cockroach)) { |
| 61 | + return; |
| 62 | + } |
| 63 | +// |
| 64 | +// if (!this.identity$hasMaracas()) { |
| 65 | +// Entity musician = this.identity$getNearestMusician(); |
| 66 | +// if (musician != null) { |
| 67 | +// if (musician.isAlive() && !(this.distanceTo(musician) > 10.0F) && (!(musician instanceof EntityCockroach) || ((EntityCockroach)musician).hasMaracas())) { |
| 68 | +// identity$forceDanceActive = true; |
| 69 | +// cockroach.setNearestMusician(musician.getUuid()); |
| 70 | +// } else { |
| 71 | +// this.identity$setNearestMusician(null); |
| 72 | +// identity$forceDanceActive = false; |
| 73 | +// identity$hasMaracas = false; |
| 74 | +// } |
| 75 | +// } |
| 76 | +// } |
| 77 | +// |
| 78 | +// if (this.identity$hasMaracas()) { |
| 79 | +// ++this.identity$laCucarachaTimer; |
| 80 | +// if (this.identity$laCucarachaTimer % 20 == 0 && this.random.nextFloat() < 0.3F) { |
| 81 | +// identity$tellOthersImPlayingLaCucaracha(); |
| 82 | +// |
| 83 | +// } |
| 84 | +// |
| 85 | +// identity$forceDanceActive = true; |
| 86 | +// if (!this.isSilent()) { |
| 87 | +// this.getWorld().sendEntityStatus(cockroach, (byte)67); |
| 88 | +// |
| 89 | +// } |
| 90 | +// } |
| 91 | + |
| 92 | + boolean dancing = identity$forceDanceActive; |
| 93 | + |
| 94 | + // If we're neither dancing nor fading out, skip entirely: |
| 95 | + if (!dancing && cockroach.danceProgress == 0) { |
| 96 | + cockroach.setDancing(false); |
| 97 | + cockroach.setNearbySongPlaying(player.getBlockPos(), false); |
| 98 | +// identity$hasMaracas = false; |
| 99 | + } |
| 100 | + else { |
| 101 | + // 1) flip the flags so vanilla code knows we're dancing: |
| 102 | + cockroach.setDancing(dancing); |
| 103 | + cockroach.setNearbySongPlaying(player.getBlockPos(), dancing); |
| 104 | + } |
| 105 | + if(identity$hasMaracas) |
| 106 | + cockroach.setNearestMusician( player.getUuid()); |
| 107 | + else cockroach.setNearestMusician(null); |
| 108 | + // 2) now *run the real EntityCockroach.tick()* so it plays out |
| 109 | + // its own dance logic exactly as in Alex's Mobs. |
| 110 | + cockroach.tick(); |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +// // 1) If the server has turned dancing off, fade out: |
| 115 | +// if (!dancing) { |
| 116 | +// if (cockroach.danceProgress > 0.0F) { |
| 117 | +// // still fading |
| 118 | +// cockroach.prevDanceProgress = cockroach.danceProgress; |
| 119 | +// cockroach.danceProgress--; |
| 120 | +// |
| 121 | +// // wing-flap during fade |
| 122 | +// if (!cockroach.isOnGround() || player.clientWorld.random.nextInt(200) == 0) { |
| 123 | +// cockroach.randomWingFlapTick = 5 + player.clientWorld.random.nextInt(15); |
| 124 | +// } |
| 125 | +// if (cockroach.randomWingFlapTick > 0) { |
| 126 | +// cockroach.randomWingFlapTick--; |
| 127 | +// } |
| 128 | +// |
| 129 | +// return; // don’t run the “start” logic |
| 130 | +// } |
| 131 | +// |
| 132 | +// // fully faded out -> clear flags once |
| 133 | +// cockroach.setDancing(false); |
| 134 | +// cockroach.setNearbySongPlaying(cockroach.getBlockPos(), false); |
| 135 | +// identity$prevStand = false; |
| 136 | +// return; |
| 137 | +// } |
| 138 | +// |
| 139 | +// // 2) Otherwise, dancing==true -> run your “start dance” animation |
| 140 | +// |
| 141 | +// // store last progress |
| 142 | +// cockroach.prevDanceProgress = cockroach.danceProgress; |
| 143 | +// |
| 144 | +// // ramp up to full dance |
| 145 | +// if (cockroach.danceProgress < 5.0F) { |
| 146 | +// cockroach.danceProgress++; |
| 147 | +// } |
| 148 | +// |
| 149 | +// // wing-flap randomness |
| 150 | +// if (!cockroach.isOnGround() || player.clientWorld.random.nextInt(200) == 0) { |
| 151 | +// cockroach.randomWingFlapTick = 5 + player.clientWorld.random.nextInt(15); |
| 152 | +// } |
| 153 | +// if (cockroach.randomWingFlapTick > 0) { |
| 154 | +// cockroach.randomWingFlapTick--; |
| 155 | +// } |
| 156 | +// |
| 157 | +// // on toggle, recalc dimensions |
| 158 | +// if (identity$prevStand != dancing) { |
| 159 | +// if (cockroach.hasMaracas()) { |
| 160 | +// identity$tellOthersImPlayingLaCucaracha(); |
| 161 | +// } |
| 162 | +// cockroach.calculateDimensions(); |
| 163 | +// } |
| 164 | +// |
| 165 | +// // mark vanilla flags so vanilla tick() sees them if you call it |
| 166 | +// cockroach.setDancing(true); |
| 167 | +// cockroach.setNearbySongPlaying(cockroach.getBlockPos(), true); |
| 168 | +// |
| 169 | +// // remember stand state |
| 170 | +// identity$prevStand = true; |
| 171 | + } |
| 172 | + |
| 173 | + @Unique |
| 174 | + private boolean identity$hasMaracas() { |
| 175 | + return identity$hasMaracas; |
| 176 | + } |
| 177 | + |
| 178 | + @Unique |
| 179 | + private void identity$tellOthersImPlayingLaCucaracha() { |
| 180 | + for(EntityCockroach roach : this.getWorld().getEntitiesByClass(EntityCockroach.class, this.identity$getMusicianDistance(), EntityPredicates.EXCEPT_SPECTATOR)) { |
| 181 | + if (!roach.hasMaracas()) { |
| 182 | + roach.setNearestMusician(this.getUuid()); |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + } |
| 187 | + @Unique |
| 188 | + private Box identity$getMusicianDistance() { |
| 189 | + return this.getBoundingBox().expand((double)10.0F, (double)10.0F, (double)10.0F); |
| 190 | + } |
| 191 | + |
| 192 | + @Unique |
| 193 | + public Entity identity$getNearestMusician() { |
| 194 | + UUID id = this.identity$nearestMusicianId; |
| 195 | + return id != null && !this.getWorld().isClient ? ((ServerWorld)this.getWorld()).getEntity(id) : null; |
| 196 | + } |
| 197 | + |
| 198 | + @Unique |
| 199 | + public void identity$setNearestMusician(@Nullable UUID uniqueId) { |
| 200 | + this.identity$nearestMusicianId = uniqueId; |
| 201 | + } |
| 202 | + |
| 203 | +// |
| 204 | +// // === your debugForceDance() inline === |
| 205 | +// cockroach.setDancing(true); |
| 206 | +// cockroach.setNearbySongPlaying(cockroach.getBlockPos(), true); |
| 207 | +// cockroach.prevDanceProgress = cockroach.danceProgress; |
| 208 | +// cockroach.danceProgress = 5.0F; |
| 209 | +// cockroach.randomWingFlapTick = 10; |
| 210 | + |
| 211 | +} |
0 commit comments