Skip to content

Commit

Permalink
stuff and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Mar 5, 2024
1 parent b57641b commit b37a5f0
Show file tree
Hide file tree
Showing 61 changed files with 430 additions and 406 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repositories {
maven { url "https://maven.ladysnake.org/releases" } //CCA
maven { url "https://maven.terraformersmc.com" } //trinkets
maven { url "https://maven.wispforest.io" } //owo-lib
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ archives_base_name = artifality
# Dependencies
minecraft_version = 1.20.1
yarn_mappings = 1.20.1+build.10
fabric_loader = 0.15.3
fabric_api = 0.91.0+1.20.1
fabric_loader = 0.15.7
fabric_api = 0.92.0+1.20.1
trinkets_version = 3.7.1
cca_version = 5.2.2
owo_lib = 0.11.2+1.20
2 changes: 1 addition & 1 deletion src/main/java/artifality/api/ArtifalityAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void onInitialize() {

@Override
public void onInitializeClient() {
ModelLoadingRegistry.INSTANCE.registerModelProvider((manager, out) -> TwoModelsItemRegistry.ENTRIES.forEach((id, item) ->
ModelLoadingRegistry.INSTANCE.registerModelProvider((manager, out) -> TwoModeledItems.ENTRIES.forEach((id, item) ->
out.accept(new ModelIdentifier(new Identifier(id + "_in_hand"), "inventory"))
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Map;

@Environment(EnvType.CLIENT)
public class TwoModelsItemRegistry {
public class TwoModeledItems {
public static final Map<Identifier, Item> ENTRIES = new LinkedHashMap<>();

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/artifality/block/TradingPedestalBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@

import artifality.block.base.BaseBlock;
import artifality.block.entity.TradingPedestalBlockEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class TradingPedestalBlock extends BaseBlock implements BlockEntityProvider {
protected static final VoxelShape SHAPE = Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 8.0, 16.0);

public TradingPedestalBlock(Settings settings) {
super(settings);
Expand Down Expand Up @@ -43,4 +48,9 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}
return super.onUse(state, world, pos, player, hand, hit);
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE;
}
}
8 changes: 3 additions & 5 deletions src/main/java/artifality/block/UpgradingPedestalBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.sound.SoundCategory;
Expand Down Expand Up @@ -36,7 +35,6 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
if(world.isClient || hand != Hand.MAIN_HAND) return ActionResult.PASS;

ItemStack stack = player.getStackInHand(hand);
Item item = stack.getItem();

if(stack.isOf(ArtifalityItems.INCREMENTAL_ORB) && getCharges(state) < 3) {
charge(world, pos, state, getCharges(state) + 1);
Expand All @@ -48,16 +46,16 @@ else if(stack.isOf(Items.NETHER_STAR) && getCharges(state) != 4) {
stack.decrement(1);
return ActionResult.SUCCESS;
}
else if(item instanceof ArtifactItem artifact && artifact.artifactSettings.hasTiers) {
else if(stack.getItem() instanceof ArtifactItem artifact && artifact.artifactSettings.hasTiers) {
if(getCharges(state) == 3 && TiersUtils.getTier(stack) == 1) {
world.playSound(null, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.BLOCK_RESPAWN_ANCHOR_DEPLETE.value(), SoundCategory.BLOCKS, 1.0F, 1.0F);
player.setStackInHand(Hand.MAIN_HAND, TiersUtils.withTier(item, 2));
player.setStackInHand(Hand.MAIN_HAND, TiersUtils.withTier(stack, 2));
world.setBlockState(pos, this.getDefaultState());
return ActionResult.SUCCESS;
}
else if(getCharges(state) == 4 && TiersUtils.getTier(stack) == 2) {
world.playSound(null, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.BLOCK_RESPAWN_ANCHOR_DEPLETE.value(), SoundCategory.BLOCKS, 1.0F, 1.0F);
player.setStackInHand(Hand.MAIN_HAND, TiersUtils.withTier(item, 3));
player.setStackInHand(Hand.MAIN_HAND, TiersUtils.withTier(stack, 3));
world.setBlockState(pos, this.getDefaultState());
return ActionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jetbrains.annotations.Nullable;

public class TradingPedestalBlockEntity extends BlockEntity {
public ItemStack sellingItem = ItemStack.EMPTY;
public ItemStack sellingItem = ArtifalityItems.BALLOON.getDefaultStack();
public ItemStack chargeItem = new ItemStack(ArtifalityItems.LUNAR_CRYSTAL, 10);

public TradingPedestalBlockEntity(BlockPos pos, BlockState state) {
Expand All @@ -27,17 +27,22 @@ public TradingPedestalBlockEntity(BlockPos pos, BlockState state) {
public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);

NbtCompound sellingItemNbt = new NbtCompound();
sellingItemNbt.putString("item", Registries.ITEM.getId(sellingItem.getItem()).toString());
sellingItemNbt.put("nbt", sellingItem.getOrCreateNbt());
sellingItemNbt.putInt("count", sellingItem.getCount());
nbt.put("sellingItem", sellingItemNbt);
if(!sellingItem.isEmpty()) {
NbtCompound sellingItemNbt = new NbtCompound();
sellingItemNbt.putString("item", Registries.ITEM.getId(sellingItem.getItem()).toString());
sellingItemNbt.put("nbt", sellingItem.getOrCreateNbt());
sellingItemNbt.putInt("count", sellingItem.getCount());
nbt.put("sellingItem", sellingItemNbt);
}

if(!chargeItem.isEmpty()) {
NbtCompound chargeItemNbt = new NbtCompound();
chargeItemNbt.putString("item", Registries.ITEM.getId(chargeItem.getItem()).toString());
chargeItemNbt.put("nbt", chargeItem.getOrCreateNbt());
chargeItemNbt.putInt("count", chargeItem.getCount());
nbt.put("chargeItem", chargeItemNbt);
}

NbtCompound chargeItemNbt = new NbtCompound();
chargeItemNbt.putString("item", Registries.ITEM.getId(chargeItem.getItem()).toString());
chargeItemNbt.put("nbt", chargeItem.getOrCreateNbt());
chargeItemNbt.putInt("count", chargeItem.getCount());
nbt.put("chargeItem", chargeItemNbt);
}

@Override
Expand All @@ -53,6 +58,9 @@ public void readNbt(NbtCompound nbt) {
this.sellingItem.setNbt((NbtCompound)sellingItemNbt.get("nbt"));
}
}
else {
this.sellingItem = ItemStack.EMPTY;
}

if(nbt.contains("chargeItem")) {
NbtCompound chargeItemNbt = nbt.getCompound("chargeItem");
Expand All @@ -63,6 +71,9 @@ public void readNbt(NbtCompound nbt) {
this.chargeItem.setNbt((NbtCompound)chargeItemNbt.get("nbt"));
}
}
else {
this.chargeItem = ItemStack.EMPTY;
}
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/artifality/client/ArtifalityClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import artifality.item.base.ArtifactItem;
import artifality.registry.ArtifalityBlockEntities;
import artifality.registry.ArtifalityBlocks;
import artifality.api.TwoModelsItemRegistry;
import artifality.api.TwoModeledItems;
import artifality.registry.ArtifalityItems;
import artifality.client.particle.ArtifalityParticles;
import dev.emi.trinkets.api.client.TrinketRendererRegistry;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
Expand All @@ -33,7 +32,7 @@ public void onInitializeClient() {
TrinketRendererRegistry.registerRenderer(item, artifact.artifactSettings.renderer);
}
if(artifact.artifactSettings.hasTwoModels) {
TwoModelsItemRegistry.register(item);
TwoModeledItems.register(item);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void render(T entity, float tickDelta, MatrixStack matrices, VertexConsum
MinecraftClient client = MinecraftClient.getInstance();
BakedModel model = client.getItemRenderer().getModel(stack, world, null, 0);
Vector3f translate = model.getTransformation().ground.translation;
matrices.translate(translate.x() + 0.5, translate.y() + 1.25, translate.z() + 0.5);
matrices.translate(translate.x() + 0.5, translate.y() + 0.75, translate.z() + 0.5);

if (stack.getItem() instanceof BlockItem) {
matrices.scale(1.5F, 1.5F, 1.5F);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/artifality/command/ArtifalityCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.item.ItemStack;
Expand All @@ -18,7 +19,10 @@
public class ArtifalityCommands {

public static void init() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ArtifalityCommands.register(dispatcher, registryAccess));
if(FabricLoader.getInstance().isDevelopmentEnvironment()) {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ArtifalityCommands.register(dispatcher, registryAccess));
}

}

private static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess) {
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/artifality/data/ArtifalityLootTables.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package artifality.data;

import artifality.registry.ArtifalityItems;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.FabricLootSupplierBuilder;
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
import net.fabricmc.fabric.api.loot.v2.FabricLootTableBuilder;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.minecraft.item.Item;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.condition.RandomChanceLootCondition;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.provider.number.ConstantLootNumberProvider;
import net.minecraft.util.Identifier;

public class ArtifalityLootTables {
private static FabricLootSupplierBuilder supplier;
private static FabricLootTableBuilder builder;
private static Identifier id;

private static final String[] NETHER_CHESTS = new String[]{"bastion_bridge", "bastion_hoglin_stable",
Expand All @@ -20,39 +20,43 @@ public class ArtifalityLootTables {
"village", "spawn_bonus_chest", "woodland_mansion"};

public static void init() {
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
LootTableEvents.MODIFY.register((resourceManager, lootManager, id, builder, source) -> {
if(!id.toString().contains("minecraft:chests/")) return;
ArtifalityLootTables.id = id;
ArtifalityLootTables.supplier = supplier;
ArtifalityLootTables.builder = builder;

overworldChest(ArtifalityItems.INVISIBILITY_CAPE, 0.04F);
overworldChest(ArtifalityItems.ZEUS_STAFF, 0.02F);
overworldChest(ArtifalityItems.FOREST_STAFF, 0.03F);
overworldChest(ArtifalityItems.HARVEST_STAFF, 0.03F);
overworldChest(ArtifalityItems.FLORAL_STAFF, 0.03F);
overworldChest(ArtifalityItems.BALLOON, 0.04F);
overworldChest(ArtifalityItems.HAUNTING_SOUL, 0.02F);
overworldChest(ArtifalityItems.HAND_FAN, 0.03F);
overworldChest(ArtifalityItems.LUNAR_CRYSTAL_WAND, 0.03F);
});
}

static void overworldChest(Item item, Float chance) {
String chest = id.toString();
if (!isBlacklisted(chest) && !isNetherChest(chest)) {
FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
.rolls(ConstantLootNumberProvider.create(1)).withCondition(RandomChanceLootCondition.builder(chance).build())
.withEntry(ItemEntry.builder(item).build());
supplier.withPool(poolBuilder.build());
LootPool.Builder poolBuilder = LootPool.builder()
.rolls(ConstantLootNumberProvider.create(1)).conditionally(RandomChanceLootCondition.builder(chance).build())
.with(ItemEntry.builder(item).build());

builder.pool(poolBuilder.build());
}
}

static boolean isBlacklisted(String string) {
for(String banned : BLACKLIST){
for(String banned : BLACKLIST) {
if(string.contains(banned)) return true;
}
return false;
}

static boolean isNetherChest(String string) {
for(String chest : NETHER_CHESTS){
for(String chest : NETHER_CHESTS) {
if(string.contains(chest)) return true;
}
return false;
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/artifality/item/HauntingSoul.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package artifality.item;

import artifality.item.base.ArtifactItem;
import artifality.util.TiersUtils;
import artifality.util.TooltipAppender;
import dev.emi.trinkets.api.Trinket;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.util.List;

public class HauntingSoul extends ArtifactItem implements Trinket {

public HauntingSoul(ArtifactSettings settings) {
super(settings);
}

@Override
public void appendTooltipInfo(ItemStack stack, List<Text> tooltip) {
tooltip.add(Text.empty());

int max = 120;
if(TiersUtils.getTier(stack) == 2) max = 160;
else if(TiersUtils.getTier(stack) == 3) max = 240;

tooltip.add(Text.literal(TooltipAppender.ofKey("souls").replaceAll("%", getSouls(stack) + "/" + max)).formatted(Formatting.DARK_GREEN));
tooltip.add(Text.literal(TooltipAppender.ofKey("extra_damage").replaceAll("%", Integer.toString(getDamageModifier(stack)))).formatted(Formatting.DARK_GREEN));
}

public static int getSouls(ItemStack stack) {
var nbt = stack.getOrCreateNbt();

if(nbt.contains("HauntingSouls")) {
return nbt.getInt("HauntingSouls");
}

return 0;
}

public static int getDamageModifier(ItemStack stack) {
int max = 120;
if(TiersUtils.getTier(stack) == 2) max = 160;
else if(TiersUtils.getTier(stack) == 3) max = 240;

int souls = getSouls(stack);

if(souls >= max) return max / 40;
else return souls / 40;
}

public static void addSoul(ItemStack stack) {
var nbt = stack.getOrCreateNbt();

if(nbt.contains("HauntingSouls")) {
int souls = nbt.getInt("HauntingSouls");
souls++;
nbt.putInt("HauntingSouls", souls);
}
else {
nbt.putInt("HauntingSouls", 1);
}
}

public static void addSouls(ItemStack stack, int increment) {
var nbt = stack.getOrCreateNbt();

if(nbt.contains("HauntingSouls")) {
int souls = nbt.getInt("HauntingSouls");
souls = souls + increment;
nbt.putInt("HauntingSouls", souls);
}
else {
nbt.putInt("HauntingSouls", increment);
}
}

public static void setSouls(ItemStack stack, int count) {
var nbt = stack.getOrCreateNbt();
nbt.putInt("HauntingSouls", count);
}
}
2 changes: 2 additions & 0 deletions src/main/java/artifality/item/InvisibilityCapeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import artifality.item.base.ArtifactItem;
import artifality.util.EffectsUtils;
import artifality.util.TiersUtils;
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.Trinket;
import net.minecraft.entity.LivingEntity;
Expand All @@ -18,5 +19,6 @@ public InvisibilityCapeItem(ArtifactSettings settings) {
public void tick(ItemStack stack, SlotReference slot, LivingEntity entity) {
if (!entity.isSneaking()) return;
EffectsUtils.ticking(entity, StatusEffects.INVISIBILITY);
if(TiersUtils.getTier(stack) >= 3) EffectsUtils.ticking(entity, StatusEffects.SPEED, 2);
}
}
Loading

0 comments on commit b37a5f0

Please sign in to comment.