Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Nov 23, 2023
1 parent 2836633 commit b8f59f5
Show file tree
Hide file tree
Showing 57 changed files with 928 additions and 365 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = true

version = 9.2.1
version = 10.0.0
maven_group = net.ludocrypt
archives_base_name = limlib
12 changes: 8 additions & 4 deletions src/main/java/net/ludocrypt/limlib/api/LimlibRegistryHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
public class LimlibRegistryHooks {

@Internal
public static final Map<RegistryKey<? extends Registry<?>>, Set<LimlibRegistryHook<?>>> REGISTRY_HOOKS = Maps.newHashMap();
public static final Map<RegistryKey<? extends Registry<?>>, Set<LimlibRegistryHook<?>>> REGISTRY_HOOKS = Maps
.newHashMap();
@Internal
public static final Map<RegistryKey<? extends Registry<?>>, Set<LimlibJsonRegistryHook<?>>> REGISTRY_JSON_HOOKS = Maps.newHashMap();
public static final Map<RegistryKey<? extends Registry<?>>, Set<LimlibJsonRegistryHook<?>>> REGISTRY_JSON_HOOKS = Maps
.newHashMap();

public static <O, T extends Registry<O>> void hook(RegistryKey<T> key, LimlibRegistryHook<O> hook) {
Set<LimlibRegistryHook<?>> hooks = REGISTRY_HOOKS.computeIfAbsent(key, k -> Sets.newHashSet());
Expand All @@ -40,7 +42,8 @@ public interface LimlibRegistryHook<O> {
* @param registryKey The RegistryKey of the registry.
* @param registry The MutableRegistry where to register.
*/
void register(RegistryInfoLookup infoLookup, RegistryKey<? extends Registry<O>> registryKey, MutableRegistry<O> registry);
void register(RegistryInfoLookup infoLookup, RegistryKey<? extends Registry<O>> registryKey,
MutableRegistry<O> registry);

}

Expand All @@ -53,7 +56,8 @@ public interface LimlibJsonRegistryHook<O> {
* @param registry The MutableRegistry where to register.
* @param jsonElement The jsonElement to modify before being read by a CODEC.
*/
void register(RegistryInfoLookup infoLookup, RegistryKey<? extends Registry<O>> registryKey, RegistryOps<JsonElement> registryOps, JsonElement jsonElement);
void register(RegistryInfoLookup infoLookup, RegistryKey<? extends Registry<O>> registryKey,
RegistryOps<JsonElement> registryOps, JsonElement jsonElement);

}

Expand Down
18 changes: 15 additions & 3 deletions src/main/java/net/ludocrypt/limlib/api/LimlibTravelling.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ public class LimlibTravelling {
@Internal
public static float travelingPitch = 1.0F;

public static <E extends Entity> E travelTo(E teleported, ServerWorld destination, TeleportTarget target, SoundEvent sound, float volume, float pitch) {
public static <E extends Entity> E travelTo(E teleported, ServerWorld destination, TeleportTarget target,
SoundEvent sound, float volume, float pitch) {

if (destination.equals(teleported.getWorld())) {

BlockPos blockPos = BlockPos.create(target.position.x, target.position.y, target.position.z);

if (!World.isValid(blockPos)) {
throw new UnsupportedOperationException("Position " + blockPos.toString() + " is out of this world!");
}
Expand All @@ -43,10 +46,13 @@ public static <E extends Entity> E travelTo(E teleported, ServerWorld destinatio
ChunkPos chunkPos = new ChunkPos(blockPos);
destination.getChunkManager().addTicket(ChunkTicketType.POST_TELEPORT, chunkPos, 1, teleported.getId());
teleported.stopRiding();

if (((ServerPlayerEntity) teleported).isSleeping()) {
((ServerPlayerEntity) teleported).wakeUp(true, true);
}
((ServerPlayerEntity) teleported).networkHandler.requestTeleport(target.position.x, target.position.y, target.position.z, f, g, Set.of());

((ServerPlayerEntity) teleported).networkHandler
.requestTeleport(target.position.x, target.position.y, target.position.z, f, g, Set.of());

teleported.setHeadYaw(f);
} else {
Expand All @@ -56,10 +62,14 @@ public static <E extends Entity> E travelTo(E teleported, ServerWorld destinatio
}

teleported.setVelocity(target.velocity);
teleported.getWorld().playSound(null, teleported.getX(), teleported.getY(), teleported.getZ(), sound, SoundCategory.AMBIENT, volume, pitch);
teleported
.getWorld()
.playSound(null, teleported.getX(), teleported.getY(), teleported.getZ(), sound, SoundCategory.AMBIENT,
volume, pitch);

return teleported;
} else {

try {
travelingSound = sound;
travelingVolume = volume;
Expand All @@ -70,7 +80,9 @@ public static <E extends Entity> E travelTo(E teleported, ServerWorld destinatio
travelingVolume = 0.0F;
travelingPitch = 0.0F;
}

}

}

}
13 changes: 10 additions & 3 deletions src/main/java/net/ludocrypt/limlib/api/LimlibWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

public class LimlibWorld {

public static final RegistryKey<Registry<LimlibWorld>> LIMLIB_WORLD_KEY = RegistryKey.ofRegistry(new Identifier("limlib", "limlib_world"));
public static final SimpleRegistry<LimlibWorld> LIMLIB_WORLD = FabricRegistryBuilder.createSimple(LIMLIB_WORLD_KEY).attribute(RegistryAttribute.SYNCED).buildAndRegister();
public static final RegistryKey<Registry<LimlibWorld>> LIMLIB_WORLD_KEY = RegistryKey
.ofRegistry(new Identifier("limlib", "limlib_world"));
public static final SimpleRegistry<LimlibWorld> LIMLIB_WORLD = FabricRegistryBuilder
.createSimple(LIMLIB_WORLD_KEY)
.attribute(RegistryAttribute.SYNCED)
.buildAndRegister();

private Supplier<DimensionType> dimensionTypeSupplier;
private Function<RegistryProvider, DimensionOptions> dimensionOptionsSupplier;

public LimlibWorld(Supplier<DimensionType> dimensionTypeSupplier, Function<RegistryProvider, DimensionOptions> dimensionOptionsSupplier) {
public LimlibWorld(Supplier<DimensionType> dimensionTypeSupplier,
Function<RegistryProvider, DimensionOptions> dimensionOptionsSupplier) {
this.dimensionTypeSupplier = Suppliers.memoize(dimensionTypeSupplier);
this.dimensionOptionsSupplier = dimensionOptionsSupplier;
}
Expand All @@ -36,7 +41,9 @@ public Function<RegistryProvider, DimensionOptions> getDimensionOptionsSupplier(
}

public static interface RegistryProvider {

public <T> HolderProvider<T> get(RegistryKey<Registry<T>> key);

}

// Load the class early so our variables are set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

public class EmptyPostEffect extends PostEffect {

public static final Codec<EmptyPostEffect> CODEC = RecordCodecBuilder.create((instance) -> instance.stable(new EmptyPostEffect()));
public static final Codec<EmptyPostEffect> CODEC = RecordCodecBuilder
.create((instance) -> instance.stable(new EmptyPostEffect()));

@Override
public Codec<? extends PostEffect> getCodec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@

public abstract class PostEffect {

public static final RegistryKey<Registry<Codec<? extends PostEffect>>> POST_EFFECT_CODEC_KEY = RegistryKey.ofRegistry(new Identifier("limlib/codec/post_effect"));
public static final Registry<Codec<? extends PostEffect>> POST_EFFECT_CODEC = RegistriesAccessor.callRegisterSimple(POST_EFFECT_CODEC_KEY, Lifecycle.stable(),
(registry) -> StaticPostEffect.CODEC);
public static final Codec<PostEffect> CODEC = POST_EFFECT_CODEC.getCodec().dispatchStable(PostEffect::getCodec, Function.identity());
public static final RegistryKey<Registry<PostEffect>> POST_EFFECT_KEY = RegistryKey.ofRegistry(new Identifier("limlib/post_effect"));
public static final RegistryKey<Registry<Codec<? extends PostEffect>>> POST_EFFECT_CODEC_KEY = RegistryKey
.ofRegistry(new Identifier("limlib/codec/post_effect"));
public static final Registry<Codec<? extends PostEffect>> POST_EFFECT_CODEC = RegistriesAccessor
.callRegisterSimple(POST_EFFECT_CODEC_KEY, Lifecycle.stable(), (registry) -> StaticPostEffect.CODEC);
public static final Codec<PostEffect> CODEC = POST_EFFECT_CODEC
.getCodec()
.dispatchStable(PostEffect::getCodec, Function.identity());
public static final RegistryKey<Registry<PostEffect>> POST_EFFECT_KEY = RegistryKey
.ofRegistry(new Identifier("limlib/post_effect"));

public abstract Codec<? extends PostEffect> getCodec();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
*/
public abstract class DimensionEffects {

public static final RegistryKey<Registry<Codec<? extends DimensionEffects>>> DIMENSION_EFFECTS_CODEC_KEY = RegistryKey.ofRegistry(new Identifier("limlib/codec/dimension_effects"));
public static final Registry<Codec<? extends DimensionEffects>> DIMENSION_EFFECTS_CODEC = RegistriesAccessor.callRegisterSimple(DIMENSION_EFFECTS_CODEC_KEY, Lifecycle.stable(),
(registry) -> StaticDimensionEffects.CODEC);
public static final Codec<DimensionEffects> CODEC = DIMENSION_EFFECTS_CODEC.getCodec().dispatchStable(DimensionEffects::getCodec, Function.identity());
public static final RegistryKey<Registry<DimensionEffects>> DIMENSION_EFFECTS_KEY = RegistryKey.ofRegistry(new Identifier("limlib/dimension_effects"));
public static final RegistryKey<Registry<Codec<? extends DimensionEffects>>> DIMENSION_EFFECTS_CODEC_KEY = RegistryKey
.ofRegistry(new Identifier("limlib/codec/dimension_effects"));
public static final Registry<Codec<? extends DimensionEffects>> DIMENSION_EFFECTS_CODEC = RegistriesAccessor
.callRegisterSimple(DIMENSION_EFFECTS_CODEC_KEY, Lifecycle.stable(), (registry) -> StaticDimensionEffects.CODEC);
public static final Codec<DimensionEffects> CODEC = DIMENSION_EFFECTS_CODEC
.getCodec()
.dispatchStable(DimensionEffects::getCodec, Function.identity());
public static final RegistryKey<Registry<DimensionEffects>> DIMENSION_EFFECTS_KEY = RegistryKey
.ofRegistry(new Identifier("limlib/dimension_effects"));

public static final AtomicReference<HolderLookup<DimensionEffects>> MIXIN_WORLD_LOOKUP = new AtomicReference<HolderLookup<DimensionEffects>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*/
public class EmptyDimensionEffects extends StaticDimensionEffects {

public static final Codec<EmptyDimensionEffects> CODEC = RecordCodecBuilder.create((instance) -> instance.stable(new EmptyDimensionEffects()));
public static final Codec<EmptyDimensionEffects> CODEC = RecordCodecBuilder
.create((instance) -> instance.stable(new EmptyDimensionEffects()));

public EmptyDimensionEffects() {
super(Optional.empty(), false, "NONE", false, false, false, 1.0F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
@ClientOnly
public class SkyPropertiesCreator {

public static DimensionVisualEffects create(float cloudHeight, boolean alternateSkyColor, String skyType, boolean brightenLighting, boolean darkened, boolean thickFog) {
return new DimensionVisualEffects(cloudHeight, alternateSkyColor, SkyType.valueOf(skyType), brightenLighting, darkened) {
public static DimensionVisualEffects create(float cloudHeight, boolean alternateSkyColor, String skyType,
boolean brightenLighting, boolean darkened, boolean thickFog) {
return new DimensionVisualEffects(cloudHeight, alternateSkyColor, SkyType.valueOf(skyType), brightenLighting,
darkened) {

@Override
public Vec3d adjustFogColor(Vec3d color, float sunHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class StaticDimensionEffects extends DimensionEffects {
private final boolean thickFog;
private final float skyShading;

public StaticDimensionEffects(Optional<Float> cloudHeight, boolean alternateSkyColor, String skyType, boolean brightenLighting, boolean darkened, boolean thickFog, float skyShading) {
public StaticDimensionEffects(Optional<Float> cloudHeight, boolean alternateSkyColor, String skyType,
boolean brightenLighting, boolean darkened, boolean thickFog, float skyShading) {
this.cloudHeight = cloudHeight;
this.alternateSkyColor = alternateSkyColor;
this.skyType = skyType;
Expand Down Expand Up @@ -84,7 +85,9 @@ public boolean hasThickFog() {
@Override
@ClientOnly
public DimensionVisualEffects getDimensionEffects() {
return SkyPropertiesCreator.create(getCloudHeight(), hasAlternateSkyColor(), getSkyType(), shouldBrightenLighting(), isDarkened(), hasThickFog());
return SkyPropertiesCreator
.create(getCloudHeight(), hasAlternateSkyColor(), getSkyType(), shouldBrightenLighting(), isDarkened(),
hasThickFog());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

public class SoundEffects {

public static final RegistryKey<Registry<SoundEffects>> SOUND_EFFECTS_KEY = RegistryKey.ofRegistry(new Identifier("limlib/sound_effects"));
public static final RegistryKey<Registry<SoundEffects>> SOUND_EFFECTS_KEY = RegistryKey
.ofRegistry(new Identifier("limlib/sound_effects"));

public static final Codec<SoundEffects> CODEC = RecordCodecBuilder.create((instance) -> {
return instance.group(ReverbEffect.CODEC.optionalFieldOf("reverb").stable().forGetter((soundEffects) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
*/
public abstract class DistortionEffect {

public static final RegistryKey<Registry<Codec<? extends DistortionEffect>>> DISTORTION_EFFECT_CODEC_KEY = RegistryKey.ofRegistry(new Identifier("limlib/codec/distortion_effect"));
public static final Registry<Codec<? extends DistortionEffect>> DISTORTION_EFFECT_CODEC = RegistriesAccessor.callRegisterSimple(DISTORTION_EFFECT_CODEC_KEY, Lifecycle.stable(),
(registry) -> StaticDistortionEffect.CODEC);
public static final Codec<DistortionEffect> CODEC = DISTORTION_EFFECT_CODEC.getCodec().dispatchStable(DistortionEffect::getCodec, Function.identity());
public static final RegistryKey<Registry<Codec<? extends DistortionEffect>>> DISTORTION_EFFECT_CODEC_KEY = RegistryKey
.ofRegistry(new Identifier("limlib/codec/distortion_effect"));
public static final Registry<Codec<? extends DistortionEffect>> DISTORTION_EFFECT_CODEC = RegistriesAccessor
.callRegisterSimple(DISTORTION_EFFECT_CODEC_KEY, Lifecycle.stable(), (registry) -> StaticDistortionEffect.CODEC);
public static final Codec<DistortionEffect> CODEC = DISTORTION_EFFECT_CODEC
.getCodec()
.dispatchStable(DistortionEffect::getCodec, Function.identity());

public abstract Codec<? extends DistortionEffect> getCodec();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static void update() {
}

public static boolean update(SoundInstance soundInstance, DistortionEffect data) {

if (id == -1 || slot == -1) {
update();
}
Expand All @@ -38,45 +39,78 @@ public static boolean update(SoundInstance soundInstance, DistortionEffect data)
if (data.isEnabled(client, soundInstance)) {
EXTEfx.alAuxiliaryEffectSlotf(slot, EXTEfx.AL_EFFECTSLOT_GAIN, 0);
EXTEfx.alEffecti(id, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_DISTORTION);
EXTEfx.alEffectf(id, EXTEfx.AL_DISTORTION_EDGE, MathHelper.clamp(data.getEdge(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_EDGE, EXTEfx.AL_DISTORTION_MAX_EDGE));
EXTEfx.alEffectf(id, EXTEfx.AL_DISTORTION_GAIN, MathHelper.clamp(data.getGain(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_GAIN, EXTEfx.AL_DISTORTION_MAX_GAIN));
EXTEfx.alEffectf(id, EXTEfx.AL_DISTORTION_LOWPASS_CUTOFF,
MathHelper.clamp(data.getLowpassCutoff(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_LOWPASS_CUTOFF, EXTEfx.AL_DISTORTION_MAX_LOWPASS_CUTOFF));
EXTEfx.alEffectf(id, EXTEfx.AL_DISTORTION_EQCENTER, MathHelper.clamp(data.getEQCenter(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_EQCENTER, EXTEfx.AL_DISTORTION_MAX_EQCENTER));
EXTEfx.alEffectf(id, EXTEfx.AL_DISTORTION_EQBANDWIDTH,
MathHelper.clamp(data.getEQBandWidth(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_EQBANDWIDTH, EXTEfx.AL_DISTORTION_MAX_EQBANDWIDTH));
EXTEfx
.alEffectf(id, EXTEfx.AL_DISTORTION_EDGE,
MathHelper
.clamp(data.getEdge(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_EDGE,
EXTEfx.AL_DISTORTION_MAX_EDGE));
EXTEfx
.alEffectf(id, EXTEfx.AL_DISTORTION_GAIN,
MathHelper
.clamp(data.getGain(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_GAIN,
EXTEfx.AL_DISTORTION_MAX_GAIN));
EXTEfx
.alEffectf(id, EXTEfx.AL_DISTORTION_LOWPASS_CUTOFF,
MathHelper
.clamp(data.getLowpassCutoff(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_LOWPASS_CUTOFF,
EXTEfx.AL_DISTORTION_MAX_LOWPASS_CUTOFF));
EXTEfx
.alEffectf(id, EXTEfx.AL_DISTORTION_EQCENTER,
MathHelper
.clamp(data.getEQCenter(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_EQCENTER,
EXTEfx.AL_DISTORTION_MAX_EQCENTER));
EXTEfx
.alEffectf(id, EXTEfx.AL_DISTORTION_EQBANDWIDTH,
MathHelper
.clamp(data.getEQBandWidth(client, soundInstance), EXTEfx.AL_DISTORTION_MIN_EQBANDWIDTH,
EXTEfx.AL_DISTORTION_MAX_EQBANDWIDTH));
EXTEfx.alAuxiliaryEffectSloti(slot, EXTEfx.AL_EFFECTSLOT_EFFECT, id);
EXTEfx.alAuxiliaryEffectSlotf(slot, EXTEfx.AL_EFFECTSLOT_GAIN, 1);

return true;
}

return false;
}

public static void update(SoundInstance soundInstance, int sourceID) {
MinecraftClient client = MinecraftClient.getInstance();

if (!(client == null || client.world == null)) {
Optional<SoundEffects> soundEffects = LookupGrabber.snatch(client.world.getRegistryManager().getLookup(SoundEffects.SOUND_EFFECTS_KEY).get(),
Optional<SoundEffects> soundEffects = LookupGrabber
.snatch(client.world.getRegistryManager().getLookup(SoundEffects.SOUND_EFFECTS_KEY).get(),
RegistryKey.of(SoundEffects.SOUND_EFFECTS_KEY, client.world.getRegistryKey().getValue()));

if (soundEffects.isPresent()) {
Optional<DistortionEffect> distortion = soundEffects.get().getDistortion();

if (distortion.isPresent()) {

if (!distortion.get().shouldIgnore(soundInstance.getId())) {

for (int i = 0; i < 2; i++) {
AL11.alSourcei(sourceID, EXTEfx.AL_DIRECT_FILTER, 0);
AL11.alSource3i(sourceID, EXTEfx.AL_AUXILIARY_SEND_FILTER, update(soundInstance, distortion.get()) ? slot : 0, 0, 0);
AL11
.alSource3i(sourceID, EXTEfx.AL_AUXILIARY_SEND_FILTER,
update(soundInstance, distortion.get()) ? slot : 0, 0, 0);
int error = AL11.alGetError();

if (error == AL11.AL_NO_ERROR) {
break;
} else {
LOGGER.warn("OpenAl Error {}", error);
}

}

}

}

}

}

}

}
Loading

0 comments on commit b8f59f5

Please sign in to comment.