mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Partial updates to 1.21.2
This commit is contained in:
parent
7e0272bd7f
commit
57ac3e4fee
31 changed files with 99 additions and 93 deletions
|
@ -3,10 +3,10 @@ org.gradle.daemon=false
|
||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/develop
|
# check these on https://fabricmc.net/develop
|
||||||
minecraft_version=1.21.1
|
minecraft_version=1.21.2-pre3
|
||||||
yarn_mappings=1.21.1+build.3
|
yarn_mappings=1.21.2-pre3+build.4
|
||||||
loader_version=0.16.4
|
loader_version=0.16.7
|
||||||
fabric_version=0.102.0+1.21.1
|
fabric_version=0.105.4+1.21.2
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
group=com.minelittlepony
|
group=com.minelittlepony
|
||||||
|
@ -21,9 +21,9 @@ org.gradle.daemon=false
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabwork_version=1.3.2+1.21
|
fabwork_version=1.3.2+1.21
|
||||||
modmenu_version=11.0.0-beta.1
|
modmenu_version=12.0.0-beta.1
|
||||||
minelp_version=4.12.0+1.21
|
minelp_version=4.12.0+1.21
|
||||||
kirin_version=1.20.0+1.21
|
kirin_version=1.20.0+1.21.3
|
||||||
trinkets_version=3.10.0
|
trinkets_version=3.10.0
|
||||||
terraformer_api_version=11.0.0-alpha.1
|
terraformer_api_version=11.0.0-alpha.1
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
|
||||||
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity;
|
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity;
|
||||||
import com.minelittlepony.unicopia.entity.mob.UEntities;
|
import com.minelittlepony.unicopia.entity.mob.UEntities;
|
||||||
|
|
||||||
|
import net.minecraft.entity.SpawnReason;
|
||||||
import net.minecraft.entity.vehicle.BoatEntity;
|
import net.minecraft.entity.vehicle.BoatEntity;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.tag.TagKey;
|
import net.minecraft.registry.tag.TagKey;
|
||||||
|
@ -34,7 +35,7 @@ public interface Debug {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (var type : BoatEntity.Type.values()) {
|
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.setBasketType(AirBalloonEntity.BasketType.of(type));
|
||||||
balloon.asItem();
|
balloon.asItem();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public interface USounds {
|
||||||
SoundEvent ENTITY_PLAYER_EARTHPONY_DASH = ENTITY_RAVAGER_STEP;
|
SoundEvent ENTITY_PLAYER_EARTHPONY_DASH = ENTITY_RAVAGER_STEP;
|
||||||
SoundEvent ENTITY_PLAYER_CHANGELING_BUZZ = register("entity.player.changeling.buzz");
|
SoundEvent ENTITY_PLAYER_CHANGELING_BUZZ = register("entity.player.changeling.buzz");
|
||||||
SoundEvent ENTITY_PLAYER_CHANGELING_TRANSFORM = register("entity.player.changeling.transform");
|
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_CHANGELING_CLIMB = ENTITY_CHICKEN_STEP;
|
||||||
SoundEvent ENTITY_PLAYER_UNICORN_TELEPORT = register("entity.player.unicorn.teleport");
|
SoundEvent ENTITY_PLAYER_UNICORN_TELEPORT = register("entity.player.unicorn.teleport");
|
||||||
SoundEvent ENTITY_PLAYER_KIRIN_RAGE = ENTITY_POLAR_BEAR_WARNING;
|
SoundEvent ENTITY_PLAYER_KIRIN_RAGE = ENTITY_POLAR_BEAR_WARNING;
|
||||||
|
|
|
@ -18,6 +18,6 @@ public interface WorldConvertable {
|
||||||
}
|
}
|
||||||
|
|
||||||
default <T> RegistryEntry<T> entryFor(RegistryKey<T> key) {
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,7 +302,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
|
||||||
maxWarmup = compound.getInt("maxWarmup");
|
maxWarmup = compound.getInt("maxWarmup");
|
||||||
maxCooldown = compound.getInt("maxCooldown");
|
maxCooldown = compound.getInt("maxCooldown");
|
||||||
triggered = compound.getBoolean("triggered");
|
triggered = compound.getBoolean("triggered");
|
||||||
activeAbility = Abilities.REGISTRY.getOrEmpty(Identifier.of(compound.getString("activeAbility")));
|
activeAbility = Abilities.REGISTRY.getOptionalValue(Identifier.of(compound.getString("activeAbility")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.advancement.UCriteria;
|
||||||
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
|
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
|
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.random.Random;
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.world.event.GameEvent;
|
import net.minecraft.world.event.GameEvent;
|
||||||
|
|
||||||
|
@ -38,8 +39,8 @@ public class BatEeeeAbility extends ScreechAbility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strength > 0.5F && rng.nextInt(SELF_SPOOK_PROBABILITY) == 0) {
|
if (player.asWorld() instanceof ServerWorld sw && strength > 0.5F && rng.nextInt(SELF_SPOOK_PROBABILITY) == 0) {
|
||||||
player.asEntity().damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), 0.1F);
|
player.asEntity().damage(sw, player.damageOf(UDamageTypes.BAT_SCREECH, player), 0.1F);
|
||||||
UCriteria.SCREECH_SELF.trigger(player.asEntity());
|
UCriteria.SCREECH_SELF.trigger(player.asEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,12 +82,12 @@ public class ChangelingFeedAbility implements Ability<Hit> {
|
||||||
if (targets.size() > 0) {
|
if (targets.size() > 0) {
|
||||||
new ChangelingFeedingSpell(targets, maximumHealthGain, maximumFoodGain).apply(iplayer);
|
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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.minelittlepony.unicopia.ability;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.DoubleSupplier;
|
import java.util.function.DoubleSupplier;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.USounds;
|
import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.UTags;
|
import com.minelittlepony.unicopia.UTags;
|
||||||
import com.minelittlepony.unicopia.ability.data.Pos;
|
import com.minelittlepony.unicopia.ability.data.Pos;
|
||||||
|
@ -28,6 +30,8 @@ import net.minecraft.item.Items;
|
||||||
import net.minecraft.network.RegistryByteBuf;
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
import net.minecraft.network.codec.PacketCodec;
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
@ -132,10 +136,13 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private boolean applyDirectly(Pony player, BlockPos pos) {
|
private boolean applyDirectly(Pony player, BlockPos pos) {
|
||||||
return player.asWorld().getRecipeManager()
|
var placementArea = new TransformCropsRecipe.PlacementArea(player, pos);
|
||||||
.getAllMatches(URecipes.GROWING, new TransformCropsRecipe.PlacementArea(player, pos), player.asWorld())
|
return StreamSupport.stream(((ServerWorld)player.asWorld()).getRecipeManager().values().spliterator(), false)
|
||||||
.stream()
|
.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))
|
.map(recipe -> recipe.value().checkPattern(player.asWorld(), pos))
|
||||||
.filter(result -> result.matchedLocations().size() + 1 >= TransformCropsRecipe.MINIMUM_INPUT)
|
.filter(result -> result.matchedLocations().size() + 1 >= TransformCropsRecipe.MINIMUM_INPUT)
|
||||||
.filter(result -> {
|
.filter(result -> {
|
||||||
|
|
|
@ -90,7 +90,9 @@ public class EarthPonyKickAbility implements Ability<Pos> {
|
||||||
if (e instanceof LivingEntity entity) {
|
if (e instanceof LivingEntity entity) {
|
||||||
float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9));
|
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());
|
entity.takeKnockback(calculatedStrength, origin.x - entity.getX(), origin.z - entity.getZ());
|
||||||
Living.updateVelocity(entity);
|
Living.updateVelocity(entity);
|
||||||
player.subtractEnergyCost(3);
|
player.subtractEnergyCost(3);
|
||||||
|
@ -109,7 +111,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == ActivationType.DOUBLE_TAP && player.asEntity().isOnGround() && player.getMagicalReserves().getMana().get() > 40) {
|
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.subtractEnergyCost(4);
|
||||||
player.asEntity().addExhaustion(5);
|
player.asEntity().addExhaustion(5);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
||||||
public Optional<Hit> prepare(Pony player) {
|
public Optional<Hit> prepare(Pony player) {
|
||||||
if (player.asEntity().getVelocity().y * player.getPhysics().getGravitySignum() < 0
|
if (player.asEntity().getVelocity().y * player.getPhysics().getGravitySignum() < 0
|
||||||
&& !player.asEntity().getAbilities().flying
|
&& !player.asEntity().getAbilities().flying
|
||||||
&& !player.asEntity().isFallFlying()
|
&& !player.asEntity().isGliding()
|
||||||
&& !player.asEntity().isUsingRiptide()) {
|
&& !player.asEntity().isUsingRiptide()) {
|
||||||
thrustDownwards(player);
|
thrustDownwards(player);
|
||||||
return Hit.INSTANCE;
|
return Hit.INSTANCE;
|
||||||
|
@ -144,7 +144,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
||||||
-(player.getY() - i.getY() - liftAmount) / inertia + (dist < 1 ? dist : 0),
|
-(player.getY() - i.getY() - liftAmount) / inertia + (dist < 1 ? dist : 0),
|
||||||
-(player.getZ() - i.getZ()) / inertia);
|
-(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) {
|
if (i instanceof PlayerEntity) {
|
||||||
Race.Composite race = Pony.of((PlayerEntity)i).getCompositeRace();
|
Race.Composite race = Pony.of((PlayerEntity)i).getCompositeRace();
|
||||||
|
@ -161,7 +161,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
||||||
amount /= EnchantmentUtil.getImpactReduction(l);
|
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);
|
Living.updateVelocity(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.entity.mob.FriendlyCreeperEntity;
|
||||||
import com.minelittlepony.unicopia.entity.mob.UEntities;
|
import com.minelittlepony.unicopia.entity.mob.UEntities;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.entity.conversion.EntityConversionContext;
|
||||||
import net.minecraft.entity.mob.CreeperEntity;
|
import net.minecraft.entity.mob.CreeperEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
|
@ -25,11 +26,13 @@ public class HugAbility extends CarryAbility {
|
||||||
pony.setAnimation(Animation.ARMS_FORWARD, Animation.Recipient.ANYONE);
|
pony.setAnimation(Animation.ARMS_FORWARD, Animation.Recipient.ANYONE);
|
||||||
|
|
||||||
if (rider instanceof CreeperEntity creeper) {
|
if (rider instanceof CreeperEntity creeper) {
|
||||||
FriendlyCreeperEntity friendlyCreeper = creeper.convertTo(UEntities.FRIENDLY_CREEPER, true);
|
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);
|
player.getWorld().spawnEntity(friendlyCreeper);
|
||||||
|
}
|
||||||
friendlyCreeper.startRiding(player, true);
|
|
||||||
Living.getOrEmpty(friendlyCreeper).ifPresent(living -> living.setCarrier(player));
|
|
||||||
} else if (rider instanceof FriendlyCreeperEntity creeper) {
|
} else if (rider instanceof FriendlyCreeperEntity creeper) {
|
||||||
creeper.startRiding(player, true);
|
creeper.startRiding(player, true);
|
||||||
Living.getOrEmpty(creeper).ifPresent(living -> living.setCarrier(player));
|
Living.getOrEmpty(creeper).ifPresent(living -> living.setCarrier(player));
|
||||||
|
|
|
@ -125,8 +125,8 @@ public class PeckAbility implements Ability<Hit> {
|
||||||
boolean isEarthPony = EquinePredicates.PLAYER_EARTH.test(living);
|
boolean isEarthPony = EquinePredicates.PLAYER_EARTH.test(living);
|
||||||
boolean isBracing = isEarthPony && player.asEntity().isSneaking();
|
boolean isBracing = isEarthPony && player.asEntity().isSneaking();
|
||||||
|
|
||||||
if (!isBracing) {
|
if (!isBracing && living.getWorld() instanceof ServerWorld sw) {
|
||||||
living.damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F);
|
living.damage(sw, player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3d knockVec = player.getOriginVector().subtract(living.getPos()).multiply(strength);
|
Vec3d knockVec = player.getOriginVector().subtract(living.getPos()).multiply(strength);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.network.RegistryByteBuf;
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
import net.minecraft.network.codec.PacketCodec;
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.math.random.Random;
|
import net.minecraft.util.math.random.Random;
|
||||||
|
@ -103,12 +104,12 @@ public class ScreechAbility implements Ability<Numeric> {
|
||||||
boolean isBracing = isEarthPony && player.asEntity().isSneaking();
|
boolean isBracing = isEarthPony && player.asEntity().isSneaking();
|
||||||
|
|
||||||
if (!isBracing) {
|
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) {
|
if (living.getWorld().random.nextInt(MOB_SPOOK_PROBABILITY) == 0) {
|
||||||
RegistryUtils.pickRandom(living.getWorld(), UTags.Items.SPOOKED_MOB_DROPS).ifPresent(drop -> {
|
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);
|
living.playSound(USounds.Vanilla.ENTITY_ITEM_PICKUP, 1, 0.1F);
|
||||||
UCriteria.SPOOK_MOB.trigger(player.asEntity());
|
UCriteria.SPOOK_MOB.trigger(player.asEntity());
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class SeaponySonarPulseAbility implements Ability<Hit> {
|
||||||
if (distance < 4) {
|
if (distance < 4) {
|
||||||
float scale = 1 - (distance/10F);
|
float scale = 1 - (distance/10F);
|
||||||
((LivingEntity)target).takeKnockback(0.7 * scale, -offset.x, -offset.z);
|
((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 {
|
} else {
|
||||||
emitPing(player, target.getPos(), 10, 1, 1.3F);
|
emitPing(player, target.getPos(), 10, 1, 1.3F);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,13 @@ package com.minelittlepony.unicopia.ability.data.tree;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
import com.minelittlepony.unicopia.util.Resources;
|
|
||||||
import com.minelittlepony.unicopia.util.Weighted;
|
import com.minelittlepony.unicopia.util.Weighted;
|
||||||
import com.minelittlepony.unicopia.util.serialization.CodecUtils;
|
import com.minelittlepony.unicopia.util.serialization.CodecUtils;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.JsonOps;
|
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.network.RegistryByteBuf;
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
import net.minecraft.network.codec.PacketCodec;
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
@ -23,10 +19,9 @@ import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.profiler.Profiler;
|
import net.minecraft.util.profiler.Profiler;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.registry.entry.RegistryEntry;
|
|
||||||
import net.minecraft.registry.tag.TagKey;
|
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");
|
private static final Identifier ID = Unicopia.id("data/tree_type");
|
||||||
|
|
||||||
public static final TreeTypeLoader INSTANCE = new TreeTypeLoader();
|
public static final TreeTypeLoader INSTANCE = new TreeTypeLoader();
|
||||||
|
@ -34,7 +29,7 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour
|
||||||
private Map<Identifier, TreeTypeDef> entries = new HashMap<>();
|
private Map<Identifier, TreeTypeDef> entries = new HashMap<>();
|
||||||
|
|
||||||
TreeTypeLoader() {
|
TreeTypeLoader() {
|
||||||
super(Resources.GSON, "tree_types");
|
super(TreeTypeDef.CODEC, "tree_types");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Identifier, TreeTypeDef> getEntries() {
|
public Map<Identifier, TreeTypeDef> getEntries() {
|
||||||
|
@ -46,18 +41,9 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected void apply(Map<Identifier, JsonElement> resources, ResourceManager manager, Profiler profiler) {
|
protected void apply(Map<Identifier, TreeTypeDef> resources, ResourceManager manager, Profiler profiler) {
|
||||||
entries = Map.ofEntries(resources.entrySet().stream()
|
entries = resources;
|
||||||
.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));
|
|
||||||
|
|
||||||
TreeTypes.load(entries);
|
TreeTypes.load(entries);
|
||||||
}
|
}
|
||||||
|
@ -120,15 +106,13 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour
|
||||||
@Override
|
@Override
|
||||||
public void appendTo(Weighted.Builder<Supplier<ItemStack>> weighted) {
|
public void appendTo(Weighted.Builder<Supplier<ItemStack>> weighted) {
|
||||||
if (item.isPresent()) {
|
if (item.isPresent()) {
|
||||||
Registries.ITEM.getOrEmpty(item.get()).ifPresent(item -> {
|
Registries.ITEM.getOptionalValue(item.get()).ifPresent(item -> {
|
||||||
weighted.put(weight, item::getDefaultStack);
|
weighted.put(weight, item::getDefaultStack);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
weighted.put(weight, () -> {
|
weighted.put(weight, () -> {
|
||||||
return Registries.ITEM.getOrCreateEntryList(TagKey.of(RegistryKeys.ITEM, tag.get()))
|
return Registries.ITEM.getRandomEntry(TagKey.of(RegistryKeys.ITEM, tag.get()), Weighted.getRng())
|
||||||
.getRandom(Weighted.getRng())
|
.map(entry -> entry.value().getDefaultStack())
|
||||||
.map(RegistryEntry::value)
|
|
||||||
.map(Item::getDefaultStack)
|
|
||||||
.orElse(ItemStack.EMPTY);
|
.orElse(ItemStack.EMPTY);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ abstract class MixinLivingEntityRenderer<T extends LivingEntity, M extends Entit
|
||||||
@Shadow
|
@Shadow
|
||||||
private @Final List<FeatureRenderer<T, M>> features;
|
private @Final List<FeatureRenderer<T, M>> features;
|
||||||
|
|
||||||
MixinLivingEntityRenderer() { super(null); }
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private AccessoryFeatureRenderer<T, M> accessories;
|
private AccessoryFeatureRenderer<T, M> accessories;
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHan
|
||||||
target = "net/minecraft/entity/player/PlayerEntity$SleepFailureReason.NOT_POSSIBLE_NOW:Lnet/minecraft/entity/player/PlayerEntity$SleepFailureReason;"
|
target = "net/minecraft/entity/player/PlayerEntity$SleepFailureReason.NOT_POSSIBLE_NOW:Lnet/minecraft/entity/player/PlayerEntity$SleepFailureReason;"
|
||||||
), cancellable = true, require = 0)
|
), cancellable = true, require = 0)
|
||||||
private void onTrySleep(BlockPos pos, CallbackInfoReturnable<Either<PlayerEntity.SleepFailureReason, Unit>> info) {
|
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);
|
((PlayerEntity)this).sendMessage(Text.translatable("block.unicopia.bed.no_sleep.nocturnal"), true);
|
||||||
|
|
||||||
info.setReturnValue(Either.left(PlayerEntity.SleepFailureReason.OTHER_PROBLEM));
|
info.setReturnValue(Either.left(PlayerEntity.SleepFailureReason.OTHER_PROBLEM));
|
||||||
|
|
|
@ -39,7 +39,7 @@ public record MsgRequestSpeciesChange (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force) {
|
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",
|
Text message = Text.translatable("respawn.reason.joined_new_tribe",
|
||||||
sender.getDisplayName(),
|
sender.getDisplayName(),
|
||||||
player.getSpecies().getDisplayName(), player.getSpecies().getAltDisplayName());
|
player.getSpecies().getDisplayName(), player.getSpecies().getAltDisplayName());
|
||||||
|
|
|
@ -26,7 +26,7 @@ public record MagicParticleEffect (
|
||||||
).apply(instance, MagicParticleEffect::new));
|
).apply(instance, MagicParticleEffect::new));
|
||||||
public static final PacketCodec<ByteBuf, MagicParticleEffect> PACKET_CODEC = PacketCodec.tuple(
|
public static final PacketCodec<ByteBuf, MagicParticleEffect> PACKET_CODEC = PacketCodec.tuple(
|
||||||
PacketCodecs.BOOL, MagicParticleEffect::tinted,
|
PacketCodecs.BOOL, MagicParticleEffect::tinted,
|
||||||
PacketCodecs.VECTOR3F, MagicParticleEffect::color,
|
PacketCodecs.VECTOR_3F, MagicParticleEffect::color,
|
||||||
MagicParticleEffect::new
|
MagicParticleEffect::new
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public record SphereParticleEffect (
|
||||||
|
|
||||||
public static final PacketCodec<RegistryByteBuf, SphereParticleEffect> createPacketCodec(ParticleType<SphereParticleEffect> type) {
|
public static final PacketCodec<RegistryByteBuf, SphereParticleEffect> createPacketCodec(ParticleType<SphereParticleEffect> type) {
|
||||||
return PacketCodec.tuple(
|
return PacketCodec.tuple(
|
||||||
PacketCodecs.VECTOR3F, SphereParticleEffect::color,
|
PacketCodecs.VECTOR_3F, SphereParticleEffect::color,
|
||||||
PacketCodecs.FLOAT, SphereParticleEffect::alpha,
|
PacketCodecs.FLOAT, SphereParticleEffect::alpha,
|
||||||
PacketCodecs.FLOAT, SphereParticleEffect::radius,
|
PacketCodecs.FLOAT, SphereParticleEffect::radius,
|
||||||
PacketCodecUtils.VECTOR, SphereParticleEffect::offset,
|
PacketCodecUtils.VECTOR, SphereParticleEffect::offset,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.recipe;
|
package com.minelittlepony.unicopia.recipe;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.block.UBlocks;
|
import com.minelittlepony.unicopia.block.UBlocks;
|
||||||
|
import com.minelittlepony.unicopia.util.Untyped;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.recipe.Ingredient;
|
import net.minecraft.recipe.Ingredient;
|
||||||
|
@ -19,13 +20,13 @@ public class CloudShapingRecipe extends StonecuttingRecipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeType<?> getType() {
|
public RecipeType<StonecuttingRecipe> getType() {
|
||||||
return URecipes.CLOUD_SHAPING;
|
return Untyped.cast(URecipes.CLOUD_SHAPING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeSerializer<?> getSerializer() {
|
public RecipeSerializer<StonecuttingRecipe> getSerializer() {
|
||||||
return URecipes.CLOUD_SHAPING_SERIALIZER;
|
return Untyped.cast(URecipes.CLOUD_SHAPING_SERIALIZER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class GlowingRecipe extends ItemCombinationRecipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeSerializer<?> getSerializer() {
|
public RecipeSerializer<? extends GlowingRecipe> getSerializer() {
|
||||||
return URecipes.GLOWING_SERIALIZER;
|
return URecipes.GLOWING_SERIALIZER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class JarExtractRecipe extends SpecialCraftingRecipe {
|
||||||
@Override
|
@Override
|
||||||
public ItemStack craft(CraftingRecipeInput inventory, @Nullable WrapperLookup manager) {
|
public ItemStack craft(CraftingRecipeInput inventory, @Nullable WrapperLookup manager) {
|
||||||
ItemStack jar = ItemStack.EMPTY;
|
ItemStack jar = ItemStack.EMPTY;
|
||||||
for (int i = 0; i < inventory.getSize(); i++) {
|
for (int i = 0; i < inventory.size(); i++) {
|
||||||
ItemStack stack = inventory.getStackInSlot(i);
|
ItemStack stack = inventory.getStackInSlot(i);
|
||||||
if (stack.isEmpty()) {
|
if (stack.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -56,7 +56,7 @@ public class JarExtractRecipe extends SpecialCraftingRecipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeSerializer<?> getSerializer() {
|
public RecipeSerializer<? extends JarExtractRecipe> getSerializer() {
|
||||||
return URecipes.JAR_INSERT_SERIALIZER;
|
return URecipes.JAR_INSERT_SERIALIZER;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.item.component.Appearance;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.recipe.RecipeSerializer;
|
import net.minecraft.recipe.RecipeSerializer;
|
||||||
|
import net.minecraft.recipe.SpecialCraftingRecipe;
|
||||||
import net.minecraft.recipe.book.CraftingRecipeCategory;
|
import net.minecraft.recipe.book.CraftingRecipeCategory;
|
||||||
import net.minecraft.recipe.input.CraftingRecipeInput;
|
import net.minecraft.recipe.input.CraftingRecipeInput;
|
||||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||||
|
@ -38,7 +39,7 @@ public class JarInsertRecipe extends ItemCombinationRecipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeSerializer<?> getSerializer() {
|
public RecipeSerializer<? extends JarInsertRecipe> getSerializer() {
|
||||||
return URecipes.JAR_INSERT_SERIALIZER;
|
return URecipes.JAR_INSERT_SERIALIZER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class TransformCropsRecipe implements Recipe<TransformCropsRecipe.Placeme
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSize() {
|
public int size() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.SpawnReason;
|
||||||
|
import net.minecraft.entity.Entity.RemovalReason;
|
||||||
import net.minecraft.predicate.entity.EntityPredicates;
|
import net.minecraft.predicate.entity.EntityPredicates;
|
||||||
import net.minecraft.registry.tag.BlockTags;
|
import net.minecraft.registry.tag.BlockTags;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
@ -138,7 +140,7 @@ public record Altar(
|
||||||
public void generateDecorations(World world) {
|
public void generateDecorations(World world) {
|
||||||
world.setBlockState(origin, UBlocks.SPECTRAL_FIRE.getDefaultState(), Block.FORCE_STATE | Block.NOTIFY_ALL);
|
world.setBlockState(origin, UBlocks.SPECTRAL_FIRE.getDefaultState(), Block.FORCE_STATE | Block.NOTIFY_ALL);
|
||||||
pillars.forEach(pillar -> {
|
pillars.forEach(pillar -> {
|
||||||
FloatingArtefactEntity artefact = UEntities.FLOATING_ARTEFACT.create(world);
|
FloatingArtefactEntity artefact = UEntities.FLOATING_ARTEFACT.create(world, SpawnReason.NATURAL);
|
||||||
artefact.setStack(UItems.ALICORN_BADGE.getDefaultStack());
|
artefact.setStack(UItems.ALICORN_BADGE.getDefaultStack());
|
||||||
artefact.setPosition(pillar.up().toCenterPos());
|
artefact.setPosition(pillar.up().toCenterPos());
|
||||||
artefact.setInvulnerable(true);
|
artefact.setInvulnerable(true);
|
||||||
|
@ -159,7 +161,13 @@ public record Altar(
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeExisting(@Nullable Entity except, World world, BlockPos pillar) {
|
private void removeExisting(@Nullable Entity except, World world, BlockPos pillar) {
|
||||||
world.getOtherEntities(except, new Box(pillar.up()), IS_PARTICIPANT).forEach(Entity::kill);
|
world.getOtherEntities(except, new Box(pillar.up()), IS_PARTICIPANT).forEach(e -> {
|
||||||
|
if (world instanceof ServerWorld sw) {
|
||||||
|
e.kill(sw);
|
||||||
|
} else {
|
||||||
|
e.setRemoved(RemovalReason.KILLED);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid(World world) {
|
public boolean isValid(World world) {
|
||||||
|
|
|
@ -19,8 +19,8 @@ public interface ULootTableEntryType {
|
||||||
});
|
});
|
||||||
LootTableEvents.ALL_LOADED.register((resourceManager, registry) -> {
|
LootTableEvents.ALL_LOADED.register((resourceManager, registry) -> {
|
||||||
extentionTableIds.forEach((base, extra) -> {
|
extentionTableIds.forEach((base, extra) -> {
|
||||||
registry.getOrEmpty(base).ifPresent(table -> {
|
registry.getOptionalValue(base).ifPresent(table -> {
|
||||||
registry.getOrEmpty(extra).ifPresent(extraTable -> {
|
registry.getOptionalValue(extra).ifPresent(extraTable -> {
|
||||||
table.pools = Stream.concat(table.pools.stream(), extraTable.pools.stream()).toList();
|
table.pools = Stream.concat(table.pools.stream(), extraTable.pools.stream()).toList();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,7 +21,7 @@ public interface InventoryUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Stream<Integer> slots(RecipeInput inventory) {
|
static Stream<Integer> slots(RecipeInput inventory) {
|
||||||
return Stream.iterate(0, i -> i < inventory.getSize(), i -> i + 1);
|
return Stream.iterate(0, i -> i < inventory.size(), i -> i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getOpenSlot(Inventory inventory) {
|
static int getOpenSlot(Inventory inventory) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ public interface LimbAnimationUtil {
|
||||||
|
|
||||||
static void resetToZero(LimbAnimator animator) {
|
static void resetToZero(LimbAnimator animator) {
|
||||||
animator.setSpeed(0);
|
animator.setSpeed(0);
|
||||||
animator.updateLimbs(-animator.getPos(), 1);
|
animator.updateLimbs(-animator.getPos(), 1, 1);
|
||||||
animator.setSpeed(0);
|
animator.setSpeed(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public interface LimbAnimationUtil {
|
||||||
|
|
||||||
resetToZero(to);
|
resetToZero(to);
|
||||||
to.setSpeed(prevSpeed);
|
to.setSpeed(prevSpeed);
|
||||||
to.updateLimbs(pos, 1);
|
to.updateLimbs(pos, 1, 1);
|
||||||
to.setSpeed(speed);
|
to.setSpeed(speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import net.minecraft.util.Util;
|
||||||
import net.minecraft.registry.*;
|
import net.minecraft.registry.*;
|
||||||
import net.minecraft.registry.entry.RegistryEntry;
|
import net.minecraft.registry.entry.RegistryEntry;
|
||||||
import net.minecraft.registry.entry.RegistryEntryList;
|
import net.minecraft.registry.entry.RegistryEntryList;
|
||||||
import net.minecraft.registry.entry.RegistryEntryList.Named;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public interface RegistryUtils {
|
public interface RegistryUtils {
|
||||||
|
@ -35,8 +34,12 @@ public interface RegistryUtils {
|
||||||
.buildAndRegister();
|
.buildAndRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static <T> RegistryEntryList<T> entriesForTag(World world, TagKey<T> key) {
|
static <T> RegistryEntryList<T> entriesForTag(World world, TagKey<T> key) {
|
||||||
return world.getRegistryManager().get(key.registry()).getOrCreateEntryList(key);
|
return world.getRegistryManager().getOrThrow(key.registryRef())
|
||||||
|
.getOptional(key)
|
||||||
|
.map(RegistryEntryList.class::cast)
|
||||||
|
.orElse(RegistryEntryList.<T>empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
static <T> Stream<T> valuesForTag(World world, TagKey<T> key) {
|
static <T> Stream<T> valuesForTag(World world, TagKey<T> key) {
|
||||||
|
@ -52,29 +55,18 @@ public interface RegistryUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
static <T> Optional<T> pickRandom(World world, TagKey<T> key, Predicate<T> filter) {
|
static <T> Optional<T> pickRandom(World world, TagKey<T> key, Predicate<T> filter) {
|
||||||
return Util.getRandomOrEmpty(world.getRegistryManager().getOptional(key.registry())
|
return Util.getRandomOrEmpty(entriesForTag(world, key).stream().map(RegistryEntry::value).filter(filter).toList(), world.random);
|
||||||
.flatMap(registry -> registry.getEntryList(key))
|
|
||||||
.stream()
|
|
||||||
.flatMap(Named::stream)
|
|
||||||
.map(RegistryEntry::value)
|
|
||||||
.filter(filter)
|
|
||||||
.toList(), world.random);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static <T> Optional<RegistryEntry<T>> pickRandomEntry(World world, TagKey<T> key, Predicate<RegistryEntry<T>> filter) {
|
static <T> Optional<RegistryEntry<T>> pickRandomEntry(World world, TagKey<T> key, Predicate<RegistryEntry<T>> filter) {
|
||||||
return Util.getRandomOrEmpty(world.getRegistryManager().getOptional(key.registry())
|
return Util.getRandomOrEmpty(entriesForTag(world, key).stream().filter(filter).toList(), world.random);
|
||||||
.flatMap(registry -> registry.getEntryList(key))
|
|
||||||
.stream()
|
|
||||||
.flatMap(Named::stream)
|
|
||||||
.filter(filter)
|
|
||||||
.toList(), world.random);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static <T> boolean isIn(World world, T obj, RegistryKey<? extends Registry<T>> registry, TagKey<T> tag) {
|
static <T> boolean isIn(World world, T obj, RegistryKey<? extends Registry<T>> registry, TagKey<T> tag) {
|
||||||
return world.getRegistryManager().get(registry).getEntry(obj).isIn(tag);
|
return world.getRegistryManager().getOrThrow(registry).getEntry(obj).isIn(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static <T> Identifier getId(World world, T obj, RegistryKey<? extends Registry<T>> registry) {
|
static <T> Identifier getId(World world, T obj, RegistryKey<? extends Registry<T>> registry) {
|
||||||
return world.getRegistryManager().get(registry).getId(obj);
|
return world.getRegistryManager().getOrThrow(registry).getId(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package com.minelittlepony.unicopia.util;
|
package com.minelittlepony.unicopia.util;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface Untyped {
|
public interface Untyped {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static <K, T extends K> T cast(K t) {
|
static <K, T extends K> T cast(K t) {
|
||||||
return (T)t;
|
return (T)t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static <K, T extends K> Optional<T> cast(Optional<K> t) {
|
||||||
|
return t.map(Untyped::cast);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue