Skip to content

Commit

Permalink
Rework Spectral Eye Amulet
Browse files Browse the repository at this point in the history
  • Loading branch information
stal111 committed Oct 28, 2024
1 parent e641aeb commit c429884
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.1 2024-10-24T16:35:57.1802687 Languages: en_us for mod: forbidden_arcanus
c4ea19da19c80b17f84e993fd9087f7a2eb20af9 assets/forbidden_arcanus/lang/en_us.json
// 1.21.1 2024-10-28T23:35:10.5863419 Languages: en_us for mod: forbidden_arcanus
904c4138da3eb97be91f5b6228ad94ed7747aee0 assets/forbidden_arcanus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@
"item.forbidden_arcanus.tentacle": "Tentacle",
"item.forbidden_arcanus.terrastomp_prism": "Terrastomp Prism",
"item.forbidden_arcanus.test_tube": "Test Tube",
"item.forbidden_arcanus.toggle_state": "(Right-Click to toggle)",
"item.forbidden_arcanus.toggle_state.activated": "Activated",
"item.forbidden_arcanus.toggle_state.deactivated": "Deactivated",
"item.forbidden_arcanus.tyr_boots": "Tyr Boots",
"item.forbidden_arcanus.tyr_chestplate": "Tyr Chestplate",
"item.forbidden_arcanus.tyr_helmet": "Tyr Helmet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void onClientSetup(FMLClientSetupEvent event) {
}

//ItemProperties.register(ModItems.FORBIDDENMICON.get(), new ResourceLocation("open"), (stack, world, entity) -> entity != null && ForbiddenmiconItem.isOpen(stack) ? 1.0F : 0.0F);
ItemProperties.register(ModItems.SPECTRAL_EYE_AMULET.get(), ForbiddenArcanus.location("deactivated"), (stack, level, entity, seed) -> entity != null && stack.getItem() instanceof SpectralEyeAmuletItem item && item.isDeactivated(stack) ? 1.0F : 0.0F);
ItemProperties.register(ModItems.SPECTRAL_EYE_AMULET.get(), ForbiddenArcanus.location("deactivated"), (stack, level, entity, seed) -> entity != null && SpectralEyeAmuletItem.isActive(stack) ? 0.0F : 1.0F);
ItemProperties.register(ModItems.BLOOD_TEST_TUBE.get(), ForbiddenArcanus.location("amount"), ESSENCE_AMOUNT_PROPERTY_FUNCTION);

