Skip to content

Commit

Permalink
2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CodexAdrian committed Dec 18, 2023
1 parent e5bc8f6 commit 8051e00
Show file tree
Hide file tree
Showing 25 changed files with 305 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
dependencies: |
resourceful-lib | depends | *
resourceful-config | depends | *
botarium | recommends | *
- name: Upload Fabric Releases (Curse/Modrinth/Github)
id: fabric_release
Expand All @@ -85,6 +86,7 @@ jobs:
fabric-api | depends | *
resourceful-lib | depends | *
resourceful-config | depends | *
botarium | recommends | *
- name: Generate Discord Embed
run: ./gradlew injectEmbed
Expand Down
7 changes: 4 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 2.2.4
# 2.3.0

Fixed favorited locations not being saved
Add config to disabled waystones & fwaystones compat
Fixed issue with Timer mode on Tempad
Added Curios support on Forge
Added Trinket support on Fabric
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -37,4 +38,6 @@ public Item.Properties apply(Item.Properties properties, int fuelCost, int fuelC
public boolean depletesDurability() {
return false;
}

public void tick(ItemStack stack, Entity entity) {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
Expand All @@ -18,26 +19,24 @@
import java.util.List;

public class TimerOption extends TempadOption {
public static final String ID = "Timer";

@Override
public boolean canTimedoorOpen(Player player, ItemStack stack) {
if (stack.getTag() != null && stack.getTag().contains(Tempad.TIMER_NBT)) {
long cooldownTimeTag = stack.getTag().getLong(Tempad.TIMER_NBT);
Instant cooldownTime = Instant.ofEpochSecond(cooldownTimeTag);
return Instant.now().isAfter(cooldownTime);
}
return true;
return !stack.getOrCreateTag().contains(ID);
}

@Override
public void onTimedoorOpen(Player player) {
TeleportUtils.findTempad(player).getOrCreateTag().putLong(Tempad.TIMER_NBT, Instant.now().plusSeconds(TempadOptionApi.getFuelCost(TeleportUtils.findTempad(player))).getEpochSecond());
ItemStack stack = TeleportUtils.findTempad(player);
stack.getOrCreateTag().putLong(ID, TempadOptionApi.getFuelCost(stack) * 20L);
}

@Override
public void addToolTip(ItemStack stack, Level level, List<Component> components, TooltipFlag flag) {
long cooldown = timeLeft(stack);
if (cooldown > 0) {
components.add(Component.translatable("tooltip.tempad.timeleft", Component.literal(DurationFormatUtils.formatDuration(cooldown, "mm:ss", true)).withStyle(ChatFormatting.AQUA)).withStyle(ChatFormatting.GRAY));
components.add(Component.translatable("tooltip.tempad.timeleft", Component.literal(DurationFormatUtils.formatDuration(cooldown * 1000, "mm:ss", true)).withStyle(ChatFormatting.AQUA)).withStyle(ChatFormatting.GRAY));
} else {
components.add(Component.translatable("tooltip.tempad.fullycharged").withStyle(ChatFormatting.AQUA));
}
Expand All @@ -51,24 +50,26 @@ public boolean isDurabilityBarVisible(ItemStack stack) {

@Override
public double getPercentage(ItemStack stack) {
return (TempadOptionApi.getFuelCost(stack) * 1000.0 - timeLeft(stack)) / (TempadOptionApi.getFuelCost(stack) * 1000.0);
return Math.max(0, 1 - (double) timeLeft(stack) / (double) TempadOptionApi.getFuelCost(stack));
}

public static long timeLeft(ItemStack stack) {
if (stack.getTag() != null && stack.getTag().contains(Tempad.TIMER_NBT)) {
long cooldownTimeTag = stack.getTag().getLong(Tempad.TIMER_NBT);
Instant cooldownTime = Instant.ofEpochSecond(cooldownTimeTag);
return Instant.now().until(cooldownTime, ChronoUnit.MILLIS);
if (stack.getTag() != null && stack.getTag().contains(ID)) {
return stack.getTag().getInt(ID) / 20;
}
return 0;
}

public static long getTimerNBT(ItemStack stack) {
if (stack.getTag() != null) {
if (stack.getTag().contains(Tempad.TIMER_NBT)) {
return stack.getTag().getLong(Tempad.TIMER_NBT);
@Override
public void tick(ItemStack stack, Entity entity) {
// tick the timer
if (stack.getTag() != null && stack.getTag().contains(ID)) {
long cooldownTimeTag = stack.getTag().getLong(ID);
if (cooldownTimeTag == 0) {
stack.getTag().remove(ID);
} else {
stack.getTag().putLong(ID, cooldownTimeTag - 1);
}
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ public static void preInit() {
public static void postInit() {
EnergyApi.registerEnergyItem(TempadRegistry.TEMPAD, stack -> {
if (stack.getItem() instanceof TempadItem item && item.getOption() instanceof EnergyOption) {
return new WrappedItemEnergyContainer(stack, new SimpleEnergyContainer(TempadOptionApi.getFuelCapacity(stack)));
return new WrappedItemEnergyContainer(stack, new TempadEnergyContainer(TempadOptionApi.getFuelCapacity(stack)));
}
return null;
});
FluidApi.registerFluidItem(TempadRegistry.TEMPAD, stack -> {
if (stack.getItem() instanceof TempadItem item && item.getOption() instanceof FluidOption) {
return new WrappedItemFluidContainer(stack, new SimpleFluidContainer(TempadOptionApi.getFuelCapacity(stack), 1, (integer, fluidHolder) -> fluidHolder.is(Tempad.TEMPAD_LIQUID_FUEL_TAG)));
return new WrappedItemFluidContainer(stack, new TempadFluidContainer(TempadOptionApi.getFuelCapacity(stack)));
}
return null;
});

EnergyApi.registerEnergyItem(TempadRegistry.CREATIVE_TEMPAD, stack -> {
if (stack.getItem() instanceof TempadItem item && item.getOption() instanceof EnergyOption) {
return new WrappedItemEnergyContainer(stack, new SimpleEnergyContainer(TempadOptionApi.getFuelCapacity(stack)));
return new WrappedItemEnergyContainer(stack, new TempadEnergyContainer(TempadOptionApi.getFuelCapacity(stack)));
}
return null;
});
FluidApi.registerFluidItem(TempadRegistry.CREATIVE_TEMPAD, stack -> {
if (stack.getItem() instanceof TempadItem item && item.getOption() instanceof FluidOption) {
return new WrappedItemFluidContainer(stack, new SimpleFluidContainer(TempadOptionApi.getFuelCapacity(stack), 1, (integer, fluidHolder) -> fluidHolder.is(Tempad.TEMPAD_LIQUID_FUEL_TAG)));
return new WrappedItemFluidContainer(stack, new TempadFluidContainer(TempadOptionApi.getFuelCapacity(stack)));
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.codexadrian.tempad.common.compat.botarium;

import earth.terrarium.botarium.common.energy.impl.SimpleEnergyContainer;

public class TempadEnergyContainer extends SimpleEnergyContainer {
public TempadEnergyContainer(long maxCapacity) {
super(maxCapacity);
}

@Override
public long maxInsert() {
return Integer.MAX_VALUE;
}

@Override
public long maxExtract() {
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.codexadrian.tempad.common.compat.botarium;

import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import earth.terrarium.botarium.common.fluid.impl.SimpleFluidContainer;
import me.codexadrian.tempad.common.Tempad;

import java.util.function.BiPredicate;
import java.util.function.IntToLongFunction;

public class TempadFluidContainer extends SimpleFluidContainer {
public TempadFluidContainer(long maxAmount) {
super(integer -> maxAmount, 1, (integer, fluidHolder) -> fluidHolder.is(Tempad.TEMPAD_LIQUID_FUEL_TAG));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.codexadrian.tempad.common.items;

import dev.architectury.injectables.annotations.PlatformOnly;
import me.codexadrian.tempad.api.options.TempadOption;
import me.codexadrian.tempad.api.options.TempadOptionApi;
import me.codexadrian.tempad.client.config.TempadClientConfig;
Expand All @@ -17,6 +18,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -98,4 +100,20 @@ public boolean isBarVisible(@NotNull ItemStack stack) {
public int getBarWidth(@NotNull ItemStack stack) {
return this.getOption().durabilityBarWidth(stack);
}

@Override
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
super.inventoryTick(stack, level, entity, slotId, isSelected);
this.getOption().tick(stack, entity);
}

@PlatformOnly(PlatformOnly.FABRIC)
public boolean allowNbtUpdateAnimation(Player player, InteractionHand hand, ItemStack oldStack, ItemStack newStack) {
return false;
}

@PlatformOnly(PlatformOnly.FORGE)
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public OpenFavoritedLocationPacket decode(FriendlyByteBuf buffer) {
@Override
public PacketContext handle(OpenFavoritedLocationPacket message) {
return (player, level) -> {
ItemStack itemInHand = TeleportUtils.findTempad(player);
ItemStack tempadStack = TeleportUtils.findTempad(player);
LocationData locationData = TempadLocationHandler.getLocation(level, player.getUUID(), TempadLocationHandler.getFavorite(level, player.getUUID()));
if (locationData != null && itemInHand.getItem() instanceof TempadItem tempadItem && tempadItem.getOption().canTimedoorOpen(player, itemInHand)) {
if (locationData != null && tempadStack.getItem() instanceof TempadItem tempadItem && tempadItem.getOption().canTimedoorOpen(player, tempadStack)) {
if (!player.getAbilities().instabuild) tempadItem.getOption().onTimedoorOpen(player);
TempadItem.summonTimeDoor(locationData, player, message.color);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package me.codexadrian.tempad.common.utils;

import me.codexadrian.tempad.common.Tempad;
import dev.architectury.injectables.annotations.ExpectPlatform;
import me.codexadrian.tempad.common.config.ConfigCache;
import me.codexadrian.tempad.common.config.TempadConfig;
import me.codexadrian.tempad.common.items.TempadItem;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;

public class TeleportUtils {

public static boolean mayTeleport(ResourceKey<Level> level, Player player) {
Expand All @@ -18,24 +22,34 @@ public static boolean mayTeleport(ResourceKey<Level> level, Player player) {
}

public static ItemStack findAndReplaceTempad(Player player, @Nullable ItemStack replacementTempad) {
ItemStack tempad = ItemStack.EMPTY;
int tempadIndex = 0;
AtomicReference<ItemStack> tempad = new AtomicReference<>(ItemStack.EMPTY);
Consumer<ItemStack> setTempad = findTempadInBaubles(player, tempad::set);

if (setTempad != null) {
if (replacementTempad != null) {
setTempad.accept(replacementTempad);
}
return tempad.get();
}

for (int i = 0; i < player.getInventory().getContainerSize(); i++) {
ItemStack stack = player.getInventory().getItem(i);
if (stack.getItem() instanceof TempadItem tempadItem) {
tempad = stack;
tempadIndex = i;
tempad.set(stack);
int finalI = i;
setTempad = (itemStack) -> player.getInventory().setItem(finalI, itemStack);

if (tempadItem.getOption().canTimedoorOpen(player, tempad)) {
if (tempadItem.getOption().canTimedoorOpen(player, tempad.get())) {
break;
}
}
}

if (replacementTempad != null && !tempad.isEmpty()) {
player.getInventory().setItem(tempadIndex, replacementTempad);
if (replacementTempad != null && setTempad != null) {
setTempad.accept(replacementTempad);
}
return tempad;

return tempad.get();
}

public static ItemStack findTempad(Player player) {
Expand All @@ -45,4 +59,10 @@ public static ItemStack findTempad(Player player) {
public static boolean hasTempad(Player player) {
return !findTempad(player).isEmpty();
}

@ExpectPlatform
@Nullable
public static Consumer<ItemStack> findTempadInBaubles(Player player, Consumer<ItemStack> setTempad) {
throw new NotImplementedException("Baubles is not implemented yet!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"tempad:tempad",
"tempad:he_who_remains_tempad"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"entities": ["player"],
"slots": ["bracelet"]
}
9 changes: 9 additions & 0 deletions common/src/main/resources/data/trinkets/entities/tempad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"entities": [
"player"
],
"slots": [
"hand/glove",
"offhand/glove"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"tempad:tempad",
"tempad:he_who_remains_tempad"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"tempad:tempad",
"tempad:he_who_remains_tempad"
]
}
3 changes: 1 addition & 2 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ dependencies {
modImplementation(group = "maven.modrinth", name = "fwaystones", version = "3.1.2+mc1.20")
modImplementation(group = "maven.modrinth", name = "owo-lib", version = "0.11.1+1.20")
modImplementation(group = "maven.modrinth", name = "energized-power", version = "ViCNmOFw")

modImplementation("dev.emi:trinkets:${trinketsVersion}")
"modImplementation"(group = "dev.emi", name = "trinkets", version = trinketsVersion)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.codexadrian.tempad.common.compat.trinkets;

import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.Trinket;
import me.codexadrian.tempad.common.items.TempadItem;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;

public class TempadTrinket implements Trinket {
@Override
public void tick(ItemStack stack, SlotReference slot, LivingEntity entity) {
if (stack.getItem() instanceof TempadItem tempadItem) {
tempadItem.getOption().tick(stack, entity);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.codexadrian.tempad.common.compat.trinkets;

import dev.emi.trinkets.api.TrinketsApi;
import me.codexadrian.tempad.common.registry.TempadRegistry;

public class TempadTrinketHandler {
public static void init() {
TrinketsApi.registerTrinket(TempadRegistry.TEMPAD.get(), new TempadTrinket());
TrinketsApi.registerTrinket(TempadRegistry.CREATIVE_TEMPAD.get(), new TempadTrinket());
}
}
Loading

0 comments on commit 8051e00

Please sign in to comment.