Skip to content

Commit

Permalink
Fix ore generation
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaTheMartian committed Jun 10, 2024
1 parent e373ea3 commit cb1e7fd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/main/java/martian/arcane/api/aura/AuraStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import martian.arcane.common.registry.ArcaneDataComponents;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.item.ItemStack;

import java.util.function.Supplier;

public class AuraStorage implements IMutableAuraStorage {
public static final Codec<AuraStorage> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Expand Down Expand Up @@ -155,4 +159,10 @@ public boolean equals(Object other) {
public int hashCode() {
return freeze().hashCode();
}

public static AuraRecord getOrCreate(ItemStack stack, Supplier<AuraRecord> defaultAuraStorage) {
if (!stack.has(ArcaneDataComponents.AURA))
stack.set(ArcaneDataComponents.AURA, defaultAuraStorage.get());
return stack.get(ArcaneDataComponents.AURA);
}
}
7 changes: 3 additions & 4 deletions src/main/java/martian/arcane/api/item/AbstractAuraItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package martian.arcane.api.item;

import martian.arcane.api.aura.AuraRecord;
import martian.arcane.api.aura.AuraStorage;
import martian.arcane.api.aura.IMutableAuraStorage;
import martian.arcane.common.registry.ArcaneDataComponents;
import net.minecraft.ChatFormatting;
Expand All @@ -22,17 +23,15 @@ public abstract class AbstractAuraItem extends Item {
private final boolean defaultExtractable, defaultInsertable;

public AbstractAuraItem(int maxAura, boolean extractable, boolean insertable, Item.Properties properties) {
super(properties);
super(properties.component(ArcaneDataComponents.AURA, new AuraRecord(maxAura, 0, extractable, insertable)));
this.defaultMaxAura = maxAura;
this.defaultExtractable = extractable;
this.defaultInsertable = insertable;
}

// Aura storage
public AuraRecord getAuraStorage(@NotNull ItemStack stack) {
if (!stack.has(ArcaneDataComponents.AURA))
stack.set(ArcaneDataComponents.AURA, new AuraRecord(defaultMaxAura, 0, defaultExtractable, defaultInsertable));
return stack.get(ArcaneDataComponents.AURA);
return AuraStorage.getOrCreate(stack, () -> new AuraRecord(defaultMaxAura, 0, defaultExtractable, defaultInsertable));
}

public <U> U mapAuraStorage(ItemStack stack, Function<? super AuraRecord, ? extends U> func) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "forge:add_features",
"type": "neoforge:add_features",
"biomes": "#minecraft:is_nether",
"features": "arcane:ore_idocrase",
"step": "underground_ores"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "forge:add_features",
"type": "neoforge:add_features",
"biomes": "minecraft:lush_caves",
"features": "arcane:ore_larimar",
"step": "underground_ores"
Expand Down

0 comments on commit cb1e7fd

Please sign in to comment.