generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84ed1fc
commit 9bded9c
Showing
14 changed files
with
241 additions
and
3 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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/portingdeadmods/nautec/api/items/IBacteriaItem.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,11 @@ | ||
package com.portingdeadmods.nautec.api.items; | ||
|
||
import com.portingdeadmods.nautec.capabilities.NTCapabilities; | ||
import com.portingdeadmods.nautec.capabilities.bacteria.IBacteriaStorage; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public interface IBacteriaItem { | ||
default IBacteriaStorage getStorage(ItemStack stack) { | ||
return stack.getCapability(NTCapabilities.BacteriaStorage.ITEM); | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
src/main/java/com/portingdeadmods/nautec/capabilities/bacteria/BacteriaStorage.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,61 @@ | ||
package com.portingdeadmods.nautec.capabilities.bacteria; | ||
|
||
import com.mojang.datafixers.util.Pair; | ||
import com.mojang.serialization.DataResult; | ||
import com.portingdeadmods.nautec.Nautec; | ||
import com.portingdeadmods.nautec.bacteria.Bacteria; | ||
import net.minecraft.core.HolderLookup; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.NbtOps; | ||
import net.minecraft.nbt.Tag; | ||
import net.neoforged.neoforge.common.util.INBTSerializable; | ||
import org.jetbrains.annotations.UnknownNullability; | ||
|
||
public class BacteriaStorage implements IBacteriaStorage, INBTSerializable<CompoundTag> { | ||
private Bacteria bacteria; | ||
private long bacteriaAmount; | ||
|
||
@Override | ||
public void setBacteria(Bacteria bacteria) { | ||
this.bacteria = bacteria; | ||
} | ||
|
||
@Override | ||
public Bacteria getBacteria() { | ||
return this.bacteria; | ||
} | ||
|
||
@Override | ||
public void setBacteriaAmount(long bacteriaAmount) { | ||
this.bacteriaAmount = bacteriaAmount; | ||
} | ||
|
||
@Override | ||
public long getBacteriaAmount() { | ||
return this.bacteriaAmount; | ||
} | ||
|
||
@Override | ||
public @UnknownNullability CompoundTag serializeNBT(HolderLookup.Provider provider) { | ||
CompoundTag tag = new CompoundTag(); | ||
tag.putLong("bacteriaAmount", this.bacteriaAmount); | ||
DataResult<Tag> tagDataResult = Bacteria.CODEC.encodeStart(NbtOps.INSTANCE, this.bacteria); | ||
if (tagDataResult.isSuccess()) { | ||
tag.put("bacteriaType", tagDataResult.getOrThrow()); | ||
} else { | ||
Nautec.LOGGER.error("Failed to encode bacteria, {}", tagDataResult.error().get().message()); | ||
} | ||
return tag; | ||
} | ||
|
||
@Override | ||
public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) { | ||
this.bacteriaAmount = nbt.getLong("bacteriaAmount"); | ||
DataResult<Pair<Bacteria, Tag>> decodedBacteria = Bacteria.CODEC.decode(NbtOps.INSTANCE, nbt.get("bacteriaType")); | ||
if (decodedBacteria.isSuccess()) { | ||
this.bacteria = decodedBacteria.result().get().getFirst(); | ||
} else { | ||
Nautec.LOGGER.error("Failed to decode bacteria, {}", decodedBacteria.error().get().message()); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/portingdeadmods/nautec/capabilities/bacteria/IBacteriaStorage.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 |
---|---|---|
@@ -1,4 +1,13 @@ | ||
package com.portingdeadmods.nautec.capabilities.bacteria; | ||
|
||
import com.portingdeadmods.nautec.bacteria.Bacteria; | ||
|
||
public interface IBacteriaStorage { | ||
void setBacteria(Bacteria bacteria); | ||
|
||
Bacteria getBacteria(); | ||
|
||
void setBacteriaAmount(long bacteriaAmount); | ||
|
||
long getBacteriaAmount(); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/portingdeadmods/nautec/capabilities/bacteria/ItemBacteriaWrapper.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,30 @@ | ||
package com.portingdeadmods.nautec.capabilities.bacteria; | ||
|
||
import com.portingdeadmods.nautec.bacteria.Bacteria; | ||
import com.portingdeadmods.nautec.data.components.ComponentBacteriaStorage; | ||
import net.minecraft.core.component.DataComponentType; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public record ItemBacteriaWrapper(Supplier<DataComponentType<ComponentBacteriaStorage>> componentType, ItemStack itemStack) implements IBacteriaStorage { | ||
@Override | ||
public void setBacteria(Bacteria bacteria) { | ||
itemStack.set(componentType, new ComponentBacteriaStorage(bacteria, getBacteriaAmount())); | ||
} | ||
|
||
@Override | ||
public Bacteria getBacteria() { | ||
return itemStack.get(componentType).bacteria(); | ||
} | ||
|
||
@Override | ||
public void setBacteriaAmount(long bacteriaAmount) { | ||
itemStack.set(componentType, new ComponentBacteriaStorage(getBacteria(), bacteriaAmount)); | ||
} | ||
|
||
@Override | ||
public long getBacteriaAmount() { | ||
return itemStack.get(componentType).bacteriaAmount(); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/portingdeadmods/nautec/content/items/PetriDishItem.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,11 @@ | ||
package com.portingdeadmods.nautec.content.items; | ||
|
||
import com.portingdeadmods.nautec.api.items.IBacteriaItem; | ||
import com.portingdeadmods.nautec.capabilities.bacteria.IBacteriaStorage; | ||
import net.minecraft.world.item.Item; | ||
|
||
public class PetriDishItem extends Item implements IBacteriaItem { | ||
public PetriDishItem(Properties properties) { | ||
super(properties); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
src/main/java/com/portingdeadmods/nautec/data/components/ComponentBacteriaStorage.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,63 @@ | ||
package com.portingdeadmods.nautec.data.components; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import com.portingdeadmods.nautec.bacteria.Bacteria; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.Items; | ||
|
||
import java.util.Objects; | ||
|
||
public record ComponentBacteriaStorage(Bacteria bacteria, long bacteriaAmount) { | ||
public static final ComponentBacteriaStorage EMPTY = new ComponentBacteriaStorage(new Bacteria() { | ||
@Override | ||
public Item type() { | ||
return Items.AIR; | ||
} | ||
|
||
@Override | ||
public float growthRate() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public float mutationResistance() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public float productionRate() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int lifespan() { | ||
return 0; | ||
} | ||
}, 0); | ||
public static final Codec<ComponentBacteriaStorage> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Bacteria.CODEC.fieldOf("bacteriaType").forGetter(ComponentBacteriaStorage::bacteria), | ||
Codec.LONG.fieldOf("bacteriaAmount").forGetter(ComponentBacteriaStorage::bacteriaAmount) | ||
).apply(instance, ComponentBacteriaStorage::new)); | ||
public static final StreamCodec<RegistryFriendlyByteBuf, ComponentBacteriaStorage> STREAM_CODEC = StreamCodec.composite( | ||
Bacteria.STREAM_CODEC, | ||
ComponentBacteriaStorage::bacteria, | ||
ByteBufCodecs.VAR_LONG, | ||
ComponentBacteriaStorage::bacteriaAmount, | ||
ComponentBacteriaStorage::new | ||
); | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof ComponentBacteriaStorage(Bacteria bacteria1, long amount))) return false; | ||
return bacteriaAmount == amount && Objects.equals(bacteria, bacteria1); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(bacteria, bacteriaAmount); | ||
} | ||
} |
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