Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ public void tick() {
if (this.vehicle instanceof Player) {
Player player = (Player) vehicle;

if (!player.isAlive()) {
player.ejectRider();
}

if (!player.onGround && !player.noPhysics) {
if (!player.isInWater()) player.yd += 0.05F;
((EntityAccessor) player).setFallDistance(0.0F);
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/teamport/aether/mixin/player/WorldBunnyMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package teamport.aether.mixin.player;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.net.packet.Packet;
import net.minecraft.core.net.packet.PacketAddEntity;
import net.minecraft.core.net.packet.PacketSetRiding;
import net.minecraft.server.entity.player.PlayerServer;
import net.minecraft.server.net.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import teamport.aether.entity.animal.aerbunny.MobAerbunny;
import teamport.aether.world.AetherDimension;

@Environment(EnvType.SERVER)
@Mixin(value = PlayerList.class)
public abstract class WorldBunnyMixin {

@Shadow
public abstract void sendPacketToPlayersAroundPoint(double x, double y, double z, double radius, int dimension, Packet packet);

@Shadow
public abstract void sendPacketToAllPlayers(Packet packet);

@WrapMethod(method = "playerLoggedIn")
public void spawnBunny(PlayerServer player, Operation<Void> original) {
original.call(player);
MobAerbunny mobAerbunny = AetherDimension.popBunnyFromPlayer(player.uuid, player.world);

if (mobAerbunny == null) return;

PacketAddEntity addBunny = new PacketAddEntity(mobAerbunny);
sendPacketToAllPlayers(addBunny);
mobAerbunny.startRiding(player);
player.positionRider();

sendPacketToAllPlayers(new PacketSetRiding(mobAerbunny, player));
}

@WrapMethod(method = "playerLoggedOut")
public void removeBunny(PlayerServer player, Operation<Void> original) {
if (player.passenger instanceof MobAerbunny) {
AetherDimension.addBunnyToPlayer(player.uuid, (MobAerbunny) player.passenger);
}
original.call(player);
}

}
31 changes: 30 additions & 1 deletion src/main/java/teamport/aether/world/AetherDimension.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import teamport.aether.block.AetherBlocks;
import teamport.aether.compat.AetherPlugin;
import teamport.aether.entity.AetherMobFallingToOverworld;
import teamport.aether.entity.animal.aerbunny.MobAerbunny;
import teamport.aether.helper.unboxed.IntPair;
import teamport.aether.net.message.SunspiritDeathNetworkMessage;
import teamport.aether.world.biome.AetherBiomes;
Expand All @@ -27,7 +28,7 @@

public class AetherDimension {

private static final int SCHEMA_VERSION = 2;
private static final int SCHEMA_VERSION = 3;

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

private static final HashMap<UUID, Boolean> HAS_RECEIVED_PARACHUTE_MAP = new HashMap<>();
private static final HashMap<UUID, CompoundTag> HAS_BUNNY_MAP = new HashMap<>();


public static List<Integer> getDimensionBlacklist(Dimension dimension) {
return getDimensionBlacklist(dimension.id);
Expand Down Expand Up @@ -132,6 +135,21 @@ public static void unlockDaylightCycle(World world) {
}
}

public static MobAerbunny popBunnyFromPlayer(UUID uuidPlayer, World world) {
CompoundTag tag = HAS_BUNNY_MAP.remove(uuidPlayer);
if (tag == null) return null;
MobAerbunny mobAerbunny = (MobAerbunny) EntityDispatcher.createEntityFromNBT(tag, world);
world.entityJoinedWorld(mobAerbunny);
return mobAerbunny;
}

public static void addBunnyToPlayer(UUID uuidPlayer, MobAerbunny mobAerbunny) {
CompoundTag tag = new CompoundTag();
mobAerbunny.save(tag);
mobAerbunny.remove();
HAS_BUNNY_MAP.put(uuidPlayer, tag);
}

public static boolean canGetParachute(UUID uuid) {
boolean result = !HAS_RECEIVED_PARACHUTE_MAP.computeIfAbsent(uuid, it -> false);
return result;
Expand Down Expand Up @@ -235,6 +253,13 @@ public static void saveWorldData(CompoundTag aetherWorldData) {
entitiesToMoveMap.addTag(entryCompound);
}

CompoundTag bunnyMap = new CompoundTag();
for (Map.Entry<UUID, CompoundTag> entry : HAS_BUNNY_MAP.entrySet()) {
bunnyMap.put(entry.getKey().toString(), entry.getValue());
}

aetherWorldData.putInt(AetherMod.MOD_ID + ".bunnyMap", SCHEMA_VERSION);

aetherWorldData.putInt(AetherMod.MOD_ID + ".__SCHEMA_VERSION__", SCHEMA_VERSION);
aetherWorldData.put(AetherMod.MOD_ID + ".overworldFallen", entitiesToMoveMap);
DungeonMap.save(aetherWorldData);
Expand All @@ -253,6 +278,10 @@ public static void loadWorldData(CompoundTag aetherWorldData) {
HAS_RECEIVED_PARACHUTE_MAP.clear();
CompoundTag canReceiveParachuteCompound = aetherWorldData.getCompound(AetherMod.MOD_ID + ".canReceiveParachute");
canReceiveParachuteCompound.getValues().forEach(it -> HAS_RECEIVED_PARACHUTE_MAP.put(UUID.fromString(it.getTagName()), ((Byte) it.getValue()) > 0));

HAS_BUNNY_MAP.clear();
CompoundTag bunnyCompound = aetherWorldData.getCompound(AetherMod.MOD_ID + ".bunnyMap");
bunnyCompound.getValues().forEach(it -> HAS_BUNNY_MAP.put(UUID.fromString(it.getTagName()), (CompoundTag) it));
}

public static void loadDimensionData(CompoundTag dimensionData) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/aether.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
"net.MinecraftServerMixinExcludeAether",
"net.PlayerLoginMixin",
"net.PlayerServerMixinExcludeAether",
"player.PlayerServerAddDartsMixin"
"player.PlayerServerAddDartsMixin",
"player.WorldBunnyMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"MartinSVK12",

"Slainlight",
"Telvarost"
"Telvarost",
"wyspr"
],
"contributors": [
"Tocinin",
Expand Down
Loading