Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crafting fixes #459

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ public enum Mixins {
"fml.MixinNetworkDispatcher",
"minecraft.NetworkManagerAccessor")
.setApplyIf(() -> FixesConfig.fixBogusIntegratedServerNPEs).addTargetedMod(TargetedMod.VANILLA)),
CRAFTING_OPTIMIZATIONS(new Builder("Crafting Optimizations").setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinShapedOreRecipe").setSide(Side.BOTH)
.setApplyIf(() -> true).addTargetedMod(TargetedMod.VANILLA)),

FIX_LOGIN_DIMENSION_ID_OVERFLOW(
new Builder("Fix dimension id overflowing when a player first logins on a server").setPhase(Phase.EARLY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

@Mixin(value = ShapedOreRecipe.class)
public class MixinShapedOreRecipe {

@Shadow(remap = false)
private int width;

@Shadow(remap = false)
private int height;

@Shadow(remap = false)
private Object[] input;

@Shadow(remap = false)
private boolean mirrored;

@Unique
private int hodgepodge$activeSize = -1;

/**
* @author kuba6000
* @reason Optimize ShapedOreRecipe
*/
@Overwrite
public boolean matches(InventoryCrafting inv, World world) {
if (hodgepodge$activeSize == -1) {
hodgepodge$activeSize = 0;
for (int i = 0; i < width * height; i++) {
if (input[i] != null) {
hodgepodge$activeSize++;
break;
}
}
}

int invSize = inv.getSizeInventory();
int wsize = (int) Math.sqrt(invSize);

// some basic checks to avoid item comparing
if (height > wsize || width > wsize) {
return false;
}
int invActiveSize = 0;
for (int i = 0; i < invSize; i++) {
if (inv.getStackInSlot(i) != null) {
invActiveSize++;
if (invActiveSize > hodgepodge$activeSize) {
return false;
}
}
}

if (invActiveSize != hodgepodge$activeSize) {
return false;
}

for (int i = 0; i < wsize - width + 1; i++) {
for (int j = 0; j < wsize - height + 1; j++) {
if (checkMatch(inv, i, j, true)) {
return true;
}
if (mirrored && checkMatch(inv, i, j, false)) {
return true;
}
}
}

return false;
}

@Shadow(remap = false)
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) {
throw new RuntimeException("Mixin failed to apply");
}

}
Loading