Skip to content

Commit

Permalink
fix: Hurt allow empty source & drops are missing when recipe can't ma…
Browse files Browse the repository at this point in the history
…tch in exploding (#75)

* fix: Hurt allow empty source

* fix: drops are missing when recipe can't match

* chore: switch to `GsonHelper`
  • Loading branch information
SettingDust authored and Snownee committed Mar 19, 2024
1 parent d3122d6 commit e8a6a0d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/main/java/snownee/lychee/core/post/Hurt.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import snownee.lychee.Lychee;
Expand Down Expand Up @@ -58,7 +59,8 @@ public static class Type extends PostActionType<Hurt> {

@Override
public Hurt fromJson(JsonObject o) {
return new Hurt(MinMaxBounds.Doubles.fromJson(o.get("damage")), new ResourceLocation(o.get("source").getAsString()));
var source = new ResourceLocation(GsonHelper.getAsString(o, "source", "generic"));
return new Hurt(MinMaxBounds.Doubles.fromJson(o.get("damage")), source);
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/snownee/lychee/mixin/ExplosionMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ private void lychee_removeBlockPost(boolean bl, CallbackInfo ci, boolean bl2, Ob
pair.setFirst(null);
var result = RecipeTypes.BLOCK_EXPLODING.process(level, state, () -> ctxBuilder.create(RecipeTypes.BLOCK_EXPLODING.contextParamSet));
if (result == null) {
for (ItemStack stack : pair.getSecond()) {
addBlockDrops(objectArrayList, stack, blockPos);
}
return;
}
BlockExplodingContext ctx = result.getFirst();
Expand Down
30 changes: 17 additions & 13 deletions src/main/resources/data/lychee/recipes/block_exploding3.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"type": "lychee:block_exploding",
"block_in": "gold_block",
"post": [
{
"type": "place",
"block": "diamond_block"
},
{
"type": "drop_item",
"item": "diamond_block"
}
]
}
"type": "lychee:block_exploding",
"block_in": "gold_block",
"contextual": {
"type": "weather",
"weather": "rain"
},
"post": [
{
"type": "place",
"block": "diamond_block"
},
{
"type": "drop_item",
"item": "diamond_block"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"max": 1.5
}
}
}
}

0 comments on commit e8a6a0d

Please sign in to comment.