Skip to content

Commit

Permalink
make sure furnace is still nearby
Browse files Browse the repository at this point in the history
  • Loading branch information
SFort committed May 20, 2024
1 parent 363e951 commit 81d7761
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import com.unascribed.fabrication.support.injection.FabModifyArg;
import com.unascribed.fabrication.util.forgery_nonsense.ForgeryFurnaceCartResupplying;
import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.inventory.Inventory;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

Expand All @@ -31,9 +32,20 @@ private static Predicate addFurnaceCarts(Predicate predicate) {
private static void checkFurnaceCarts(World world, double x, double y, double z, CallbackInfoReturnable<Inventory> cir) {
List<ResupplyingFurnaceCart> furnaceList = ForgeryFurnaceCartResupplying.fabrication$fmr$lastCart.get();
if (furnaceList == null) return;
int i = world.random.nextInt(furnaceList.size()+1);
if (i != furnaceList.size()) {
cir.setReturnValue(furnaceList.get(i).fabrication$getResupplyingFurnaceCart());
int i = 0;
while (i<furnaceList.size()) {
Vec3d pos = ((Entity)furnaceList.get(i)).getPos();
if (Math.abs(x-pos.getX())>1 ||Math.abs(y-pos.getY())>1 ||Math.abs(z-pos.getZ())>1) {
furnaceList.remove(i);
} else {
i++;
}
}
if (!furnaceList.isEmpty()) {
i = world.random.nextInt(furnaceList.size()+1);
if (i != furnaceList.size()) {
cir.setReturnValue(furnaceList.get(i).fabrication$getResupplyingFurnaceCart());
}
}
ForgeryFurnaceCartResupplying.fabrication$fmr$lastCart.remove();
}
Expand Down

0 comments on commit 81d7761

Please sign in to comment.