Skip to content

Commit

Permalink
Partial updates to 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Oct 14, 2024
1 parent a6c9522 commit 215fa24
Show file tree
Hide file tree
Showing 31 changed files with 97 additions and 91 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.5
fabric_version=0.105.0+1.21.1
minecraft_version=1.21.2-pre3
yarn_mappings=1.21.2-pre3+build.4
loader_version=0.16.7
fabric_version=0.105.4+1.21.2

# Mod Properties
group=com.minelittlepony
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/minelittlepony/unicopia/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity;
import com.minelittlepony.unicopia.entity.mob.UEntities;

import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.TagKey;
Expand All @@ -34,7 +35,7 @@ static void runTests(World world) {

try {
for (var type : BoatEntity.Type.values()) {
var balloon = UEntities.AIR_BALLOON.create(world);
var balloon = UEntities.AIR_BALLOON.create(world, SpawnReason.SPAWN_ITEM_USE);
balloon.setBasketType(AirBalloonEntity.BasketType.of(type));
balloon.asItem();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/minelittlepony/unicopia/USounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface USounds {
SoundEvent ENTITY_PLAYER_EARTHPONY_DASH = ENTITY_RAVAGER_STEP;
SoundEvent ENTITY_PLAYER_CHANGELING_BUZZ = register("entity.player.changeling.buzz");
SoundEvent ENTITY_PLAYER_CHANGELING_TRANSFORM = register("entity.player.changeling.transform");
SoundEvent ENTITY_PLAYER_CHANGELING_FEED = ENTITY_GENERIC_DRINK;
RegistryEntry<SoundEvent> ENTITY_PLAYER_CHANGELING_FEED = ENTITY_GENERIC_DRINK;
SoundEvent ENTITY_PLAYER_CHANGELING_CLIMB = ENTITY_CHICKEN_STEP;
SoundEvent ENTITY_PLAYER_UNICORN_TELEPORT = register("entity.player.unicorn.teleport");
SoundEvent ENTITY_PLAYER_KIRIN_RAGE = ENTITY_POLAR_BEAR_WARNING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ default boolean isClient() {
}

default <T> RegistryEntry<T> entryFor(RegistryKey<T> key) {
return asWorld().getRegistryManager().get(key.getRegistryRef()).getEntry(key).orElseThrow();
return asWorld().getRegistryManager().getOrThrow(key.getRegistryRef()).getEntry(key.getValue()).orElseThrow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
maxWarmup = compound.getInt("maxWarmup");
maxCooldown = compound.getInt("maxCooldown");
triggered = compound.getBoolean("triggered");
activeAbility = Abilities.REGISTRY.getOrEmpty(Identifier.of(compound.getString("activeAbility")));
activeAbility = Abilities.REGISTRY.getOptionalValue(Identifier.of(compound.getString("activeAbility")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
import com.minelittlepony.unicopia.entity.player.Pony;

import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.event.GameEvent;

Expand Down Expand Up @@ -38,8 +39,8 @@ protected void playSounds(Pony player, Random rng, float strength) {
}
}

if (strength > 0.5F && rng.nextInt(SELF_SPOOK_PROBABILITY) == 0) {
player.asEntity().damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), 0.1F);
if (player.asWorld() instanceof ServerWorld sw && strength > 0.5F && rng.nextInt(SELF_SPOOK_PROBABILITY) == 0) {
player.asEntity().damage(sw, player.damageOf(UDamageTypes.BAT_SCREECH, player), 0.1F);
UCriteria.SCREECH_SELF.trigger(player.asEntity());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public boolean apply(Pony iplayer, Hit data) {
if (targets.size() > 0) {
new ChangelingFeedingSpell(targets, maximumHealthGain, maximumFoodGain).apply(iplayer);

iplayer.playSound(USounds.ENTITY_PLAYER_CHANGELING_FEED, 0.1F, iplayer.getRandomPitch());
iplayer.playSound(USounds.ENTITY_PLAYER_CHANGELING_FEED.value(), 0.1F, iplayer.getRandomPitch());
return true;
}
}

iplayer.playSound(USounds.Vanilla.ENTITY_PLAYER_BURP, 1, (float)player.getWorld().random.nextTriangular(1F, 0.2F));
iplayer.playSound(USounds.Vanilla.ENTITY_PLAYER_BURP, 1, player.getWorld().random.nextTriangular(1F, 0.2F));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Optional;
import java.util.function.DoubleSupplier;
import java.util.function.Supplier;
import java.util.stream.StreamSupport;

import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.ability.data.Pos;
Expand All @@ -28,6 +30,8 @@
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
Expand Down Expand Up @@ -132,10 +136,13 @@ protected int applySingle(Pony player, World w, BlockState state, BlockPos pos)
return 0;
}

@SuppressWarnings("unchecked")
private boolean applyDirectly(Pony player, BlockPos pos) {
return player.asWorld().getRecipeManager()
.getAllMatches(URecipes.GROWING, new TransformCropsRecipe.PlacementArea(player, pos), player.asWorld())
.stream()
var placementArea = new TransformCropsRecipe.PlacementArea(player, pos);
return StreamSupport.stream(((ServerWorld)player.asWorld()).getRecipeManager().values().spliterator(), false)
.filter(recipe -> recipe.value().getType() == URecipes.GROWING)
.map(recipe -> (RecipeEntry<TransformCropsRecipe>)recipe)
.filter(recipe -> recipe.value().matches(placementArea, player.asWorld()))
.map(recipe -> recipe.value().checkPattern(player.asWorld(), pos))
.filter(result -> result.matchedLocations().size() + 1 >= TransformCropsRecipe.MINIMUM_INPUT)
.filter(result -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public boolean onQuickAction(Pony player, ActivationType type, Optional<Pos> dat
if (e instanceof LivingEntity entity) {
float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9));

entity.damage(player.damageOf(UDamageTypes.KICK, player), player.asWorld().random.nextBetween(2, 10) + calculatedStrength);
if (player.asWorld() instanceof ServerWorld sw) {
entity.damage(sw, player.damageOf(UDamageTypes.KICK, player), player.asWorld().random.nextBetween(2, 10) + calculatedStrength);
}
entity.takeKnockback(calculatedStrength, origin.x - entity.getX(), origin.z - entity.getZ());
Living.updateVelocity(entity);
player.subtractEnergyCost(3);
Expand All @@ -109,7 +111,7 @@ public boolean onQuickAction(Pony player, ActivationType type, Optional<Pos> dat
}

if (type == ActivationType.DOUBLE_TAP && player.asEntity().isOnGround() && player.getMagicalReserves().getMana().get() > 40) {
player.getPhysics().dashForward((float)player.asWorld().random.nextTriangular(3.5F, 0.3F));
player.getPhysics().dashForward(player.asWorld().random.nextTriangular(3.5F, 0.3F));
player.subtractEnergyCost(4);
player.asEntity().addExhaustion(5);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public double getCostEstimate(Pony player) {
public Optional<Hit> prepare(Pony player) {
if (player.asEntity().getVelocity().y * player.getPhysics().getGravitySignum() < 0
&& !player.asEntity().getAbilities().flying
&& !player.asEntity().isFallFlying()
&& !player.asEntity().isGliding()
&& !player.asEntity().isUsingRiptide()) {
thrustDownwards(player);
return Hit.INSTANCE;
Expand Down Expand Up @@ -144,7 +144,7 @@ public float dispatch(float fallDistance) {
-(player.getY() - i.getY() - liftAmount) / inertia + (dist < 1 ? dist : 0),
-(player.getZ() - i.getZ()) / inertia);

double amount = (1.5F * player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).getValue() + heavyness * 0.4) / (float)(dist * 1.3F);
double amount = (1.5F * player.getAttributeInstance(EntityAttributes.ATTACK_DAMAGE).getValue() + heavyness * 0.4) / (float)(dist * 1.3F);

if (i instanceof PlayerEntity) {
Race.Composite race = Pony.of((PlayerEntity)i).getCompositeRace();
Expand All @@ -161,7 +161,7 @@ public float dispatch(float fallDistance) {
amount /= EnchantmentUtil.getImpactReduction(l);
}

i.damage(iplayer.damageOf(UDamageTypes.SMASH, iplayer), (float)amount);
i.damage((ServerWorld)iplayer.asWorld(), iplayer.damageOf(UDamageTypes.SMASH, iplayer), (float)amount);
Living.updateVelocity(i);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.minelittlepony.unicopia.entity.mob.UEntities;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.conversion.EntityConversionContext;
import net.minecraft.entity.mob.CreeperEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
Expand All @@ -25,11 +26,13 @@ public boolean apply(Pony pony, Hit data) {
pony.setAnimation(Animation.ARMS_FORWARD, Animation.Recipient.ANYONE);

if (rider instanceof CreeperEntity creeper) {
FriendlyCreeperEntity friendlyCreeper = creeper.convertTo(UEntities.FRIENDLY_CREEPER, true);
player.getWorld().spawnEntity(friendlyCreeper);

friendlyCreeper.startRiding(player, true);
Living.getOrEmpty(friendlyCreeper).ifPresent(living -> living.setCarrier(player));
FriendlyCreeperEntity friendlyCreeper = creeper.convertTo(UEntities.FRIENDLY_CREEPER, EntityConversionContext.create(creeper, true, true), e -> {
e.startRiding(player, true);
Living.getOrEmpty(e).ifPresent(living -> living.setCarrier(player));
});
if (friendlyCreeper != null) {
player.getWorld().spawnEntity(friendlyCreeper);
}
} else if (rider instanceof FriendlyCreeperEntity creeper) {
creeper.startRiding(player, true);
Living.getOrEmpty(creeper).ifPresent(living -> living.setCarrier(player));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ protected void spookMob(Pony player, LivingEntity living, float strength) {
boolean isEarthPony = EquinePredicates.PLAYER_EARTH.test(living);
boolean isBracing = isEarthPony && player.asEntity().isSneaking();

if (!isBracing) {
living.damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F);
if (!isBracing && living.getWorld() instanceof ServerWorld sw) {
living.damage(sw, player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F);
}

Vec3d knockVec = player.getOriginVector().subtract(living.getPos()).multiply(strength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;
Expand Down Expand Up @@ -103,12 +104,12 @@ protected void spookMob(Pony player, LivingEntity living, float strength) {
boolean isBracing = isEarthPony && player.asEntity().isSneaking();

if (!isBracing) {
living.damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F);
living.damage((ServerWorld)player.asWorld(), player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F);


if (living.getWorld().random.nextInt(MOB_SPOOK_PROBABILITY) == 0) {
RegistryUtils.pickRandom(living.getWorld(), UTags.Items.SPOOKED_MOB_DROPS).ifPresent(drop -> {
living.dropStack(drop.getDefaultStack());
living.dropStack((ServerWorld)living.getWorld(), drop.getDefaultStack());
living.playSound(USounds.Vanilla.ENTITY_ITEM_PICKUP, 1, 0.1F);
UCriteria.SPOOK_MOB.trigger(player.asEntity());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean apply(Pony player, Hit data) {
if (distance < 4) {
float scale = 1 - (distance/10F);
((LivingEntity)target).takeKnockback(0.7 * scale, -offset.x, -offset.z);
target.damage(target.getDamageSources().sonicBoom(player.asEntity()), 10 * scale);
target.damage((ServerWorld)target.getWorld(), target.getDamageSources().sonicBoom(player.asEntity()), 10 * scale);
} else {
emitPing(player, target.getPos(), 10, 1, 1.3F);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import java.util.*;
import java.util.function.Supplier;
import com.google.gson.JsonElement;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.util.Resources;
import com.minelittlepony.unicopia.util.Weighted;
import com.minelittlepony.unicopia.util.serialization.CodecUtils;
import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
Expand All @@ -23,18 +19,17 @@
import net.minecraft.util.profiler.Profiler;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.TagKey;

public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResourceReloadListener {
public class TreeTypeLoader extends JsonDataLoader<TreeTypeLoader.TreeTypeDef> implements IdentifiableResourceReloadListener {
private static final Identifier ID = Unicopia.id("data/tree_type");

public static final TreeTypeLoader INSTANCE = new TreeTypeLoader();

private Map<Identifier, TreeTypeDef> entries = new HashMap<>();

TreeTypeLoader() {
super(Resources.GSON, "tree_types");
super(TreeTypeDef.CODEC, "tree_types");
}

public Map<Identifier, TreeTypeDef> getEntries() {
Expand All @@ -46,18 +41,9 @@ public Identifier getFabricId() {
return ID;
}

@SuppressWarnings("unchecked")
@Override
protected void apply(Map<Identifier, JsonElement> resources, ResourceManager manager, Profiler profiler) {
entries = Map.ofEntries(resources.entrySet().stream()
.filter(Objects::nonNull)
.map(entry -> TreeTypeDef.CODEC.decode(JsonOps.INSTANCE, entry.getValue())
.result()
.map(p -> p.getFirst())
.map(p -> Map.entry(entry.getKey(), p))
.orElse(null))
.filter(Objects::nonNull)
.toArray(Map.Entry[]::new));
protected void apply(Map<Identifier, TreeTypeDef> resources, ResourceManager manager, Profiler profiler) {
entries = resources;

TreeTypes.load(entries);
}
Expand Down Expand Up @@ -120,15 +106,13 @@ static record Drop (
@Override
public void appendTo(Weighted.Builder<Supplier<ItemStack>> weighted) {
if (item.isPresent()) {
Registries.ITEM.getOrEmpty(item.get()).ifPresent(item -> {
Registries.ITEM.getOptionalValue(item.get()).ifPresent(item -> {
weighted.put(weight, item::getDefaultStack);
});
} else {
weighted.put(weight, () -> {
return Registries.ITEM.getOrCreateEntryList(TagKey.of(RegistryKeys.ITEM, tag.get()))
.getRandom(Weighted.getRng())
.map(RegistryEntry::value)
.map(Item::getDefaultStack)
return Registries.ITEM.getRandomEntry(TagKey.of(RegistryKeys.ITEM, tag.get()), Weighted.getRng())
.map(entry -> entry.value().getDefaultStack())
.orElse(ItemStack.EMPTY);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ abstract class MixinLivingEntityRenderer<T extends LivingEntity, M extends Entit
@Shadow
private @Final List<FeatureRenderer<T, M>> features;

MixinLivingEntityRenderer() { super(null); }
@Nullable
private AccessoryFeatureRenderer<T, M> accessories;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void onCopyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInf
target = "net/minecraft/entity/player/PlayerEntity$SleepFailureReason.NOT_POSSIBLE_NOW:Lnet/minecraft/entity/player/PlayerEntity$SleepFailureReason;"
), cancellable = true)
private void onTrySleep(BlockPos pos, CallbackInfoReturnable<Either<PlayerEntity.SleepFailureReason, Unit>> info) {
if (get().getSpecies().isNocturnal() && get().asWorld().getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES)) {
if (get().getSpecies().isNocturnal() && ((ServerWorld)get().asWorld()).getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES)) {
((PlayerEntity)this).sendMessage(Text.translatable("block.unicopia.bed.no_sleep.nocturnal"), true);

info.setReturnValue(Either.left(PlayerEntity.SleepFailureReason.OTHER_PROBLEM));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void handle(ServerPlayerEntity sender) {
}

if (force) {
if (sender.getWorld().getGameRules().getBoolean(UGameRules.ANNOUNCE_TRIBE_JOINS)) {
if (((ServerWorld)sender.getWorld()).getGameRules().getBoolean(UGameRules.ANNOUNCE_TRIBE_JOINS)) {
Text message = Text.translatable("respawn.reason.joined_new_tribe",
sender.getDisplayName(),
player.getSpecies().getDisplayName(), player.getSpecies().getAltDisplayName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public record MagicParticleEffect (
).apply(instance, MagicParticleEffect::new));
public static final PacketCodec<ByteBuf, MagicParticleEffect> PACKET_CODEC = PacketCodec.tuple(
PacketCodecs.BOOL, MagicParticleEffect::tinted,
PacketCodecs.VECTOR3F, MagicParticleEffect::color,
PacketCodecs.VECTOR_3F, MagicParticleEffect::color,
MagicParticleEffect::new
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static MapCodec<SphereParticleEffect> createCodec(ParticleType<SpherePart

public static final PacketCodec<RegistryByteBuf, SphereParticleEffect> createPacketCodec(ParticleType<SphereParticleEffect> type) {
return PacketCodec.tuple(
PacketCodecs.VECTOR3F, SphereParticleEffect::color,
PacketCodecs.VECTOR_3F, SphereParticleEffect::color,
PacketCodecs.FLOAT, SphereParticleEffect::alpha,
PacketCodecs.FLOAT, SphereParticleEffect::radius,
PacketCodecUtils.VECTOR, SphereParticleEffect::offset,
Expand Down
Loading

0 comments on commit 215fa24

Please sign in to comment.