Skip to content

Commit

Permalink
feat: Veridium Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jun 13, 2024
1 parent 20be69a commit a6e45fb
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/java/net/zepalesque/redux/config/ReduxConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ public static class Server extends DataSerializableConfig {
public final ModConfigSpec.ConfigValue<Boolean> redux_sky_colors;
public final ModConfigSpec.ConfigValue<Boolean> cloudbed;
public final ModConfigSpec.ConfigValue<Boolean> revamped_quicksoil_movement;
public final ModConfigSpec.IntValue max_veridium_tool_infusion;

public Server(ModConfigSpec.Builder builder) {
super(() -> SERVER_SPEC, "redux_server");
builder.push("TODO");
builder.push("Tweaks");
redux_sky_colors = builder
.comment("Use Redux's alternative sky colors for the Aether")
.define("Redux Sky Colors", true);
Expand All @@ -25,6 +26,11 @@ public Server(ModConfigSpec.Builder builder) {
.comment("Changes quicksoil to make it use a better movement system, based on the way it worked in the Aether II: Highlands in 1.12")
.define("Revamped Quicksoil Movement", true);
builder.pop();
builder.push("Tweaks");
max_veridium_tool_infusion = builder
.comment("The maximum amount of infusion a Veridium tool is able to carry. Note that by default, a tools infusion level is increased by 4 when it is infused with a single Ambrosium Shard.")
.defineInRange("Max Veridium Tool Infusion", 64, 1, 127);
builder.pop();
}
}

Expand Down
76 changes: 76 additions & 0 deletions src/main/java/net/zepalesque/redux/item/VeridiumItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package net.zepalesque.redux.item;

import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeType;
import net.zepalesque.redux.config.ReduxConfig;
import net.zepalesque.redux.recipe.recipes.InfusionRecipe;
import net.zepalesque.zenith.item.CustomStackingBehavior;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public interface VeridiumItem extends CustomStackingBehavior {

String NBT_KEY = "infusion_level";
String INFUSION_AMOUNT = "infusion_increase";

static byte getInfusionLevel(ItemStack stack) {
CompoundTag compound = stack.getTag();
return compound == null ? 0 : compound.getByte(NBT_KEY);
}

Item getUninfusedItem(ItemStack stack);

default ItemStack getUninfusedStack(ItemStack stack) {
ItemStack i = new ItemStack(this.getUninfusedItem(stack));
CompoundTag tag = stack.getOrCreateTag().copy();
tag.remove(NBT_KEY);
i.setTag(tag);
return i;
}

@Nullable
@Override
default ItemStack transformStack(Ingredient ingredient, ItemStack original, RecipeType<?> type, Optional<CompoundTag> additionalData) {
if (additionalData.isEmpty()) {
return original;
}
CompoundTag additional = additionalData.get();
int increase = additional.getByte(InfusionRecipe.ADDED_INFUSION);
if (increase <= 0) {
return original;
}
int max = ReduxConfig.SERVER.max_veridium_tool_infusion.get();
CompoundTag tag = original.getOrCreateTag();
// CompoundTags already return 0 if they do not contain the given byte key, and as the config has a minimum value of 1, it will skip this and add infusion if the item doesn't have the tag
if (tag.getByte(NBT_KEY) >= max) {
return null;
} else {
// As the above comment mentions, CompoundTags will return 0 when the byte key isn't present. This will still result in the correct value, as it will add the amount to zero.
byte infusion = (byte) Math.min(tag.getByte(NBT_KEY) + additional.getByte(InfusionRecipe.ADDED_INFUSION), max);
original.addTagElement(NBT_KEY, ByteTag.valueOf(infusion));
return original;
}
}

// If null is returned, do not change the item in the slot
@Nullable
static ItemStack deplete(ItemStack stack, @Nullable LivingEntity user, int amount) {
if (stack.getItem() instanceof VeridiumItem vi) {
CompoundTag tag = stack.getOrCreateTag();
if (tag.getByte(NBT_KEY) > amount) {
byte infusion = (byte) (tag.getByte(NBT_KEY) - amount);
stack.addTagElement(NBT_KEY, ByteTag.valueOf(infusion));
return null;
} else {
return vi.getUninfusedStack(stack);
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Optional;

public class InfusionRecipe extends AbstractStackingRecipe {
public static final String ADDED_INFUSION = "added_infusion";
public InfusionRecipe(Ingredient ingredient, ItemStack result, Optional<CompoundTag> additional, Optional<Holder<SoundEvent>> sound) {
super(ReduxRecipes.INFUSION.get(), ingredient, result, additional, sound);
}
Expand Down

0 comments on commit a6e45fb

Please sign in to comment.