Skip to content

Commit

Permalink
1.21 fixes and additional optimizations
Browse files Browse the repository at this point in the history
- Fixed enchantments not working due to a Mixin
- Added an "unstable" category for things that aren't enabled by default because they aren't fully polished
- Added a tnt networking optimization
- Fixed some older optimizations that were disabled
- Moved some optimizations to the "unstable" category
- Add a proper naming scheme
  • Loading branch information
QPCrummer committed Jun 23, 2024
1 parent 6de638c commit 3225ea1
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 48 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.15.11

# Mod Properties
mod_version = 0.0.1
mod_version = 0.0.1-dev.1
maven_group = com.github.tatercertified
archives_base_name = potatoptimize

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Option {
private final String name;

private Object2BooleanLinkedOpenHashMap<Option> dependencies;
private Set<String> modDefined = null;
private Set<String> modDefined;
private boolean enabled;
private boolean userDefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ public class PotatoptimizeConfig {

private PotatoptimizeConfig() {
// Defines the default rules which can be configured by the user or other mods.
InputStream defaultPropertiesStream = PotatoptimizeConfig.class.getResourceAsStream("/assets/potatoptimize/potatoptimize-mixin-config-default.properties");
if (defaultPropertiesStream == null) {
throw new IllegalStateException("Potatoptimize mixin config default properties could not be read!");
}
try (BufferedReader propertiesReader = new BufferedReader(new InputStreamReader(defaultPropertiesStream))) {
Properties properties = new Properties();
properties.load(propertiesReader);
properties.forEach((ruleName, enabled) -> this.addMixinRule((String) ruleName, Boolean.parseBoolean((String) enabled)));
try (InputStream defaultPropertiesStream = PotatoptimizeConfig.class.getResourceAsStream("/assets/potatoptimize/potatoptimize-mixin-config-default.properties")) {
if (defaultPropertiesStream == null) {
throw new IllegalStateException("Potatoptimize mixin config default properties could not be read!");
}
try (BufferedReader propertiesReader = new BufferedReader(new InputStreamReader(defaultPropertiesStream))) {
Properties properties = new Properties();
properties.load(propertiesReader);
properties.forEach((ruleName, enabled) -> this.addMixinRule((String) ruleName, Boolean.parseBoolean((String) enabled)));
} catch (IOException e) {
e.printStackTrace();
throw new IllegalStateException("Potatoptimize mixin config default properties could not be read!");
}
} catch (IOException e) {
e.printStackTrace();
throw new IllegalStateException("Potatoptimize mixin config default properties could not be read!");
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public abstract class MobPathfindingMixin {

@Shadow @Final protected MobEntity entity;
@Unique
private int lastFailure = 0;
private int lastFailure;
@Unique
private int pathfindFailures = 0;
private int pathfindFailures;

@Inject(method = "startMovingTo(Lnet/minecraft/entity/Entity;D)Z", at = @At("HEAD"), cancellable = true)
private void startMovingTo(Entity entity, double speed, CallbackInfoReturnable<Boolean> cir) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.tatercertified.potatoptimize.mixin.logic.reduce_ray_casting;

import com.moulberry.mixinconstraints.annotations.IfModAbsent;
import net.fabricmc.fabric.api.blockview.v2.FabricBlockView;
import net.minecraft.block.BlockState;
import net.minecraft.fluid.FluidState;
Expand All @@ -22,7 +23,7 @@
/**
* Credit to PaperMC Patch #0687 and #684
*/

@IfModAbsent(value = "lithium")
@Mixin(BlockView.class)
public interface BlockViewCastingMixin extends HeightLimitView, FabricBlockView {
@Shadow BlockState getBlockState(BlockPos pos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.github.tatercertified.potatoptimize.mixin.logic.shape;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import net.minecraft.util.shape.SimplePairList;
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.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
Expand All @@ -24,11 +28,13 @@ public class SimplePairListMixin {
private static final int[] INFINITE_B_0 = new int[]{0, 0};
private static final int[] INFINITE_C = new int[]{0, 1};

@Inject(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/util/shape/SimplePairList;valueIndices:[D", ordinal = 0, shift = At.Shift.BEFORE), cancellable = true)
private void injectIntoConstructor(DoubleList first, DoubleList second, boolean includeFirstOnly, boolean includeSecondOnly, CallbackInfo ci, @Local(ordinal = 0) int i) {
@Inject(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/util/shape/SimplePairList;valueIndices:[D", ordinal = 0, shift = At.Shift.BEFORE))
private void injectIntoConstructor(DoubleList first, DoubleList second, boolean includeFirstOnly, boolean includeSecondOnly, CallbackInfo ci, @Local(ordinal = 0) int i, @Share("arg") LocalBooleanRef booleanRef) {
double tail = first.getDouble(i - 1);
double head = first.getDouble(0);
if (head == Double.NEGATIVE_INFINITY && tail == Double.POSITIVE_INFINITY && !includeFirstOnly && !includeSecondOnly && (i == 2 || i == 4)) {
boolean process = head == Double.NEGATIVE_INFINITY && tail == Double.POSITIVE_INFINITY && !includeFirstOnly && !includeSecondOnly && (i == 2 || i == 4);
booleanRef.set(process);
if (process) {
this.valueIndices = second.toDoubleArray();
this.size = second.size();
if (i == 2) {
Expand All @@ -37,7 +43,15 @@ private void injectIntoConstructor(DoubleList first, DoubleList second, boolean
this.minValues = INFINITE_B_1;
}
this.maxValues = INFINITE_C;
ci.cancel();
}
}

@ModifyConstant(method = "<clinit>", constant = @Constant(intValue = 1))
private static int injected(int constant, @Share("arg") LocalBooleanRef booleanRef) {
if (booleanRef.get()) {
return 0;
} else {
return 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static ExecutorService createWorker(String name) {
executorService = MoreExecutors.newDirectExecutorService();
} else {
executorService = new AbstractExecutorService() {
private volatile boolean shutdown = false;
private volatile boolean shutdown;

@Override
public List<Runnable> shutdownNow() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.tatercertified.potatoptimize.mixin.threading.entity_ticking;
package com.github.tatercertified.potatoptimize.mixin.unstable.entity_ticking;

import com.github.tatercertified.potatoptimize.utils.interfaces.ServerEntityThreadInterface;
import net.minecraft.entity.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.tatercertified.potatoptimize.mixin.threading.entity_ticking;
package com.github.tatercertified.potatoptimize.mixin.unstable.entity_ticking;

import com.github.tatercertified.potatoptimize.utils.interfaces.ServerEntityThreadInterface;
import com.github.tatercertified.potatoptimize.utils.threading.ThreadedTaskExecutor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.tatercertified.potatoptimize.mixin.unstable.explosion_packets;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.Ownable;
import net.minecraft.entity.TntEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundEvents;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(TntEntity.class)
public abstract class ClientExplosionMixin extends Entity implements Ownable {
public ClientExplosionMixin(EntityType<?> type, World world) {
super(type, world);
}

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/TntEntity;discard()V", shift = At.Shift.BEFORE))
private void addClientFunctionality(CallbackInfo ci) {
this.getWorld().addParticle(ParticleTypes.EXPLOSION_EMITTER, this.getX(), this.getY() + 0.5, this.getZ(), 0.0, 0.0, 0.0);
MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.ENTITY_GENERIC_EXPLODE, 1.0F));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.tatercertified.potatoptimize.mixin.unstable.explosion_packets;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ServerWorld.class)
public class ExplosionNetworkingMixin {

@Inject(method = "createExplosion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/explosion/Explosion;shouldDestroy()Z", shift = At.Shift.AFTER), cancellable = true)
private void cancelPackets(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionBehavior behavior, double x, double y, double z, float power, boolean createFire, World.ExplosionSourceType explosionSourceType, ParticleEffect particle, ParticleEffect emitterParticle, RegistryEntry<SoundEvent> soundEvent, CallbackInfoReturnable<Explosion> cir, @Local(ordinal = 0) Explosion explosion) {
cir.setReturnValue(explosion);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.tatercertified.potatoptimize.mixin.memory.reduce_random;
package com.github.tatercertified.potatoptimize.mixin.unstable.reduce_random;

import com.github.tatercertified.potatoptimize.utils.random.ThreadLocalRandomImpl;
import net.minecraft.util.math.random.Random;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ mixin.logic.json = true
mixin.logic.main_thread = true
mixin.logic.recipe_manager = true
mixin.logic.reduce_ray_casting = true
mixin.logic.shape = false
mixin.logic.shape = true
mixin.logic.var_int = true
mixin.logic.worker_thread = true
mixin.memory.map_dedupe = true
mixin.memory.memory_reserve = false
mixin.memory.reduce_alloc = true
mixin.memory.reduce_random = false
mixin.networking.block_breaking = true
mixin.random.creation = true
mixin.random.entity = true
Expand All @@ -44,8 +43,10 @@ mixin.random.unsafe = false
mixin.random.world = true
mixin.remove.profiler = false
mixin.threading.client_tick = true
mixin.threading.entity_ticking = false
mixin.threading.explosions = false
mixin.unstable.entity_ticking = false
mixin.unstable.explosion_packets = false
mixin.unstable.reduce_random = false
mixin.unstream.nearest_item = true
mixin.unstream.pathfinding = true
mixin.unstream.player_movement = true
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/potatoptimize.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"memory.reduce_alloc.ComposterMixin",
"memory.reduce_alloc.ComposterMixin2",
"memory.reduce_alloc.ComposterMixin3",
"memory.reduce_alloc.EnchantmentsMixin",
"memory.reduce_alloc.EntityTrackerEntryMixin",
"memory.reduce_alloc.LivingEntityMixin",
"memory.reduce_alloc.MobEntityMixin",
Expand All @@ -71,8 +70,9 @@
"memory.reduce_alloc.NbtLongArrayMixin",
"memory.reduce_alloc.PacketEncryptionManagerMixin",
"memory.reduce_alloc.ServerConfigListMixin",
"memory.reduce_random.RandomCreationMixin",
"unstable.reduce_random.RandomCreationMixin",
"networking.block_breaking.CacheBlockBreakPacketMixin",
"unstable.explosion_packets.ExplosionNetworkingMixin",
"random.creation.QueryResponseHandlerMixin",
"random.creation.ServerPlayerEntityRandomMixin",
"random.entity.RandomEntityMixin",
Expand All @@ -86,8 +86,8 @@
"remove.profiler.JFRCommandMixin",
"remove.profiler.JFRMixin",
"remove.profiler.ProfilerSystemMixin",
"threading.entity_ticking.EntityListMixin",
"threading.entity_ticking.EntityServerThreadingMixin",
"unstable.entity_ticking.EntityListMixin",
"unstable.entity_ticking.EntityServerThreadingMixin",
"threading.explosions.AsyncExplosionMixin",
"threading.explosions.ExplosionThreadStopMixin",
"unstream.nearest_item.NearestItemSensorMixin",
Expand All @@ -107,6 +107,7 @@
"client": [
"fastmath.rounding.FastRoundingDebugRenderMixin",
"fastmath.rounding.FastRoundingQuadsMixin",
"unstable.explosion_packets.ClientExplosionMixin",
"threading.client_tick.ClientTickMixin",
"unstream.recipe_manager.ClientNetworkAccessor",
"unstream.recipe_manager.StreamClientPlayNetworkHandlerMixin"
Expand Down

0 comments on commit 3225ea1

Please sign in to comment.