Skip to content

Commit

Permalink
new: collections.fluid_submersion: Use faster collection and avoid Fl…
Browse files Browse the repository at this point in the history
…uidTag equality tests
  • Loading branch information
2No2Name committed Mar 9, 2023
1 parent 0ce6b75 commit fc55b7b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lithium-mixin-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ The expensive check to see if a TypeFilterableList can be filtered by a specific
(default: `true`)
Copy entity hashmap instead of duplicating the list using iteration

### `mixin.collections.fluid_submersion`
(default: `true`)
Use ReferenceArraySet instead of HashSet to store the fluids the entity is currently submerged in.

### `mixin.collections.gamerules`
(default: `true`)
Uses fastutil hashmaps for gamerules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.jellysquid.mods.lithium.mixin.collections.fluid_submersion;

import it.unimi.dsi.fastutil.objects.ReferenceArraySet;
import net.minecraft.entity.Entity;
import net.minecraft.fluid.Fluid;
import net.minecraft.registry.tag.TagKey;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Set;

@Mixin(Entity.class)
public class EntityMixin {

@Mutable
@Shadow
@Final
private Set<TagKey<Fluid>> submergedFluidTag;

@Inject(
method = "<init>",
at = @At("RETURN")
)
private void useReferenceArraySet(CallbackInfo ci) {
this.submergedFluidTag = new ReferenceArraySet<>(this.submergedFluidTag);
}

@Redirect(
method = "updateSubmergedInWaterState()V",
at = @At(value = "INVOKE", target = "Ljava/util/Set;clear()V"),
require = 0
)
private void clearIfNotEmpty(Set<?> set) {
if (!set.isEmpty()) {
set.clear();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@MixinConfigOption(description = "Use ReferenceArraySet instead of HashSet to store the fluids the entity is currently submerged in.")
package me.jellysquid.mods.lithium.mixin.collections.fluid_submersion;

import net.caffeinemc.gradle.MixinConfigOption;
1 change: 1 addition & 0 deletions src/main/resources/lithium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"collections.entity_by_type.TypeFilterableListMixin",
"collections.entity_filtering.TypeFilterableListMixin",
"collections.entity_ticking.EntityListMixin",
"collections.fluid_submersion.EntityMixin",
"collections.gamerules.GameRulesMixin",
"collections.goals.GoalSelectorMixin",
"collections.mob_spawning.PoolMixin",
Expand Down

0 comments on commit fc55b7b

Please sign in to comment.