Skip to content

Commit 85a626e

Browse files
committed
fix bunny on head
1 parent b677aa1 commit 85a626e

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

src/main/java/teamport/aether/entity/animal/aerbunny/MobAerbunny.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ public void tick() {
194194
if (this.vehicle instanceof Player) {
195195
Player player = (Player) vehicle;
196196

197+
if (!player.isAlive()) {
198+
player.ejectRider();
199+
}
200+
197201
if (!player.onGround && !player.noPhysics) {
198202
if (!player.isInWater()) player.yd += 0.05F;
199203
((EntityAccessor) player).setFallDistance(0.0F);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package teamport.aether.mixin.player;
2+
3+
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
5+
import net.fabricmc.api.EnvType;
6+
import net.fabricmc.api.Environment;
7+
import net.minecraft.core.entity.Entity;
8+
import net.minecraft.core.net.packet.Packet;
9+
import net.minecraft.core.net.packet.PacketAddEntity;
10+
import net.minecraft.core.net.packet.PacketSetRiding;
11+
import net.minecraft.server.entity.player.PlayerServer;
12+
import net.minecraft.server.net.PlayerList;
13+
import org.spongepowered.asm.mixin.Mixin;
14+
import org.spongepowered.asm.mixin.Shadow;
15+
import teamport.aether.entity.animal.aerbunny.MobAerbunny;
16+
import teamport.aether.world.AetherDimension;
17+
18+
@Environment(EnvType.SERVER)
19+
@Mixin(value = PlayerList.class)
20+
public abstract class WorldBunnyMixin {
21+
22+
@Shadow
23+
public abstract void sendPacketToPlayersAroundPoint(double x, double y, double z, double radius, int dimension, Packet packet);
24+
25+
@Shadow
26+
public abstract void sendPacketToAllPlayers(Packet packet);
27+
28+
@WrapMethod(method = "playerLoggedIn")
29+
public void spawnBunny(PlayerServer player, Operation<Void> original) {
30+
original.call(player);
31+
MobAerbunny mobAerbunny = AetherDimension.popBunnyFromPlayer(player.uuid, player.world);
32+
33+
if (mobAerbunny == null) return;
34+
35+
PacketAddEntity addBunny = new PacketAddEntity(mobAerbunny);
36+
sendPacketToAllPlayers(addBunny);
37+
mobAerbunny.startRiding(player);
38+
player.positionRider();
39+
40+
sendPacketToAllPlayers(new PacketSetRiding(mobAerbunny, player));
41+
}
42+
43+
@WrapMethod(method = "playerLoggedOut")
44+
public void removeBunny(PlayerServer player, Operation<Void> original) {
45+
if (player.passenger instanceof MobAerbunny) {
46+
AetherDimension.addBunnyToPlayer(player.uuid, (MobAerbunny) player.passenger);
47+
}
48+
original.call(player);
49+
}
50+
51+
}

src/main/java/teamport/aether/world/AetherDimension.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import teamport.aether.block.AetherBlocks;
1515
import teamport.aether.compat.AetherPlugin;
1616
import teamport.aether.entity.AetherMobFallingToOverworld;
17+
import teamport.aether.entity.animal.aerbunny.MobAerbunny;
1718
import teamport.aether.helper.unboxed.IntPair;
1819
import teamport.aether.net.message.SunspiritDeathNetworkMessage;
1920
import teamport.aether.world.biome.AetherBiomes;
@@ -27,7 +28,7 @@
2728

2829
public class AetherDimension {
2930

30-
private static final int SCHEMA_VERSION = 2;
31+
private static final int SCHEMA_VERSION = 3;
3132

3233
public static final int OVERWORLD_RETURN_HEIGHT = 270;
3334
public static final int DUNGEON_GENERATION_RADIUS = 16;
@@ -38,6 +39,8 @@ public class AetherDimension {
3839
private static final HashMap<Integer, List<Integer>> DIMENSION_PLACEMENT_BLACKLIST = new HashMap<>();
3940

4041
private static final HashMap<UUID, Boolean> HAS_RECEIVED_PARACHUTE_MAP = new HashMap<>();
42+
private static final HashMap<UUID, CompoundTag> HAS_BUNNY_MAP = new HashMap<>();
43+
4144

4245
public static List<Integer> getDimensionBlacklist(Dimension dimension) {
4346
return getDimensionBlacklist(dimension.id);
@@ -132,6 +135,21 @@ public static void unlockDaylightCycle(World world) {
132135
}
133136
}
134137

138+
public static MobAerbunny popBunnyFromPlayer(UUID uuidPlayer, World world) {
139+
CompoundTag tag = HAS_BUNNY_MAP.remove(uuidPlayer);
140+
if (tag == null) return null;
141+
MobAerbunny mobAerbunny = (MobAerbunny) EntityDispatcher.createEntityFromNBT(tag, world);
142+
world.entityJoinedWorld(mobAerbunny);
143+
return mobAerbunny;
144+
}
145+
146+
public static void addBunnyToPlayer(UUID uuidPlayer, MobAerbunny mobAerbunny) {
147+
CompoundTag tag = new CompoundTag();
148+
mobAerbunny.save(tag);
149+
mobAerbunny.remove();
150+
HAS_BUNNY_MAP.put(uuidPlayer, tag);
151+
}
152+
135153
public static boolean canGetParachute(UUID uuid) {
136154
boolean result = !HAS_RECEIVED_PARACHUTE_MAP.computeIfAbsent(uuid, it -> false);
137155
return result;
@@ -235,6 +253,13 @@ public static void saveWorldData(CompoundTag aetherWorldData) {
235253
entitiesToMoveMap.addTag(entryCompound);
236254
}
237255

256+
CompoundTag bunnyMap = new CompoundTag();
257+
for (Map.Entry<UUID, CompoundTag> entry : HAS_BUNNY_MAP.entrySet()) {
258+
bunnyMap.put(entry.getKey().toString(), entry.getValue());
259+
}
260+
261+
aetherWorldData.putInt(AetherMod.MOD_ID + ".bunnyMap", SCHEMA_VERSION);
262+
238263
aetherWorldData.putInt(AetherMod.MOD_ID + ".__SCHEMA_VERSION__", SCHEMA_VERSION);
239264
aetherWorldData.put(AetherMod.MOD_ID + ".overworldFallen", entitiesToMoveMap);
240265
DungeonMap.save(aetherWorldData);
@@ -253,6 +278,10 @@ public static void loadWorldData(CompoundTag aetherWorldData) {
253278
HAS_RECEIVED_PARACHUTE_MAP.clear();
254279
CompoundTag canReceiveParachuteCompound = aetherWorldData.getCompound(AetherMod.MOD_ID + ".canReceiveParachute");
255280
canReceiveParachuteCompound.getValues().forEach(it -> HAS_RECEIVED_PARACHUTE_MAP.put(UUID.fromString(it.getTagName()), ((Byte) it.getValue()) > 0));
281+
282+
HAS_BUNNY_MAP.clear();
283+
CompoundTag bunnyCompound = aetherWorldData.getCompound(AetherMod.MOD_ID + ".bunnyMap");
284+
bunnyCompound.getValues().forEach(it -> HAS_BUNNY_MAP.put(UUID.fromString(it.getTagName()), (CompoundTag) it));
256285
}
257286

258287
public static void loadDimensionData(CompoundTag dimensionData) {

src/main/resources/aether.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@
171171
"net.MinecraftServerMixinExcludeAether",
172172
"net.PlayerLoginMixin",
173173
"net.PlayerServerMixinExcludeAether",
174-
"player.PlayerServerAddDartsMixin"
174+
"player.PlayerServerAddDartsMixin",
175+
"player.WorldBunnyMixin"
175176
],
176177
"injectors": {
177178
"defaultRequire": 1

0 commit comments

Comments
 (0)