Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ne-Journey-2#395

- Forge doesn't enforce strict `@Nonnull` contract in `FillBucketEvent#getFilledBucket`. If a listener sets the event's result to `ALLOW` while`getFilledBucket` returns null; NPEs will occur.
- Bump 3.0.6.
  • Loading branch information
Rongmario committed Oct 3, 2021
1 parent f1509a0 commit 8738da5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'org.spongepowered.mixin'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.

version = "3.0.5"
version = "3.0.6"
group = "zone.rong.loliasm" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "loliasm"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package zone.rong.loliasm.bakedquad;

import it.unimi.dsi.fastutil.ints.IntArrays;
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package zone.rong.loliasm.common.forgefixes.mixins;

import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = ForgeEventFactory.class, remap = false)
public class ForgeEventFactoryMixin {

@SuppressWarnings("ConstantConditions")
@Redirect(method = "onBucketUse", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/entity/player/FillBucketEvent;getResult()Lnet/minecraftforge/fml/common/eventhandler/Event$Result;"))
private static Event.Result checkContract(FillBucketEvent event) {
if (event.getResult() == Event.Result.ALLOW && event.getFilledBucket() == null) {
return Event.Result.DEFAULT;
}
return event.getResult();
}

}
3 changes: 3 additions & 0 deletions src/main/java/zone/rong/loliasm/config/LoliConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public boolean shouldSkipClass(Class<?> clazz) {
public boolean quickerEnableUniversalBucketCheck, stripInstancedRandomFromSoundEventAccessor;
public boolean fixBlockIEBaseArrayIndexOutOfBoundsException, cleanupChickenASMClassHierarchyManager, optimizeAmuletRelatedFunctions, labelCanonicalization, skipCraftTweakerRecalculatingSearchTrees, bwmBlastingOilOptimization;
public boolean fixAmuletHolderCapability;
public boolean fixFillBucketEventNullPointerException;

private void initialize() {
configuration = new Configuration(new File(Launch.minecraftHome, "config" + File.separator + "loliasm.cfg"));
Expand Down Expand Up @@ -126,6 +127,8 @@ public void load() {

fixAmuletHolderCapability = getBoolean("fixAmuletHolderCapability", "capability", "Fixes Astral Sorcery applying AmuletHolderCapability to large amount of ItemStacks when it isn't needed. This option will be ignored when Astral Sorcery isn't installed", true);

fixFillBucketEventNullPointerException = getBoolean("fixFillBucketEventNullPointerException", "forgefixes", "Fixes Forge's mistake of annotating FillBucketEvent#getFilledBucket as @Nonnull when the contract isn't fulfilled nor checked. First discovered here: https://github.com/Divine-Journey-2/main/issues/295", true);

configuration.save();
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/zone/rong/loliasm/core/LoliLoadingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion)
public class LoliLoadingPlugin implements IFMLLoadingPlugin {

public static final String VERSION = "3.0.5";
public static final String VERSION = "3.0.6";

public static final boolean isDeobf = FMLLaunchHandler.isDeobfuscatedEnvironment();
public static final boolean isOptifineInstalled = LoliReflector.doesClassExist("optifine.OptiFineForgeTweaker");
Expand Down Expand Up @@ -63,6 +63,9 @@ public LoliLoadingPlugin() {
if (LoliConfig.instance.quickerEnableUniversalBucketCheck) {
Mixins.addConfiguration("mixins.misc_fluidregistry.json");
}
if (LoliConfig.instance.fixFillBucketEventNullPointerException) {
Mixins.addConfiguration("mixins.forgefixes.json");
}
if (isClient) {
if (LoliConfig.instance.reuseBucketQuads) {
Mixins.addConfiguration("mixins.bucket.json");
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/mixins.forgefixes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"package": "zone.rong.loliasm.common.forgefixes.mixins",
"refmap": "mixins.loliasm.refmap.json",
"target": "@env(DEFAULT)",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ForgeEventFactoryMixin"
]
}

0 comments on commit 8738da5

Please sign in to comment.