Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Several fixes for last update
Browse files Browse the repository at this point in the history
  • Loading branch information
florensie committed Oct 4, 2021
1 parent da9be1c commit bdbbfcd
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 96 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.1] - 2021-10-04
### Fixed
- No longer depend on cardinal components for items, fixes related crash
- As a side effect, Artifacts that were set to have effects disabled have had their effects re-enabled
- Fix issue with aqua dashers working when resurfacing from water
- Fix everlasting beef dropping for non-player kills

## [4.0.0] - 2021-09-29
### Added
- Helium Flamingo artifact
Expand Down Expand Up @@ -191,7 +198,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release

[Unreleased]: https://github.com/florensie/artifacts-fabric/compare/v3.2.1...HEAD
[Unreleased]: https://github.com/florensie/artifacts-fabric/compare/v4.0.1...HEAD
[4.0.1]: https://github.com/florensie/artifacts-fabric/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/florensie/artifacts-fabric/compare/v3.2.1...v4.0.0
[3.2.1]: https://github.com/florensie/artifacts-fabric/compare/v3.2.0...v3.2.1
[3.2.0]: https://github.com/florensie/artifacts-fabric/compare/v3.1.0...v3.2.0
[3.1.0]: https://github.com/florensie/artifacts-fabric/compare/v3.0.3...v3.1.0
Expand Down
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ dependencies {
modImplementation("com.github.emilyploszaj:trinkets:${project.trinkets_version}") {
transitive = false
}
modImplementation include("io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${project.cca_version}")
modImplementation include("io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:${project.cca_version}")
modImplementation include("io.github.onyxstudios.Cardinal-Components-API:cardinal-components-item:${project.cca_version}")
modImplementation include("io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${cca_version}")
modImplementation include("io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:${cca_version}")
modImplementation include("be.florens:expandability-fabric:${project.expandability_version}")
modImplementation "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}"
modImplementation("com.terraformersmc:modmenu:${project.mod_menu_version}") {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ loader_version=0.11.7
parchment_version=2021.08.29

# Mod Properties
mod_version=4.0.0+fabric
mod_version=4.0.1+fabric
maven_group=artifacts
archives_base_name=artifacts

# Dependencies
fabric_version=0.36.0+1.16
trinkets_version=2.6.7
cca_version=2.8.3
expandability_version=2.0.1
expandability_version=2.0.2
cloth_config_version=4.11.26
mod_menu_version=1.16.9
step_height_attr_version=v1.0.1
Expand Down
53 changes: 0 additions & 53 deletions src/main/java/artifacts/components/BooleanComponent.java

This file was deleted.

38 changes: 36 additions & 2 deletions src/main/java/artifacts/components/SyncedBooleanComponent.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
package artifacts.components;

import dev.onyxstudios.cca.api.v3.component.Component;
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;

public class SyncedBooleanComponent extends BooleanComponent implements AutoSyncedComponent {
public class SyncedBooleanComponent implements Component, AutoSyncedComponent {

private final String name;
protected boolean bool;

public SyncedBooleanComponent(String name) {
super(name);
this.name = name;
}

public boolean get() {
return bool;
}

public void set(boolean bool) {
this.bool = bool;
}

@Override
public void readFromNbt(CompoundTag tag) {
this.bool = tag.contains(this.name) && tag.getBoolean(this.name);
}

@Override
public void writeToNbt(CompoundTag tag) {
tag.putBoolean(this.name, this.bool);
}

@Override
Expand All @@ -19,4 +42,15 @@ public void writeSyncPacket(FriendlyByteBuf buf, ServerPlayer recipient) {
public void applySyncPacket(FriendlyByteBuf buf) {
this.bool = buf.readBoolean();
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof SyncedBooleanComponent) {
SyncedBooleanComponent other = (SyncedBooleanComponent) obj;
return this.get() == other.get() && this.name.equals(other.name);
}
return false;
}
}
22 changes: 1 addition & 21 deletions src/main/java/artifacts/init/Components.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
package artifacts.init;

import artifacts.Artifacts;
import artifacts.components.BooleanComponent;
import artifacts.components.EntityKillTrackerComponent;
import artifacts.components.SwimAbilityComponent;
import artifacts.components.SyncedBooleanComponent;
import artifacts.item.curio.TrinketArtifactItem;
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import dev.onyxstudios.cca.api.v3.component.ComponentRegistryV3;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer;
import dev.onyxstudios.cca.api.v3.item.ItemComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.item.ItemComponentInitializer;
import nerdhub.cardinal.components.api.util.RespawnCopyStrategy;
import net.minecraft.core.Registry;
import net.minecraft.world.entity.item.ItemEntity;

import java.util.concurrent.atomic.AtomicInteger;

public class Components implements EntityComponentInitializer, ItemComponentInitializer {
public class Components implements EntityComponentInitializer {

public static final ComponentKey<SyncedBooleanComponent> DROPPED_ITEM_ENTITY =
ComponentRegistryV3.INSTANCE.getOrCreate(Artifacts.id("dropped_item_entity"), SyncedBooleanComponent.class);
public static final ComponentKey<BooleanComponent> ARTIFACT_ENABLED =
ComponentRegistryV3.INSTANCE.getOrCreate(Artifacts.id("trinket_enabled"), BooleanComponent.class);
public static final ComponentKey<SwimAbilityComponent> SWIM_ABILITIES =
ComponentRegistryV3.INSTANCE.getOrCreate(Artifacts.id("swim_abilities"), SwimAbilityComponent.class);
public static final ComponentKey<EntityKillTrackerComponent> ENTITY_KILL_TRACKER =
Expand All @@ -35,15 +26,4 @@ public void registerEntityComponentFactories(EntityComponentFactoryRegistry regi
registry.registerForPlayers(SWIM_ABILITIES, SwimAbilityComponent::new, RespawnCopyStrategy.LOSSLESS_ONLY);
registry.registerForPlayers(ENTITY_KILL_TRACKER, entity -> new EntityKillTrackerComponent(), RespawnCopyStrategy.LOSSLESS_ONLY);
}

@Override
public void registerItemComponentFactories(ItemComponentFactoryRegistry registry) {
// Non-dynamic component registration, might fix this issue: https://github.com/florensie/artifacts-fabric/issues/35
AtomicInteger registerCount = new AtomicInteger();
Registry.ITEM.stream().filter(item -> item instanceof TrinketArtifactItem).forEach(item -> {
registry.registerFor(item, ARTIFACT_ENABLED, stack -> new BooleanComponent("isEnabled", true));
registerCount.getAndIncrement();
});
Artifacts.LOGGER.info("[Artifacts] Registered item components for {} Artifacts", registerCount.get());
}
}
39 changes: 32 additions & 7 deletions src/main/java/artifacts/item/curio/TrinketArtifactItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import artifacts.Artifacts;
import artifacts.client.render.trinket.CurioRenderers;
import artifacts.components.BooleanComponent;
import artifacts.events.PlayHurtSoundCallback;
import artifacts.init.Components;
import artifacts.init.Slot;
import artifacts.item.ArtifactItem;
import artifacts.trinkets.TrinketsHelper;
Expand All @@ -20,6 +18,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.TranslatableComponent;
Expand Down Expand Up @@ -60,16 +59,16 @@ public boolean canWearInSlot(String group, String slot) {

@Override
public InteractionResultHolder<ItemStack> use(Level level, Player user, InteractionHand hand) {
// Toggle artifact effects when sneak right-clicking
// Cycle artifact status when sneak right-clicking
if (user.isShiftKeyDown()) {
ItemStack stack = user.getItemInHand(hand);
boolean enabled = Components.ARTIFACT_ENABLED.maybeGet(stack)
.map(BooleanComponent::invert)
.orElse(true);
CompoundTag tag = stack.getOrCreateTagElement("Artifacts");
tag.putByte("Status", (byte) ArtifactStatus.nextIndex(tag.getByte("Status")));
stack.addTagElement("Artifacts", tag);

if (level.isClientSide()) {
// Show enabled/disabled message above hotbar
ChatFormatting enabledColor = enabled ? ChatFormatting.GREEN : ChatFormatting.RED;
ChatFormatting enabledColor = TrinketsHelper.areEffectsEnabled(stack) ? ChatFormatting.GREEN : ChatFormatting.RED;
Component enabledText = new TranslatableComponent(getEffectsEnabledLanguageKey(stack)).withStyle(enabledColor);
Minecraft.getInstance().gui.setOverlayMessage(enabledText, false);
}
Expand Down Expand Up @@ -176,6 +175,32 @@ private static String getEffectsEnabledLanguageKey(ItemStack stack) {
return TrinketsHelper.areEffectsEnabled(stack) ? "artifacts.trinket.effectsenabled" : "artifacts.trinket.effectsdisabled";
}

public enum ArtifactStatus {
ALL_ENABLED(true, true),
COSMETIC_ONLY(false, true);
// EFFECTS_ONLY(true, false);

private final boolean hasEffects;
private final boolean hasCosmetics;

ArtifactStatus(boolean hasEffects, boolean hasCosmetics) {
this.hasEffects = hasEffects;
this.hasCosmetics = hasCosmetics;
}

public boolean hasEffects() {
return hasEffects;
}

public boolean hasCosmetics() {
return hasCosmetics;
}

public static int nextIndex(int index) {
return index >= values().length - 1 ? 0 : index + 1;
}
}

// From Curios
// TODO: Java 17 Record
protected static final class SoundInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public AquaDashersItem() {

@Override
public void tick(Player player, ItemStack stack) {
Components.SWIM_ABILITIES.maybeGet(this).ifPresent(swimAbilities -> {
Components.SWIM_ABILITIES.maybeGet(player).ifPresent(swimAbilities -> {
if (player.isInWater()) {
swimAbilities.setWet(true);
} else if (player.isOnGround() || player.abilities.flying) {
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/artifacts/trinkets/TrinketsHelper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package artifacts.trinkets;

import artifacts.components.BooleanComponent;
import artifacts.init.Components;
import artifacts.item.curio.TrinketArtifactItem;
import dev.emi.trinkets.api.TrinketsApi;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.Container;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -66,8 +65,15 @@ public static List<ItemStack> getAllEquipped(LivingEntity entity, boolean ignore
}

public static boolean areEffectsEnabled(ItemStack stack) {
return Components.ARTIFACT_ENABLED.maybeGet(stack)
.map(BooleanComponent::get)
.orElse(true);
if (!(stack.getItem() instanceof TrinketArtifactItem)) {
return false;
}

CompoundTag tag = stack.getTagElement("Artifacts");
if (tag == null || !tag.contains("Status", 1)) {
return true;
}

return TrinketArtifactItem.ArtifactStatus.values()[tag.getByte("Status")].hasEffects();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
{
"condition": "artifacts:configurable_random_chance",
"default_probability": 0.002
},
{
"condition": "minecraft:killed_by_player"
}
]
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"expandability": ">=2.0.0",
"cardinal-components-base": ">=2.7.5",
"cardinal-components-entity": ">=2.7.5",
"cardinal-components-item": ">=2.7.5",
"cloth-config2": ">=4.9",
"step-height-entity-attribute": "*"
},
Expand Down

0 comments on commit bdbbfcd

Please sign in to comment.