-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using lava for Sky Steel recipe (#84)
- Loading branch information
Showing
13 changed files
with
176 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"minVersion": "0.8.5", | ||
"package": "gripe._90.megacells.mixin.data", | ||
"compatibilityLevel": "JAVA_17", | ||
"mixins": ["TextureSlotAccessor"], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
"mixins": ["TextureSlotAccessor"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
common/src/main/java/gripe/_90/megacells/misc/LavaTransformLogic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package gripe._90.megacells.misc; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import net.minecraft.tags.FluidTags; | ||
import net.minecraft.world.entity.item.ItemEntity; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.AABB; | ||
|
||
import appeng.recipes.transform.TransformRecipe; | ||
|
||
public final class LavaTransformLogic { | ||
private static final Set<Item> lavaCache = new HashSet<>(); | ||
|
||
public static boolean canTransformInLava(ItemEntity entity) { | ||
return getLavaTransformableItems(entity.level()) | ||
.contains(entity.getItem().getItem()); | ||
} | ||
|
||
@SuppressWarnings("resource") | ||
public static boolean allIngredientsPresent(ItemEntity entity) { | ||
var x = entity.getX(); | ||
var y = entity.getY(); | ||
var z = entity.getZ(); | ||
var level = entity.level(); | ||
|
||
var items = level.getEntities(null, new AABB(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1)).stream() | ||
.filter(e -> e instanceof ItemEntity && !e.isRemoved()) | ||
.map(e -> ((ItemEntity) e).getItem().getItem()) | ||
.toList(); | ||
|
||
for (var recipe : level.getRecipeManager().getAllRecipesFor(TransformRecipe.TYPE)) { | ||
if (!recipe.circumstance.isFluidTag(FluidTags.LAVA)) { | ||
continue; | ||
} | ||
|
||
if (recipe.ingredients.isEmpty()) { | ||
continue; | ||
} | ||
|
||
return recipe.ingredients.stream().noneMatch(ingredient -> { | ||
for (var stack : ingredient.getItems()) { | ||
if (items.contains(stack.getItem())) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static Set<Item> getLavaTransformableItems(Level level) { | ||
if (lavaCache.isEmpty()) { | ||
for (var recipe : level.getRecipeManager().getAllRecipesFor(TransformRecipe.TYPE)) { | ||
if (!recipe.circumstance.isFluidTag(FluidTags.LAVA)) { | ||
continue; | ||
} | ||
|
||
for (var ingredient : recipe.ingredients) { | ||
for (var stack : ingredient.getItems()) { | ||
lavaCache.add(stack.getItem()); | ||
} | ||
|
||
// Don't break here unlike AE2's TransformLogic, otherwise non-processed items will burn up | ||
} | ||
} | ||
} | ||
|
||
return lavaCache; | ||
} | ||
|
||
public static void clearCache() { | ||
lavaCache.clear(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
common/src/main/java/gripe/_90/megacells/mixin/ItemEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package gripe._90.megacells.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.tags.FluidTags; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.item.ItemEntity; | ||
import net.minecraft.world.level.Level; | ||
|
||
import gripe._90.megacells.misc.LavaTransformLogic; | ||
|
||
@Mixin(ItemEntity.class) | ||
public abstract class ItemEntityMixin extends Entity { | ||
public ItemEntityMixin(EntityType<?> entityType, Level level) { | ||
super(entityType, level); | ||
} | ||
|
||
@Unique | ||
private boolean mega$lavaImmune = false; | ||
|
||
@Unique | ||
private int mega$lavaTicks = 0; | ||
|
||
@Inject(method = "fireImmune", at = @At("RETURN"), cancellable = true) | ||
private void handleLavaTransform(CallbackInfoReturnable<Boolean> cir) { | ||
cir.setReturnValue(cir.getReturnValue() || mega$lavaImmune); | ||
} | ||
|
||
@SuppressWarnings({"resource", "DataFlowIssue"}) | ||
@Inject(method = "tick", at = @At("RETURN")) | ||
private void lavaTimeout(CallbackInfo ci) { | ||
var self = (ItemEntity) (Object) this; | ||
|
||
if (LavaTransformLogic.canTransformInLava(self)) { | ||
var x = Mth.floor(getX()); | ||
var y = Mth.floor((getBoundingBox().minY + getBoundingBox().maxY) / 2); | ||
var z = Mth.floor(getZ()); | ||
var state = level().getFluidState(new BlockPos(x, y, z)); | ||
|
||
if (state.is(FluidTags.LAVA)) { | ||
mega$lavaImmune = mega$lavaTicks++ <= 200 || LavaTransformLogic.allIngredientsPresent(self); | ||
|
||
if (mega$lavaTicks > 200 && LavaTransformLogic.allIngredientsPresent(self)) { | ||
mega$lavaTicks = 0; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8.5", | ||
"package": "gripe._90.megacells.mixin", | ||
"mixins": ["ItemEntityMixin"], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ loom { | |
} | ||
|
||
forge { | ||
mixinConfig("$modId.mixins.json") | ||
mixinConfig("$modId.forge.mixins.json") | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters