Skip to content

Commit

Permalink
Initial checking for 1.21.4 update
Browse files Browse the repository at this point in the history
  • Loading branch information
OreCruncher committed Jan 1, 2025
1 parent 4fbe3fa commit 8c47ec6
Show file tree
Hide file tree
Showing 58 changed files with 306 additions and 273 deletions.
14 changes: 7 additions & 7 deletions common/src/main/java/org/orecruncher/dsurround/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.orecruncher.dsurround.commands.Commands;
import org.orecruncher.dsurround.config.libraries.*;
import org.orecruncher.dsurround.config.libraries.impl.*;
import org.orecruncher.dsurround.effects.particles.ParticleSheets;
import org.orecruncher.dsurround.effects.particles.Particles;
import org.orecruncher.dsurround.gui.overlay.OverlayManager;
import org.orecruncher.dsurround.gui.keyboard.KeyBindings;
import org.orecruncher.dsurround.lib.GameUtils;
Expand Down Expand Up @@ -76,6 +76,11 @@ public Client() {
}
}
});

// Make sure our particle sheets get registered otherwise they will not render.
// These sheets are purely client side - they have to be manhandled into the
// Minecraft environment.
Particles.register();
}

public void construct() {
Expand Down Expand Up @@ -180,11 +185,6 @@ public void onComplete(Minecraft client) {
// of the dependencies to be initialized.
container.resolve(Handlers.class);

// Make sure our particle sheets get registered otherwise they will not render.
// These sheets are purely client side - they have to be manhandled into the
// Minecraft environment.
ParticleSheets.register();

this.logger.info("[%s] Finalization complete", Constants.MOD_ID);
}

Expand All @@ -196,7 +196,7 @@ private void onConnect(Minecraft minecraftClient) {
var result = versionQueryResult.get();
this.logger.info("Update to %s version %s is available", result.displayName(), result.version());
var player = GameUtils.getPlayer();
player.ifPresent(p -> p.sendSystemMessage(result.getChatText()));
player.ifPresent(p -> p.displayClientMessage(result.getChatText(), false));
} else if(Config.logging.enableModUpdateChatMessage) {
this.logger.info("The mod version is current");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ protected AbstractClientCommand() {
protected int execute(CommandContext<ClientCommandRegistrationEvent.ClientCommandSourceStack> ctx, Supplier<Component> commandHandler) {
try {
var result = commandHandler.get();
ctx.getSource().arch$getPlayer().sendSystemMessage(result);
ctx.getSource().arch$getPlayer().displayClientMessage(result, false);
return 0;
} catch(Exception ex) {
Library.LOGGER.error(ex, "Unable to execute command %s", ctx.getCommand().toString());
ctx.getSource().arch$getPlayer().sendSystemMessage(Component.literal(ex.getMessage()));
ctx.getSource().arch$getPlayer().displayClientMessage(Component.literal(ex.getMessage()), false);
return 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class BiomeCommandHandler {
public static Component execute(ResourceLocation biomeIdentifier, String script) {
return GameUtils.getRegistryManager()
.map(rm -> {
var biome = rm.registry(Registries.BIOME).map(r -> r.get(biomeIdentifier));
var biome = rm.lookup(Registries.BIOME).map(r -> r.get(biomeIdentifier));
if (biome.isEmpty()) {
return Component.translatable("dsurround.command.dsbiome.failure.unknown_biome", biomeIdentifier.toString());
}
var result = ContainerManager.resolve(IBiomeLibrary.class).eval(biome.get(), new Script(script));
var result = ContainerManager.resolve(IBiomeLibrary.class).eval(biome.get().get().value(), new Script(script));
return Component.literal(result.toString());
})
.orElse(Component.literal("Unable to locate registry manager"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public IndividualSoundConfigEntry(ResourceLocation id) {
}

public static IndividualSoundConfigEntry createDefault(final SoundEvent event) {
return new IndividualSoundConfigEntry(event.getLocation());
return new IndividualSoundConfigEntry(event.location());
}

public static IndividualSoundConfigEntry from(IndividualSoundConfigEntry source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static DataResult<IMatcher<Item>> manifest(String itemId) {
return DataResult.success(new ItemTypeMatcher.MatchOnItemTag(tagKey));
} else if (itemId.contains(":")) {
var item = BuiltInRegistries.ITEM.get(id);
return DataResult.success(new ItemTypeMatcher.MatchOnItem(item));
return DataResult.success(new ItemTypeMatcher.MatchOnItem(item.get().value()));
}

return DataResult.error(() -> String.format("Unknown item class(s) %s", itemId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.orecruncher.dsurround.config;

import net.minecraft.resources.ResourceLocation;
import org.orecruncher.dsurround.Constants;
import org.orecruncher.dsurround.effects.particles.ParticleSheets;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.SimpleParticleType;
import org.orecruncher.dsurround.effects.particles.Particles;
import org.orecruncher.dsurround.lib.random.Randomizer;

public enum WaterRippleStyle {

NONE (ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "none")),
PIXELATED_CIRCLE(ParticleSheets.TEXTURE_WATER_RIPPLE_PIXELATED_CIRCLE) {
NONE(null),
PIXELATED_CIRCLE(Particles.WATER_RIPPLE_PIXELATED) {
private final int FRAMES = 7;
private final float DELTA = 1F / this.FRAMES;
private final int MAX_AGE = this.FRAMES * 2;
Expand All @@ -34,14 +35,14 @@ public int getMaxAge() {
}
};

private final ResourceLocation resource;
private final RegistrySupplier<SimpleParticleType> particleTypeRegistrySupplier;

WaterRippleStyle(final ResourceLocation texture) {
this.resource = texture;
WaterRippleStyle(RegistrySupplier<SimpleParticleType> particleTypeSupplier) {
this.particleTypeRegistrySupplier = particleTypeSupplier;
}

public ResourceLocation getTexture() {
return this.resource;
public ParticleType<SimpleParticleType> getParticleType() {
return this.particleTypeRegistrySupplier.get();
}

public float getU1(final int age) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ public BiomeInfo(final int version, final ResourceLocation id, final String name
var accessor = (IBiomeExtended)(Object)biome;
accessor.dsurround_getSpecialEffects().getBackgroundMusic()
.ifPresent(m -> {
var factory = SOUND_LIBRARY.getSoundFactoryForMusic(m);
var entry = new AcousticEntry(factory, null);
this.musicSounds.add(entry);
for (var e : m.unwrap()) {
var factory = SOUND_LIBRARY.getSoundFactoryForMusic(e.data());
// Multiply the weight by 10 - Minecraft has a weight of 1.
var entry = new AcousticEntry(factory, null, e.weight().asInt() * 10);
this.musicSounds.add(entry);
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static void afterReload(ResourceUtilities resourceUtilities, IReloadEven
// Only want to send a message if debug logging is enabled
if (CONFIG.logging.enableDebugLogging) {
var msg = Component.translatable("dsurround.text.reloadassets", Component.translatable("dsurround.modname"));
GameUtils.getPlayer().ifPresent(p -> p.sendSystemMessage(msg));
GameUtils.getPlayer().ifPresent(p -> p.displayClientMessage(msg, false));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.orecruncher.dsurround.config.biome.biometraits.BiomeTraits;
import org.orecruncher.dsurround.config.data.BiomeConfigRule;
import org.orecruncher.dsurround.config.libraries.IBiomeLibrary;
import org.orecruncher.dsurround.config.libraries.IDimensionLibrary;
import org.orecruncher.dsurround.config.libraries.IReloadEvent;
import org.orecruncher.dsurround.lib.Guard;
import org.orecruncher.dsurround.lib.logging.ModLog;
Expand Down Expand Up @@ -48,9 +49,9 @@ public final class BiomeLibrary implements IBiomeLibrary {
// configs changed and cached biome info needs a refresh.
private int version = 0;

public BiomeLibrary(IModLog logger) {
public BiomeLibrary(IDimensionLibrary dimensionLibrary, IModLog logger) {
this.logger = ModLog.createChild(logger, "BiomeLibrary");
this.biomeConditionEvaluator = new BiomeConditionEvaluator(this, logger);
this.biomeConditionEvaluator = new BiomeConditionEvaluator(this, dimensionLibrary, logger);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
Expand Down Expand Up @@ -107,13 +108,13 @@ public Stream<String> dump() {

@Nullable
private static SoundEvent getEquipableSoundEvent(ItemStack stack) {
var item = stack.getItem();
SoundEvent itemEquipSound = null;

if (item instanceof Equipable equipment)
itemEquipSound = equipment.getEquipSound().value();
else if (item instanceof ArmorItem armor)
itemEquipSound = armor.getEquipSound().value();
if (stack.has(DataComponents.EQUIPPABLE)) {
var equippable = stack.getComponents().get(DataComponents.EQUIPPABLE);
if (equippable != null)
itemEquipSound = equippable.equipSound().value();
}

return itemEquipSound;
}
Expand All @@ -125,11 +126,7 @@ private SoundEvent getSoundEvent(ItemStack stack) {
if (itemEquipSound != null)
return itemEquipSound;

var item = stack.getItem();

if (item instanceof ElytraItem elytraItem)
itemEquipSound = elytraItem.getEquipSound().value();
else if (this.tagLibrary.is(ItemTags.LAVA_BUCKETS, stack))
if (this.tagLibrary.is(ItemTags.LAVA_BUCKETS, stack))
itemEquipSound = SoundEvents.BUCKET_FILL_LAVA;
else if (this.tagLibrary.is(ItemTags.WATER_BUCKETS, stack))
itemEquipSound = SoundEvents.BUCKET_FILL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public SoundLibrary(Configuration config, IModLog logger, IMinecraftDirectories
@Override
public Stream<String> dump() {
return this.myRegistry.values().stream()
.sorted((c1, c2) -> Comparers.IDENTIFIER_NATURAL_COMPARABLE.compare(c1.getLocation(), c2.getLocation()))
.sorted((c1, c2) -> Comparers.IDENTIFIER_NATURAL_COMPARABLE.compare(c1.location(), c2.location()))
.map(Object::toString);
}

Expand All @@ -95,7 +95,7 @@ public void reload(ResourceUtilities resourceUtilities, IReloadEvent.Scope scope

// Initializes the internal sound registry once all the other mods have
// registered their sounds.
BuiltInRegistries.SOUND_EVENT.forEach(se -> this.myRegistry.put(se.getLocation(), se));
BuiltInRegistries.SOUND_EVENT.forEach(se -> this.myRegistry.put(se.location(), se));

// Gather resource pack sound files and process them to ensure metadata is collected.
// Resource pack sounds generally replace existing registration, but this allows for new
Expand Down Expand Up @@ -149,7 +149,7 @@ public ISoundFactory getSoundFactoryOrDefault(ResourceLocation factoryLocation)

@Override
public ISoundFactory getSoundFactoryForMusic(Music music) {
return this.soundFactories.computeIfAbsent(music.getEvent().value().getLocation(), loc -> SoundFactoryBuilder.create(music).build());
return this.soundFactories.computeIfAbsent(music.getEvent().value().location(), loc -> SoundFactoryBuilder.create(music).build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean is(TagKey<Block> tagKey, BlockState entry) {
return false;
if (entry.is(tagKey))
return true;
var location = entry.getBlockHolder().unwrapKey().orElseThrow().location();
var location = resolveLocation(entry.getBlockHolder());
return this.isInCache(tagKey, location);
}

Expand All @@ -76,7 +76,7 @@ public boolean is(TagKey<Item> tagKey, ItemStack entry) {
return false;
if (entry.is(tagKey))
return true;
var location = entry.getItemHolder().unwrapKey().orElseThrow().location();
var location = resolveLocation(entry.getItemHolder());
return this.isInCache(tagKey, location);
}

Expand All @@ -87,7 +87,7 @@ public boolean is(TagKey<Biome> tagKey, Biome entry) {
var e = registryEntry.get();
if (e.is(tagKey))
return true;
var location = e.key().location();
var location = resolveLocation(e);
return this.isInCache(tagKey, location);
}
return false;
Expand All @@ -100,12 +100,16 @@ public boolean is(TagKey<EntityType<?>> tagKey, EntityType<?> entry) {

var registryEntry = RegistryUtils.getRegistryEntry(Registries.ENTITY_TYPE, entry);
if (registryEntry.isPresent()) {
var location = registryEntry.get().key().location();
var location = resolveLocation(entry.arch$holder());
return this.isInCache(tagKey, location);
}
return false;
}

public static ResourceLocation resolveLocation(Holder<?> holder) {
return holder.unwrapKey().map(ResourceKey::location).orElseThrow();
}

@Override
public boolean is(TagKey<Fluid> tagKey, FluidState entry) {
if (entry.isEmpty())
Expand All @@ -115,7 +119,7 @@ public boolean is(TagKey<Fluid> tagKey, FluidState entry) {

var registryEntry = RegistryUtils.getRegistryEntry(Registries.FLUID, entry.getType());
if (registryEntry.isPresent()) {
var location = registryEntry.get().key().location();
var location = resolveLocation(entry.holder());
return this.isInCache(tagKey, location);
}
return false;
Expand Down Expand Up @@ -166,7 +170,7 @@ public <T> String asString(Stream<TagKey<T>> tagStream) {
@Override
public <T> Stream<Pair<TagKey<T>, Set<T>>> getEntriesByTag(ResourceKey<? extends Registry<T>> registryKey) {
var registry = RegistryUtils.getRegistry(registryKey).orElseThrow();
return registry.holders()
return registry.listElements()
.flatMap(e -> this.streamTags(e).map(tag -> Pair.of(tag, e.value())))
.collect(groupingBy(Pair::key, mapping(Pair::value, toSet())))
.entrySet().stream().map(e -> Pair.of(e.getKey(), e.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.orecruncher.dsurround.Configuration;
import org.orecruncher.dsurround.config.WaterRippleStyle;
import org.orecruncher.dsurround.config.libraries.ITagLibrary;
import org.orecruncher.dsurround.effects.particles.Particles;
import org.orecruncher.dsurround.effects.particles.WaterRippleParticle;
import org.orecruncher.dsurround.lib.GameUtils;
import org.orecruncher.dsurround.lib.di.ContainerManager;
Expand All @@ -26,10 +27,9 @@ private static boolean doRipples() {
}

private static void addWaterRipple(ClientLevel world, double x, double y, double z) {
var ripple = new WaterRippleParticle(
CONFIG.waterRippleStyle,
world, x, y, z);
GameUtils.getParticleManager().add(ripple);
GameUtils.getParticleManager().createParticle(Particles.WATER_RIPPLE_PIXELATED.get(),x, y, z, 0, 0, 0);
//var ripple = new WaterRippleParticle(CONFIG.waterRippleStyle, world, x, y, z);
//GameUtils.getParticleManager().add(ripple);
}

public static void createRippleParticle(ClientLevel world, Particle particle, Vec3 position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import org.orecruncher.dsurround.config.libraries.IDimensionLibrary;
import org.orecruncher.dsurround.effects.particles.FrostBreathParticle;
import org.orecruncher.dsurround.lib.GameUtils;
import org.orecruncher.dsurround.lib.di.ContainerManager;
Expand All @@ -15,6 +16,7 @@
public class BreathEffect extends EntityEffectBase {

private static final ISeasonalInformation SEASONAL_INFORMATION = ContainerManager.resolve(ISeasonalInformation.class);
private static final IDimensionLibrary DIMENSION_LIBRARY = ContainerManager.resolve(IDimensionLibrary.class);

private final ITickCount tickCount;
private int seed;
Expand Down Expand Up @@ -84,7 +86,7 @@ protected boolean showWaterBubbles(final BlockState headBlock) {
protected boolean showFrostBreath(final LivingEntity entity, final BlockState headBlock, final BlockPos pos) {
if (headBlock.isAir()) {
final Level world = entity.level();
return SEASONAL_INFORMATION.isColdTemperature(world, pos);
return SEASONAL_INFORMATION.isColdTemperature(world, pos, DIMENSION_LIBRARY.getData(world).getSeaLevel());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.item.ItemUseAnimation;
import net.minecraft.world.phys.HitResult;
import org.orecruncher.dsurround.config.libraries.IItemLibrary;

Expand Down Expand Up @@ -68,7 +68,7 @@ protected static boolean looksToBeBlocking(LivingEntity entity) {
return false;
}
Item item = entity.getUseItem().getItem();
return item.getUseAnimation(entity.getUseItem()) == UseAnim.BLOCK;
return item.getUseAnimation(entity.getUseItem()) == ItemUseAnimation.BLOCK;
}

protected static boolean freeSwing(LivingEntity entity) {
Expand Down
Loading

0 comments on commit 8c47ec6

Please sign in to comment.