Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/io/wispforest/affinity/Affinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.wispforest.affinity.endec.ReflectiveMinecraftEndecs;
import io.wispforest.affinity.network.AffinityNetwork;
import io.wispforest.affinity.object.*;
import io.wispforest.affinity.object.attunedshards.CustomShardTierRegistry;
import io.wispforest.affinity.worldgen.AffinityStructures;
import io.wispforest.affinity.worldgen.AffinityWorldgen;
import io.wispforest.owo.Owo;
Expand Down Expand Up @@ -119,6 +120,8 @@ public void onInitialize() {
));
});

CustomShardTierRegistry.initialize();

if (!Owo.DEBUG) return;
AffinityDebugCommands.register();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import io.wispforest.affinity.blockentity.template.ShardBearingAethumNetworkMemberBlockEntity;
import io.wispforest.affinity.blockentity.template.TickedBlockEntity;
import io.wispforest.affinity.client.render.CuboidRenderer;
import io.wispforest.affinity.item.AttunedShardItem;
import io.wispforest.affinity.misc.util.ListUtil;
import io.wispforest.affinity.misc.util.MathUtil;
import io.wispforest.affinity.misc.util.NbtUtil;
import io.wispforest.affinity.object.AffinityBlocks;
import io.wispforest.affinity.object.attunedshards.AttunedShardTier;
import io.wispforest.affinity.object.attunedshards.AttunedShardTiers;
import io.wispforest.owo.ops.ItemOps;
import io.wispforest.owo.particles.ClientParticles;
Expand All @@ -25,7 +25,6 @@
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -379,45 +378,35 @@ protected void writeNbt(NbtCompound nbt) {
@Override
public ActionResult onUse(PlayerEntity player, Hand hand, BlockHitResult hit) {
var playerStack = player.getStackInHand(hand);
if (playerStack.isEmpty()) {
return ActionResult.PASS;
}

if (!playerStack.isEmpty()) {

if (playerStack.isOf(Items.AMETHYST_SHARD)) {
if (this.shard.isEmpty()) {
this.shard = ItemOps.singleCopy(playerStack);
this.tier = AttunedShardTiers.CRUDE;

ItemOps.decrementPlayerHandItem(player, hand);

updatePropertyCache();
this.markDirty(false);

return ActionResult.SUCCESS;
} else if (this.isUpgradeable && this.outerShardCount < this.outerShards.size()) {
ListUtil.addItem(this.outerShards, ItemOps.singleCopy(playerStack));

ItemOps.decrementPlayerHandItem(player, hand);

updatePropertyCache();
this.markDirty(false);
var shardTier = AttunedShardTier.forItem(playerStack.getItem());
if (shardTier.isNone()) {
return ActionResult.PASS;
}

return ActionResult.SUCCESS;
}
} else if (this.isUpgradeable() && this.shard.isEmpty() && playerStack.getItem() instanceof AttunedShardItem shardItem) {
if (this.shard.isEmpty()) {
if (shardTier.tier() == AttunedShardTiers.CRUDE || this.isUpgradeable) {
this.shard = ItemOps.singleCopy(playerStack);
this.tier = shardItem.tier();

ItemOps.decrementPlayerHandItem(player, hand);

updatePropertyCache();
this.markDirty(false);

return ActionResult.SUCCESS;
this.tier = shardTier;
} else {
return ActionResult.PASS;
}

} else if (shardTier.tier() == AttunedShardTiers.CRUDE && this.isUpgradeable) {
ListUtil.addItem(this.outerShards, ItemOps.singleCopy(playerStack));
} else {
return ActionResult.PASS;
}

return ActionResult.PASS;
ItemOps.decrementPlayerHandItem(player, hand);

updatePropertyCache();
this.markDirty(false);

return ActionResult.SUCCESS;
}

public ActionResult onAttack(PlayerEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GravitonTransducerBlockEntityRenderer(BlockEntityRendererFactory.Context
@Override
protected void render(GravitonTransducerBlockEntity entity, float tickDelta, float frameDelta, long time, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
var shardTier = AttunedShardTier.forItem(entity.shard().getItem());
if (shardTier == AttunedShardTiers.NONE) return;
if (shardTier.isNone()) return;

matrices.push();
matrices.translate(.5, .5 + Math.sin(time / 1000f) * .1f, .5);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/wispforest/affinity/misc/util/FuturesUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.wispforest.affinity.misc.util;

import java.util.List;
import java.util.concurrent.CompletableFuture;

public class FuturesUtil {

public static CompletableFuture<Void> allOf(List<CompletableFuture> futuresList) {
return CompletableFuture.allOf(futuresList.toArray(new CompletableFuture[futuresList.size()]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -26,6 +25,11 @@ public interface AttunedShardTier {
*/
int maxDistance();

/**
* @return The Tier variant of this shard
* */
AttunedShardTiers tier();

/**
* @return The translation key of this tier, used in the
* HUD when looking at a node with a shard of this tier
Expand All @@ -50,8 +54,7 @@ default boolean isNone() {
@NotNull
static AttunedShardTier forItem(Item item) {
if (item instanceof AttunedShardItem shardItem) return shardItem.tier();
if (item == Items.AMETHYST_SHARD) return AttunedShardTiers.CRUDE;
return AttunedShardTiers.NONE;
return CustomShardTierRegistry.getOrDefault(item, AttunedShardTiers.NONE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.wispforest.affinity.object.attunedshards;

import io.wispforest.affinity.Affinity;

import io.wispforest.endec.Endec;

import java.util.Locale;

public class AttunedShardTierString {

public static Endec<AttunedShardTierString> ENDEC = Endec.STRING.xmap(AttunedShardTierString::new, AttunedShardTierString::getTierName);

private String tierName;
private AttunedShardTiers variant;

public AttunedShardTierString(String tierName) {
this.variant = AttunedShardTiers.valueOf(tierName.toUpperCase(Locale.ROOT));
this.tierName = tierName;

if (AttunedShardTiers.NONE == this.variant) {
Affinity.LOGGER.info("Named tier {} could not be matched", tierName);
this.tierName = "NONE";
}
}

public AttunedShardTierString(AttunedShardTiers tier) {
String name = tier.name();
if (!name.equals("NONE")) {
name.toLowerCase(Locale.ROOT);
}

this.variant = tier;
this.tierName = name;
}

public String getTierName() {
return this.tierName.toLowerCase(Locale.ROOT);
}

public AttunedShardTiers getTierVariant() {
return this.variant;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import io.wispforest.affinity.Affinity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.screen.PlayerScreenHandler;

import java.util.Locale;

public enum AttunedShardTiers implements AttunedShardTier {

NONE(0, 5),
Expand All @@ -28,7 +25,7 @@ public enum AttunedShardTiers implements AttunedShardTier {
this.maxTransfer = maxTransfer;
this.maxDistance = maxDistance;

final var name = this.name().toLowerCase(Locale.ROOT);
final var name = this.name().toLowerCase();
this.translationKey = "shard_tier.affinity." + name;

if (Affinity.onClient()) {
Expand All @@ -47,6 +44,10 @@ public int maxDistance() {
return this.maxDistance;
}

public AttunedShardTiers tier() {
return this;
}

@Override
public String translationKey() {
return translationKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.wispforest.affinity.object.attunedshards;

import io.wispforest.affinity.Affinity;
import io.wispforest.endec.Endec;
import io.wispforest.endec.impl.StructEndecBuilder;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.screen.PlayerScreenHandler;

public class CustomShardTier implements AttunedShardTier {
public static final Endec<CustomShardTier> ENDEC = StructEndecBuilder.of(
Endec.LONG.fieldOf("maxTransfer", CustomShardTier::maxTransfer),
Endec.INT.fieldOf("maxDistance", CustomShardTier::maxDistance),
AttunedShardTierString.ENDEC.fieldOf("tierName", CustomShardTier::_getASTS),
CustomShardTier::new
);

private long maxTransfer;
private int maxDistance;
private AttunedShardTierString tierName;
private String translationKey;

@Environment(EnvType.CLIENT)
private SpriteIdentifier sprite;

private void constructHelper(long tf, int d, AttunedShardTierString tier) {
this.maxDistance = d;
this.maxTransfer = tf;
this.tierName = tier;
String tierName = tier.getTierName();
this.translationKey = "shard_tier.affinity." + tierName;

if (Affinity.onClient()) {
this.sprite = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE,
Affinity.id("block/" + tierName + "_aethum_flux_node_shard"));
}
}

public CustomShardTier(long tf, int d, AttunedShardTierString tier) {
this.constructHelper(tf, d, tier);
}

public CustomShardTier(long tf, int d, AttunedShardTiers tier) {
AttunedShardTierString asts = new AttunedShardTierString(tier);
this.constructHelper(tf, d, asts);
}

public CustomShardTier(long tf, int d, String tierName) {
AttunedShardTierString asts = new AttunedShardTierString(tierName);
this.constructHelper(tf, d, asts);
}

@Override
public long maxTransfer() {
return this.maxTransfer;
}

@Override
public int maxDistance() {
return this.maxDistance;
}

public AttunedShardTiers tier() {
return this.tierName.getTierVariant();
}

public AttunedShardTierString _getASTS() {
return this.tierName;
}

@Override
public String translationKey() {
return this.translationKey;
}

@Environment(EnvType.CLIENT)
public SpriteIdentifier sprite() {
return this.sprite;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.wispforest.affinity.object.attunedshards;

import io.wispforest.affinity.endec.BuiltInEndecs;
import io.wispforest.endec.Endec;
import io.wispforest.endec.impl.StructEndecBuilder;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;

import java.util.List;

public class CustomShardTierJsonFile {

public static final Endec<CustomShardTierJsonFile> ENDEC = StructEndecBuilder.of(
BuiltInEndecs.ofRegistry(Registries.ITEM).listOf().fieldOf("items", CustomShardTierJsonFile::getItems),
CustomShardTier.ENDEC.fieldOf("tier", CustomShardTierJsonFile::getTier),
CustomShardTierJsonFile::new
);

private List<Item> items;
private CustomShardTier tier;

public CustomShardTierJsonFile (List<Item> items, CustomShardTier tier) {
this.items = items;
this.tier = tier;
}

public List<Item> getItems() {
return items;
}

public CustomShardTier getTier() {
return tier;
}
}
Loading