Skip to content

Commit 2cd90f4

Browse files
committed
Implement cockroach dance mechanics and update gradle properties
1 parent 949282e commit 2cd90f4

16 files changed

Lines changed: 316 additions & 347 deletions

forge/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ dependencies {
3434
modCompileOnly "curse.maven:citadel-331936:5633260"
3535

3636
// Forge-only runtime dependencies for development
37-
modRuntimeOnly "curse.maven:alexs-mobs-426558:5698791"
38-
modRuntimeOnly "curse.maven:citadel-331936:5633260"
37+
//modRuntimeOnly "curse.maven:alexs-mobs-426558:5698791"
38+
// modRuntimeOnly "curse.maven:citadel-331936:5633260"
3939

4040
common(project(path: ":common", configuration: "namedElements")) { transitive = false }
4141
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }

forge/src/main/java/draylar/identity/api/model/forge/EntityUpdaterForge.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import com.github.alexthe666.alexsmobs.entity.AMEntityRegistry;
44
import draylar.identity.api.model.EntityUpdaters;
55
import draylar.identity.forge.IdentityForge;
6-
import draylar.identity.forge.network.ForceDancePacket;
7-
import draylar.identity.forge.network.NetworkHandler;
86
import draylar.identity.impl.NearbySongAccessor;
97

108
public class EntityUpdaterForge {
@@ -14,20 +12,21 @@ public static void init() {
1412
if (!IdentityForge.isAlexsMobsLoaded) {
1513
return;
1614
}
17-
EntityUpdaters.register(AMEntityRegistry.COCKROACH.get(), (player, cockroach) -> {
18-
if (player.isOnGround() && ((NearbySongAccessor) player).identity_isNearbySongPlaying()) {
19-
20-
cockroach.setNearbySongPlaying(player.getBlockPos(), true);
21-
cockroach.setDancing(true);
22-
cockroach.handleStatus((byte) 67);
23-
24-
NetworkHandler.CHANNEL.sendToServer(new ForceDancePacket(cockroach.getBlockPos()));
25-
26-
} else {
27-
cockroach.setNearbySongPlaying(player.getBlockPos(), false);
28-
cockroach.setDancing(false);
29-
}
30-
});
15+
System.out.println("Registering entity updaters for Alex's Mobs!");
16+
// EntityUpdaters.register(AMEntityRegistry.COCKROACH.get(), (player, cockroach) -> {
17+
// if (player.isOnGround() && ((NearbySongAccessor) player).identity_isNearbySongPlaying()) {
18+
//
19+
// cockroach.setNearbySongPlaying(player.getBlockPos(), true);
20+
// cockroach.setDancing(true);
21+
// player.handleStatus((byte) 67);
22+
// System.out.println("Playing nearby song!");
23+
//
24+
// } else {
25+
// cockroach.setNearbySongPlaying(player.getBlockPos(), false);
26+
// cockroach.setDancing(false);
27+
// System.out.println("Stopping nearby song!");
28+
// }
29+
// });
3130

3231
}
3332
}

forge/src/main/java/draylar/identity/forge/IdentityForge.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import draylar.identity.forge.ability.AlexsMobsAbilityRegistry;
66
import draylar.identity.forge.config.ConfigLoader;
77
import draylar.identity.forge.config.IdentityForgeConfig;
8-
//import draylar.identity.forge.mixin.accessor.ForgeLivingEntityAccessorCompat;
9-
import draylar.identity.forge.network.NetworkHandler;
108
import draylar.identity.util.IdentityCompatUtils;
119
import net.minecraftforge.common.MinecraftForge;
1210
import net.minecraftforge.fml.common.Mod;
@@ -35,7 +33,6 @@ public IdentityForge() {
3533

3634
private void setup(final FMLCommonSetupEvent event) {
3735
event.enqueueWork(() -> {
38-
NetworkHandler.registerPackets();
3936
AlexsMobsAbilityRegistry.init();
4037
});
4138
}

forge/src/main/java/draylar/identity/forge/ability/impl/CockRoachAbility.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,28 @@
22

33
import com.github.alexthe666.alexsmobs.entity.EntityCockroach;
44
import draylar.identity.ability.IdentityAbility;
5-
import draylar.identity.forge.compat.accessor.ForceDanceAccessor;
6-
import draylar.identity.forge.network.ForceDancePacket;
7-
import draylar.identity.forge.network.NetworkHandler;
8-
95
import draylar.identity.forge.util.CockroachDanceManager;
10-
import draylar.identity.forge.util.CockroachDanceUtil;
116
import net.minecraft.entity.player.PlayerEntity;
7+
import net.minecraft.server.network.ServerPlayerEntity;
8+
import net.minecraft.server.world.ServerWorld;
129
import net.minecraft.item.Item;
1310
import net.minecraft.item.Items;
1411
import net.minecraft.world.World;
1512

1613
public class CockRoachAbility extends IdentityAbility<EntityCockroach> {
14+
1715
@Override
1816
public void onUse(PlayerEntity player, EntityCockroach identity, World world) {
19-
if (!world.isClient) {
20-
CockroachDanceManager.forceDance(player, 200);
17+
if (!world.isClient && player instanceof ServerPlayerEntity sp) {
18+
// no longer need debug‐util: just send 67 to kick off the dance
19+
sp.getWorld().sendEntityStatus(player, (byte) 67);
20+
CockroachDanceManager.forceDance(sp, 200);
2121
}
2222
}
2323

2424

25-
26-
2725
@Override
2826
public Item getIcon() {
2927
return Items.MUSIC_DISC_CAT;
3028
}
3129
}
32-
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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+
}

forge/src/main/java/draylar/identity/forge/mixin/EntityCockroachClientMixin.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)