ItemProperties.register(ModItems.AUREAL_TANK.get(), ForbiddenArcanus.location("amount"), ESSENCE_AMOUNT_PROPERTY_FUNCTION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,11 @@
package com.stal111.forbidden_arcanus.common.effect;

import com.stal111.forbidden_arcanus.core.init.ModMobEffects;
import com.stal111.forbidden_arcanus.util.ModUtils;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.ambient.AmbientCreature;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.phys.AABB;
import net.minecraft.ChatFormatting;

import java.util.List;

/**
* Spectral Eye Effect <br>
* Forbidden Arcanus - com.stal111.forbidden_arcanus.common.effect.SpectralEyeEffect
*
* @author stal111
* @version 1.17.1 - 2.0.0
*/
public class SpectralEyeEffect extends MobEffect {

private static final int EFFECT_RADIUS = 60;

public SpectralEyeEffect(MobEffectCategory effectCategory, int color) {
super(effectCategory, color);
}

@Override
public boolean applyEffectTick(LivingEntity entity, int amplifier) {
int i = entity.getEffect(ModMobEffects.SPECTRAL_VISION).getDuration();
if (!entity.getCommandSenderWorld().isClientSide()) {
Scoreboard scoreboard = entity.getCommandSenderWorld().getServer().getScoreboard();
PlayerTeam teamPassiveOrNeutral = ModUtils.createTeam(scoreboard, "PassiveOrNeutral", ChatFormatting.GREEN);
PlayerTeam teamHostile = ModUtils.createTeam(scoreboard, "Hostile", ChatFormatting.RED);
PlayerTeam teamWater = ModUtils.createTeam(scoreboard, "Water", ChatFormatting.BLUE);

double k = entity.getX();
double l = entity.getY();
double i1 = entity.getZ();

AABB aabb = new AABB(k, l, i1, (k + 1), (l + 1), (i1 + 1)).inflate(EFFECT_RADIUS).expandTowards(0.0D, entity.level().getMaxBuildHeight(), 0.0D);
List<LivingEntity> list = entity.level().getEntitiesOfClass(LivingEntity.class, aabb);

for(LivingEntity livingEntity : list) {
if (livingEntity instanceof Animal || livingEntity instanceof AmbientCreature) {
scoreboard.addPlayerToTeam(livingEntity.getScoreboardName(), teamPassiveOrNeutral);
} else if (livingEntity instanceof Monster) {
scoreboard.addPlayerToTeam(livingEntity.getScoreboardName(), teamHostile);
} else if (!(livingEntity instanceof Player)) {
scoreboard.addPlayerToTeam(livingEntity.getScoreboardName(), teamWater);
}
livingEntity.addEffect(new MobEffectInstance(MobEffects.GLOWING, 5, 0, true, true, false));
}

if (i <= 5) {
ModUtils.removeTeam(scoreboard, teamPassiveOrNeutral);
ModUtils.removeTeam(scoreboard, teamHostile);
ModUtils.removeTeam(scoreboard, teamWater);
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand All @@ -41,7 +40,6 @@ public QuantumCatcherItem(TagKey<EntityType<?>> blacklistedEntities, Properties
this.blacklistedEntities = blacklistedEntities;
}

@NotNull
@Override
public InteractionResult useOn(UseOnContext context) {
ItemStack stack = context.getItemInHand();
Expand Down Expand Up @@ -146,10 +144,8 @@ private static void playSound(Level level, @Nullable Player player, BlockPos pos
}

@Override
public void appendHoverText(@NotNull ItemStack stack, @NotNull TooltipContext context, @NotNull List<Component> components, @NotNull TooltipFlag flag) {
getData(stack).ifPresent(storedEntity -> {
storedEntity.addToTooltip(context, components::add, flag);
});
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> components, TooltipFlag flag) {
stack.addToTooltip(ModDataComponents.STORED_ENTITY, context, components::add, flag);
}

private static Optional<StoredEntity> getData(ItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,52 @@
package com.stal111.forbidden_arcanus.common.item;

import com.stal111.forbidden_arcanus.ForbiddenArcanus;
import net.minecraft.ChatFormatting;
import com.stal111.forbidden_arcanus.common.item.component.ToggleableState;
import com.stal111.forbidden_arcanus.core.init.ModDataComponents;
import com.stal111.forbidden_arcanus.core.init.ModMobEffects;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.List;

/**
* Spectral Eye Amulet Item <br>
* Forbidden Arcanus - com.stal111.forbidden_arcanus.common.item.SpectralEyeAmuletItem
*
* @author stal111
* @version 1.19 - 2.1.0
*/
public class SpectralEyeAmuletItem extends Item {

public SpectralEyeAmuletItem(Item.Properties properties) {
super(properties);
}

@Override
public void inventoryTick(@Nonnull ItemStack stack, Level level, @Nonnull Entity entity, int itemSlot, boolean isSelected) {
if (!level.isClientSide() && !this.isDeactivated(stack) && entity instanceof LivingEntity livingEntity) {
//TODO
//livingEntity.addEffect(new MobEffectInstance(ModMobEffects.SPECTRAL_VISION.get(), 40, 0, false, false, true));
public void inventoryTick(ItemStack stack, Level level, Entity entity, int itemSlot, boolean isSelected) {
if (isActive(stack) && entity instanceof LivingEntity livingEntity) {
livingEntity.addEffect(new MobEffectInstance(BuiltInRegistries.MOB_EFFECT.wrapAsHolder(ModMobEffects.SPECTRAL_VISION.get()), 80, 0, false, false, true));
}
super.inventoryTick(stack, level, entity, itemSlot, isSelected);
}

@Nonnull
@Override
public InteractionResultHolder<ItemStack> use(@Nonnull Level level, Player player, @Nonnull InteractionHand hand) {
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);

this.setDeactivated(stack, !this.isDeactivated(stack));
stack.update(ModDataComponents.TOGGLEABLE_STATE, ToggleableState.DEFAULT, ToggleableState::toggle);

return InteractionResultHolder.sidedSuccess(stack, level.isClientSide());
}

@Override
public void appendHoverText(@NotNull ItemStack stack, @NotNull TooltipContext context, @NotNull List<Component> components, @NotNull TooltipFlag flag) {
super.appendHoverText(stack, context, components, flag);

Component toggle = Component.translatable("tooltip." + ForbiddenArcanus.MOD_ID + ".toggle").withStyle(ChatFormatting.GRAY);

boolean deactivated = this.isDeactivated(stack);
components.add(Component.translatable("tooltip." + ForbiddenArcanus.MOD_ID + (deactivated ? ".deactivated" : ".activated")).withStyle(deactivated ? ChatFormatting.RED : ChatFormatting.GREEN).append(" ").append(toggle));
}

public boolean isDeactivated(ItemStack stack) {
return false;
//TODO
// return stack.getOrCreateTag().getBoolean("Deactivated");
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
stack.addToTooltip(ModDataComponents.TOGGLEABLE_STATE, context, tooltipComponents::add, tooltipFlag);
}

public void setDeactivated(ItemStack stack, boolean deactivated) {
//stack.getOrCreateTag().putBoolean("Deactivated", deactivated);
public static boolean isActive(ItemStack stack) {
return stack.getOrDefault(ModDataComponents.TOGGLEABLE_STATE, ToggleableState.DEFAULT).active();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.TooltipProvider;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -76,6 +76,7 @@ public static StoredEntity of(LivingEntity entity) {
return new StoredEntity(CustomData.of(tag));
}

@Nullable
public Entity createEntity(Level level) {
return EntityType.loadEntityRecursive(this.data.copyTag(), level, Function.identity());
}
Expand All @@ -89,7 +90,7 @@ public Optional<Component> getDisplayName() {
}

@Override
public void addToTooltip(Item.@NotNull TooltipContext context, @NotNull Consumer<Component> consumer, @NotNull TooltipFlag flag) {
public void addToTooltip(Item.TooltipContext context, Consumer<Component> consumer, TooltipFlag flag) {
this.getEntityType().map(type -> Component.translatable(type.getDescriptionId())).ifPresent(type -> {
MutableComponent component = this.getDisplayName()
.map(name -> Component.translatable(STORED_ENTITY_WITH_NAME_KEY, type, name))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.stal111.forbidden_arcanus.common.item.component;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.stal111.forbidden_arcanus.ForbiddenArcanus;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.component.TooltipProvider;

import java.util.function.Consumer;

public record ToggleableState(boolean active, boolean showInTooltip) implements TooltipProvider {

public static final Codec<ToggleableState> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.BOOL.optionalFieldOf("active", true).forGetter(ToggleableState::active),
Codec.BOOL.optionalFieldOf("showInTooltip", true).forGetter(ToggleableState::showInTooltip)
).apply(instance, ToggleableState::new));

public static final StreamCodec<FriendlyByteBuf, ToggleableState> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.BOOL,
ToggleableState::active,
ByteBufCodecs.BOOL,
ToggleableState::showInTooltip,
ToggleableState::new
);

public static final ToggleableState DEFAULT = new ToggleableState(true, true);

private static final Component TOGGLE = Component.translatable(Util.makeDescriptionId("item", ForbiddenArcanus.location("toggle_state"))).withStyle(ChatFormatting.GRAY);
private static final Component TOGGLE_ACTIVATED = Component.translatable(Util.makeDescriptionId("item", ForbiddenArcanus.location("toggle_state.activated"))).withStyle(ChatFormatting.GREEN).append(" ").append(TOGGLE);
private static final Component TOGGLE_DEACTIVATED = Component.translatable(Util.makeDescriptionId("item", ForbiddenArcanus.location("toggle_state.deactivated"))).withStyle(ChatFormatting.RED).append(" ").append(TOGGLE);

public ToggleableState toggle() {
return new ToggleableState(!this.active, this.showInTooltip);
}

@Override
public void addToTooltip(Item.TooltipContext context, Consumer<Component> tooltipAdder, TooltipFlag tooltipFlag) {
if (this.showInTooltip) {
tooltipAdder.accept(this.active ? TOGGLE_ACTIVATED : TOGGLE_DEACTIVATED);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@FieldsAreNonnullByDefault
package com.stal111.forbidden_arcanus.common.item.component;

import net.minecraft.FieldsAreNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.stal111.forbidden_arcanus.common.essence.EssenceData;
import com.stal111.forbidden_arcanus.common.essence.EssenceStorage;
import com.stal111.forbidden_arcanus.common.item.component.StoredEntity;
import com.stal111.forbidden_arcanus.common.item.component.ToggleableState;
import com.stal111.forbidden_arcanus.common.item.enhancer.EnhancerDefinition;
import com.stal111.forbidden_arcanus.common.item.modifier.ItemModifier;
import com.stal111.forbidden_arcanus.core.registry.FARegistries;
Expand Down Expand Up @@ -36,5 +37,6 @@ public class ModDataComponents {
public static final RegistryEntry<DataComponentType<?>, DataComponentType<Integer>> RITUAL_USES = HELPER.register("ritual_uses", () -> DataComponentType.<Integer>builder().persistent(ExtraCodecs.POSITIVE_INT).build());
public static final RegistryEntry<DataComponentType<?>, DataComponentType<Integer>> REMAINING_RITUAL_USES = HELPER.register("remaining_ritual_uses", () -> DataComponentType.<Integer>builder().persistent(ExtraCodecs.NON_NEGATIVE_INT).networkSynchronized(ByteBufCodecs.VAR_INT).build());
public static final RegistryEntry<DataComponentType<?>, DataComponentType<ResourceKey<EnhancerDefinition>>> ENHANCER = HELPER.register("enhancer", () -> DataComponentType.<ResourceKey<EnhancerDefinition>>builder().persistent(ResourceKey.codec(FARegistries.ENHANCER_DEFINITION)).networkSynchronized(ResourceKey.streamCodec(FARegistries.ENHANCER_DEFINITION)).build());
public static final RegistryEntry<DataComponentType<?>, DataComponentType<ToggleableState>> TOGGLEABLE_STATE = HELPER.register("toggleable_state", () -> DataComponentType.<ToggleableState>builder().persistent(ToggleableState.CODEC).networkSynchronized(ToggleableState.STREAM_CODEC).build());

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.stal111.forbidden_arcanus.common.item.bucket.CapacityBucketItem;
import com.stal111.forbidden_arcanus.common.item.bucket.CapacityMilkBucketItem;
import com.stal111.forbidden_arcanus.common.item.bucket.SolidCapacityBucketItem;
import com.stal111.forbidden_arcanus.common.item.component.ToggleableState;
import com.stal111.forbidden_arcanus.common.item.mundabitur.MundabiturDustItem;
import com.stal111.forbidden_arcanus.data.enhancer.ModEnhancerDefinitions;
import com.stal111.forbidden_arcanus.util.ModTags;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class ModItems implements RegistryClass {
public static final ItemRegistryEntry<Item> SILVER_DRAGON_SCALE = HELPER.register("silver_dragon_scale", () -> new Item(new Item.Properties()));
public static final ItemRegistryEntry<Item> GOLDEN_DRAGON_SCALE = HELPER.register("golden_dragon_scale", () -> new Item(new Item.Properties()));
public static final ItemRegistryEntry<Item> AQUATIC_DRAGON_SCALE = HELPER.register("aquatic_dragon_scale", () -> new Item(new Item.Properties()));
public static final ItemRegistryEntry<Item> SPECTRAL_EYE_AMULET = HELPER.register("spectral_eye_amulet", () -> new SpectralEyeAmuletItem(new Item.Properties().rarity(Rarity.RARE).stacksTo(1)));
public static final ItemRegistryEntry<Item> SPECTRAL_EYE_AMULET = HELPER.register("spectral_eye_amulet", () -> new SpectralEyeAmuletItem(new Item.Properties().rarity(Rarity.RARE).stacksTo(1).component(ModDataComponents.TOGGLEABLE_STATE, ToggleableState.DEFAULT)));
public static final ItemRegistryEntry<Item> BAT_WING = HELPER.register("bat_wing", () -> new Item(new Item.Properties().food(ModFoods.BAT_WING)));
public static final ItemRegistryEntry<Item> BAT_SOUP = HELPER.register("bat_soup", () -> new Item(new Item.Properties().stacksTo(1).food(ModFoods.BAT_SOUP)));
public static final ItemRegistryEntry<Item> TENTACLE = HELPER.register("tentacle", () -> new Item(new Item.Properties().food(ModFoods.TENTACLE)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.valhelsia.valhelsia_core.api.common.registry.RegistryClass;
import net.valhelsia.valhelsia_core.api.common.registry.RegistryEntry;
import net.valhelsia.valhelsia_core.api.common.registry.helper.MappedRegistryHelper;

/**
* @author stal111
*/
public class ModMobEffects implements RegistryClass {
public class ModMobEffects {

public static final MappedRegistryHelper<MobEffect> HELPER = ForbiddenArcanus.REGISTRY_MANAGER.getHelper(Registries.MOB_EFFECT);

Expand Down
Loading

0 comments on commit c429884

Please sign in to comment.