mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-17 10:24:23 +01:00
Fix stuff and port enchantments (part 1)
This commit is contained in:
parent
27cecead63
commit
4f03bb81f6
38 changed files with 359 additions and 499 deletions
|
@ -1,6 +1,5 @@
|
|||
package com.minelittlepony.unicopia;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Stack;
|
||||
import java.util.UUID;
|
||||
|
@ -8,6 +7,7 @@ import java.util.UUID;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.container.SpellbookChapter;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.entity.player.dummy.DummyPlayerEntity;
|
||||
import com.minelittlepony.unicopia.particle.ParticleSpawner;
|
||||
|
@ -16,7 +16,6 @@ import com.mojang.authlib.GameProfile;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -52,7 +51,7 @@ public class InteractionManager {
|
|||
return ParticleSpawner.EMPTY;
|
||||
}
|
||||
|
||||
public Map<Identifier, ?> readChapters(PacketByteBuf buf) {
|
||||
public SpellbookChapter readChapter(PacketByteBuf buf) {
|
||||
throw new RuntimeException("Method not supported");
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.entity.Living;
|
|||
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.item.UItems;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
||||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
|
@ -25,7 +26,6 @@ import com.minelittlepony.unicopia.util.VecHelper;
|
|||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
|
@ -125,7 +125,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
|||
player.fallDistance = 0;
|
||||
BlockPos center = PosHelper.findSolidGroundAt(player.getEntityWorld(), player.getBlockPos(), iplayer.getPhysics().getGravitySignum());
|
||||
|
||||
float heavyness = 1 + EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, player);
|
||||
float heavyness = 1 + EnchantmentUtil.getLevel(UEnchantments.HEAVY, player);
|
||||
|
||||
iplayer.asWorld().getOtherEntities(player, areaOfEffect.offset(iplayer.getOriginVector())).forEach(i -> {
|
||||
double dist = Math.sqrt(center.getSquaredDistance(i.getBlockPos()));
|
||||
|
@ -134,7 +134,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
|||
double inertia = 2 / dist;
|
||||
|
||||
if (i instanceof LivingEntity) {
|
||||
inertia *= 1 + EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, (LivingEntity)i);
|
||||
inertia *= 1 + EnchantmentUtil.getLevel(UEnchantments.HEAVY, (LivingEntity)i);
|
||||
}
|
||||
inertia /= heavyness;
|
||||
|
||||
|
@ -159,7 +159,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
if (i instanceof LivingEntity) {
|
||||
amount /= 1 + (EnchantmentHelper.getEquipmentLevel(UEnchantments.PADDED, (LivingEntity)i) / 6F);
|
||||
amount /= 1 + (EnchantmentUtil.getLevel(UEnchantments.PADDED, (LivingEntity)i) / 6F);
|
||||
}
|
||||
|
||||
i.damage(iplayer.damageOf(UDamageTypes.SMASH, iplayer), (float)amount);
|
||||
|
|
|
@ -5,10 +5,10 @@ import org.jetbrains.annotations.Nullable;
|
|||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.entity.effect.EffectUtils;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
@ -44,7 +44,7 @@ public interface AttractionUtils {
|
|||
center = target.getPos().subtract(center).normalize().multiply(force);
|
||||
|
||||
if (target instanceof LivingEntity) {
|
||||
center = center.multiply(1 / (1 + EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, (LivingEntity)target)));
|
||||
center = center.multiply(1 / (1 + EnchantmentUtil.getLevel(UEnchantments.HEAVY, (LivingEntity)target)));
|
||||
}
|
||||
|
||||
target.addVelocity(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.minelittlepony.unicopia.client;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
@ -18,6 +17,7 @@ import com.minelittlepony.unicopia.client.gui.DismissSpellScreen;
|
|||
import com.minelittlepony.unicopia.client.gui.spellbook.ClientChapters;
|
||||
import com.minelittlepony.unicopia.client.particle.ClientBoundParticleSpawner;
|
||||
import com.minelittlepony.unicopia.client.sound.*;
|
||||
import com.minelittlepony.unicopia.container.SpellbookChapter;
|
||||
import com.minelittlepony.unicopia.entity.player.PlayerPhysics;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.entity.player.dummy.DummyClientPlayerEntity;
|
||||
|
@ -41,7 +41,6 @@ import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
|||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
@ -54,8 +53,8 @@ public class ClientInteractionManager extends InteractionManager {
|
|||
private final Int2ObjectMap<WeakReference<TickableSoundInstance>> playingSounds = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<Identifier, ?> readChapters(PacketByteBuf buffer) {
|
||||
return buffer.readMap(PacketByteBuf::readIdentifier, ClientChapters::loadChapter);
|
||||
public SpellbookChapter readChapter(PacketByteBuf buffer) {
|
||||
return ClientChapters.loadChapter(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,22 +3,24 @@ package com.minelittlepony.unicopia.client.gui.spellbook;
|
|||
import java.util.*;
|
||||
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*;
|
||||
import com.minelittlepony.unicopia.client.gui.spellbook.element.DynamicContent;
|
||||
import com.minelittlepony.unicopia.container.SpellbookChapter;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.*;
|
||||
|
||||
public class ClientChapters {
|
||||
private static Map<Identifier, Chapter> CHAPTERS = new HashMap<>();
|
||||
private static Map<Identifier, Chapter> CHAPTERS = Map.of();
|
||||
|
||||
public static Set<SpellbookChapterList.Chapter> getChapters() {
|
||||
return new HashSet<>(CHAPTERS.values());
|
||||
public static Map<Identifier, Chapter> getChapters() {
|
||||
return CHAPTERS;
|
||||
}
|
||||
|
||||
public static void load(Map<Identifier, Chapter> chapters) {
|
||||
CHAPTERS = chapters;
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static void load(Map<Identifier, SpellbookChapter> chapters) {
|
||||
CHAPTERS = (Map)chapters;
|
||||
}
|
||||
|
||||
public static Chapter loadChapter(PacketByteBuf buffer) {
|
||||
public static SpellbookChapter loadChapter(PacketByteBuf buffer) {
|
||||
return new Chapter(
|
||||
buffer.readIdentifier(),
|
||||
buffer.readEnumConstant(TabSide.class),
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.util.stream.Stream;
|
|||
|
||||
import com.minelittlepony.common.client.gui.IViewRoot;
|
||||
import com.minelittlepony.unicopia.Debug;
|
||||
import com.minelittlepony.unicopia.container.SpellbookChapter;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
|
@ -19,9 +21,7 @@ public class SpellbookChapterList {
|
|||
public SpellbookChapterList(SpellbookScreen screen, Chapter craftingChapter, Chapter... builtIn) {
|
||||
this.screen = screen;
|
||||
this.craftingChapter = craftingChapter;
|
||||
ClientChapters.getChapters().forEach(chapter -> {
|
||||
chapters.put(chapter.id(), chapter);
|
||||
});
|
||||
chapters.putAll(ClientChapters.getChapters());
|
||||
chapters.put(craftingChapter.id(), craftingChapter);
|
||||
for (Chapter i : builtIn) {
|
||||
chapters.put(i.id(), i);
|
||||
|
@ -34,11 +34,13 @@ public class SpellbookChapterList {
|
|||
|
||||
public Chapter getCurrentChapter() {
|
||||
if (Debug.SPELLBOOK_CHAPTERS) {
|
||||
ClientChapters.getChapters().forEach(chapter -> {
|
||||
Optional.ofNullable(chapters.get(chapter.id())).flatMap(Chapter::content).ifPresent(old -> {
|
||||
chapter.content().ifPresent(neu -> neu.copyStateFrom(old));
|
||||
ClientChapters.getChapters().forEach((id, chapter) -> {
|
||||
chapters.compute(id, (key, old) -> {
|
||||
Optional.ofNullable(old).flatMap(Chapter::content).ifPresent(o -> {
|
||||
chapter.content().ifPresent(neu -> neu.copyStateFrom(o));
|
||||
});
|
||||
return chapter;
|
||||
});
|
||||
chapters.put(chapter.id(), chapter);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -50,7 +52,7 @@ public class SpellbookChapterList {
|
|||
TabSide side,
|
||||
int tabY,
|
||||
int color,
|
||||
Optional<Content> content) {
|
||||
Optional<Content> content) implements SpellbookChapter {
|
||||
|
||||
public static Identifier createIcon(Identifier id, String suffex) {
|
||||
return id.withPath(p -> "textures/gui/container/pages/" + p + suffex + ".png");
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.client.gui.DrawContext;
|
|||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TextCodecs;
|
||||
import net.minecraft.util.*;
|
||||
|
||||
public class DynamicContent implements Content {
|
||||
|
@ -102,7 +103,7 @@ public class DynamicContent implements Content {
|
|||
private Bounds bounds = Bounds.empty();
|
||||
|
||||
public Page(PacketByteBuf buffer) {
|
||||
title = buffer.readText();
|
||||
title = TextCodecs.PACKET_CODEC.decode(buffer);
|
||||
level = buffer.readInt();
|
||||
color = buffer.readInt();
|
||||
elements = buffer.readList(r -> PageElement.read(this, r));
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.network.PacketByteBuf;
|
|||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TextCodecs;
|
||||
|
||||
public interface PageElement extends Drawable {
|
||||
@Override
|
||||
|
@ -47,7 +48,7 @@ public interface PageElement extends Drawable {
|
|||
case 0 -> new Image(buffer.readIdentifier(), boundsFromBuffer(buffer), buffer.readEnumConstant(Flow.class));
|
||||
case 1 -> new Recipe(page, buffer.readIdentifier(), Bounds.empty());
|
||||
case 2 -> new Stack(page, IngredientWithSpell.PACKET_CODEC.decode((RegistryByteBuf)buffer), boundsFromBuffer(buffer));
|
||||
case 3 -> new TextBlock(page, List.of(Suppliers.ofInstance(buffer.readText())));
|
||||
case 3 -> new TextBlock(page, List.of(Suppliers.ofInstance(TextCodecs.PACKET_CODEC.decode(buffer))));
|
||||
case 4 -> new TextBlock(page, buffer.readList(b -> {
|
||||
int count = b.readVarInt();
|
||||
byte t = b.readByte();
|
||||
|
@ -55,8 +56,8 @@ public interface PageElement extends Drawable {
|
|||
case 1 -> formatLine(capture(b.readIdentifier(), id -> {
|
||||
return Registries.ITEM.get(id).getDefaultStack().getName();
|
||||
}), "item", count);
|
||||
case 2 -> formatLine(Trait.fromId(b.readIdentifier()).orElseThrow()::getShortName, "trait", count);
|
||||
case 3 -> Suppliers.ofInstance(b.readText());
|
||||
case 2 -> formatLine(Trait.PACKET_CODEC.decode(b)::getShortName, "trait", count);
|
||||
case 3 -> Suppliers.ofInstance(TextCodecs.PACKET_CODEC.decode(b));
|
||||
case 4 -> formatLine(SpellType.getKey(b.readIdentifier())::getName, "spell", count);
|
||||
default -> throw new IllegalArgumentException("Unexpected value: " + t);
|
||||
};
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.minelittlepony.unicopia.client.sound;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.minelittlepony.unicopia.USounds;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.item.enchantment.SimpleEnchantment;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
|
@ -28,7 +25,7 @@ public class MagicAuraSoundInstance extends FadeOutSoundInstance {
|
|||
|
||||
@Override
|
||||
protected boolean shouldKeepPlaying() {
|
||||
Optional<SimpleEnchantment.Data> data = living.getEnchants().getOrEmpty(UEnchantments.GEM_FINDER);
|
||||
var data = living.getEnchants().getOrEmpty(UEnchantments.GEM_FINDER);
|
||||
|
||||
Vec3d pos = living.getOriginVector();
|
||||
x = pos.x;
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.stream.Stream;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.container.SpellbookScreenHandler;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.network.Channel;
|
||||
import com.minelittlepony.unicopia.network.MsgTrinketBroken;
|
||||
|
@ -16,7 +17,6 @@ import dev.emi.trinkets.TrinketSlot;
|
|||
import dev.emi.trinkets.api.*;
|
||||
import dev.emi.trinkets.api.TrinketEnums.DropRule;
|
||||
import dev.emi.trinkets.api.event.TrinketDropCallback;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Equipment;
|
||||
|
@ -36,7 +36,7 @@ public class TrinketsDelegateImpl implements TrinketsDelegate {
|
|||
@Override
|
||||
public void bootstrap() {
|
||||
TrinketDropCallback.EVENT.register((rule, stack, ref, entity) -> {
|
||||
if (EnchantmentHelper.getLevel(UEnchantments.HEART_BOUND, stack) > 0) {
|
||||
if (EnchantmentUtil.getLevel(UEnchantments.HEART_BOUND, stack) > 0) {
|
||||
return DropRule.KEEP;
|
||||
}
|
||||
return rule;
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.entity.ItemTracker;
|
|||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.item.FriendshipBraceletItem;
|
||||
import com.minelittlepony.unicopia.item.WearableItem;
|
||||
import com.minelittlepony.unicopia.item.component.Issuer;
|
||||
|
||||
import dev.emi.trinkets.api.*;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
|
@ -66,7 +67,7 @@ public class UnicopiaTrinket implements Trinket {
|
|||
|
||||
@Override
|
||||
public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity) {
|
||||
if (item instanceof FriendshipBraceletItem && !FriendshipBraceletItem.isSigned(stack)) {
|
||||
if (item instanceof FriendshipBraceletItem && !Issuer.isSigned(stack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.minelittlepony.unicopia.container;
|
||||
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
|
||||
public interface SpellbookChapter {
|
||||
PacketCodec<RegistryByteBuf, SpellbookChapter> PACKET_CODEC = PacketCodec.ofStatic(
|
||||
(buffer, chapter) -> ((SpellbookChapterLoader.Chapter)chapter).write(buffer),
|
||||
buffer -> InteractionManager.getInstance().readChapter(buffer)
|
||||
);
|
||||
}
|
|
@ -44,7 +44,7 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
|
|||
public static final SpellbookChapterLoader INSTANCE = new SpellbookChapterLoader();
|
||||
|
||||
private boolean dirty;
|
||||
private Map<Identifier, Chapter> chapters = new HashMap<>();
|
||||
private Map<Identifier, SpellbookChapter> chapters = new HashMap<>();
|
||||
|
||||
public SpellbookChapterLoader() {
|
||||
super(Resources.GSON, ID.getPath());
|
||||
|
@ -55,17 +55,14 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
|
|||
return ID;
|
||||
}
|
||||
|
||||
public Map<Identifier, Chapter> getChapters() {
|
||||
public Map<Identifier, SpellbookChapter> getChapters() {
|
||||
return chapters;
|
||||
}
|
||||
|
||||
public void sendUpdate(MinecraftServer server) {
|
||||
if (dirty) {
|
||||
dirty = false;
|
||||
MsgServerResources msg = new MsgServerResources();
|
||||
server.getWorlds().forEach(world -> {
|
||||
Channel.SERVER_RESOURCES.sendToAllPlayers(msg, world);
|
||||
});
|
||||
Channel.SERVER_RESOURCES.sendToAllPlayers(new MsgServerResources(), server);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +101,7 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
|
|||
TabSide side,
|
||||
int tabY,
|
||||
int color,
|
||||
List<Page> pages) {
|
||||
List<Page> pages) implements SpellbookChapter {
|
||||
@Deprecated
|
||||
public Chapter(Identifier id, JsonObject json) {
|
||||
this(id,
|
||||
|
|
|
@ -41,6 +41,7 @@ import net.minecraft.predicate.item.EnchantmentsPredicate;
|
|||
import net.minecraft.predicate.item.ItemPredicate;
|
||||
import net.minecraft.predicate.item.ItemSubPredicateTypes;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
|
@ -55,17 +56,17 @@ public class UAdvancementsProvider extends FabricAdvancementProvider {
|
|||
@Override
|
||||
public void generateAdvancement(WrapperLookup registryLookup, Consumer<AdvancementEntry> consumer) {
|
||||
AdvancementDisplayBuilder.create(UItems.ALICORN_BADGE).criterion("crafting_table", hasItems(Items.CRAFTING_TABLE)).build(consumer, "root").children(root -> {
|
||||
createTribeRootAdvancement(consumer, root, Race.EARTH).children(consumer, this::generateEarthTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(consumer, root, Race.BAT).children(consumer, this::generateBatTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(consumer, root, Race.PEGASUS).children(consumer, this::generatePegasusTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(consumer, root, Race.UNICORN, Race.ALICORN).children(consumer, this::generateUnicornTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(consumer, root, Race.HIPPOGRIFF, Race.SEAPONY).children(consumer, this::generateHippogrifTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(registryLookup, consumer, root, Race.EARTH).children(consumer, this::generateEarthTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(registryLookup, consumer, root, Race.BAT).children(consumer, this::generateBatTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(registryLookup, consumer, root, Race.PEGASUS).children(consumer, this::generatePegasusTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(registryLookup, consumer, root, Race.UNICORN, Race.ALICORN).children(consumer, this::generateUnicornTribeAdvancementsTree);
|
||||
createTribeRootAdvancement(registryLookup, consumer, root, Race.HIPPOGRIFF, Race.SEAPONY).children(consumer, this::generateHippogrifTribeAdvancementsTree);
|
||||
});
|
||||
|
||||
generateEnchantmentsAdvancementsTree(consumer);
|
||||
generateEnchantmentsAdvancementsTree(registryLookup ,consumer);
|
||||
}
|
||||
|
||||
private AdvancementDisplayBuilder.Parent createTribeRootAdvancement(Consumer<AdvancementEntry> consumer, AdvancementDisplayBuilder.Parent root, Race race, Race...extra) {
|
||||
private AdvancementDisplayBuilder.Parent createTribeRootAdvancement(WrapperLookup registryLookup, Consumer<AdvancementEntry> consumer, AdvancementDisplayBuilder.Parent root, Race race, Race...extra) {
|
||||
AdvancementDisplayBuilder builder = root.child(Registries.ITEM.get(race.getId().withSuffixedPath("_badge"))).showToast().announce().group(race.getId().getPath())
|
||||
.criterion("be_" + race.getId().getPath(), UCriteria.PLAYER_CHANGE_RACE.create(new RaceChangeCriterion.Conditions(Optional.empty(), race)));
|
||||
|
||||
|
@ -198,9 +199,10 @@ public class UAdvancementsProvider extends FabricAdvancementProvider {
|
|||
.child(UItems.PEARL_NECKLACE).showToast().announce().criterion("seapony_transition", UCriteria.CUSTOM_EVENT.create(new CustomEventCriterion.Conditions(Optional.empty(), "seapony_transition", RacePredicate.of(Set.of(), Set.of(Race.SEAPONY)), TriState.DEFAULT, 1))).build(consumer, "shoo_be_done");
|
||||
}
|
||||
|
||||
private void generateEnchantmentsAdvancementsTree(Consumer<AdvancementEntry> consumer) {
|
||||
private void generateEnchantmentsAdvancementsTree(WrapperLookup registryLookup, Consumer<AdvancementEntry> consumer) {
|
||||
var enchantments = registryLookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT);
|
||||
AdvancementDisplayBuilder.create(Items.NETHERITE_SCRAP).showToast().announce()
|
||||
.criterion("enchant_with_consumption", enchant(UEnchantments.CONSUMPTION))
|
||||
.criterion("enchant_with_consumption", enchant(enchantments.getOrThrow(UEnchantments.CONSUMPTION)))
|
||||
.rewards(AdvancementRewards.Builder.experience(120))
|
||||
.parent(Identifier.ofVanilla("story/enchant_item"))
|
||||
.group("enchanting")
|
||||
|
@ -212,7 +214,7 @@ public class UAdvancementsProvider extends FabricAdvancementProvider {
|
|||
.hidden()
|
||||
.build(consumer, "xp_miner");
|
||||
AdvancementDisplayBuilder.create(Items.GOLDEN_APPLE).showToast().announce()
|
||||
.criterion("enchant_with_heart_bound", enchant(UEnchantments.HEART_BOUND))
|
||||
.criterion("enchant_with_heart_bound", enchant(enchantments.getOrThrow(UEnchantments.HEART_BOUND)))
|
||||
.rewards(AdvancementRewards.Builder.experience(120))
|
||||
.parent(Identifier.ofVanilla("story/enchant_item"))
|
||||
.group("enchanting")
|
||||
|
|
|
@ -60,7 +60,7 @@ public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvid
|
|||
|
||||
public LootCondition.Builder createWithGemFinderCondition() {
|
||||
return MatchToolLootCondition.builder(ItemPredicate.Builder.create().subPredicate(ItemSubPredicateTypes.ENCHANTMENTS, EnchantmentsPredicate.enchantments(List.of(
|
||||
new EnchantmentPredicate(UEnchantments.GEM_FINDER, NumberRange.IntRange.atLeast(1))
|
||||
new EnchantmentPredicate(entryOf(UEnchantments.GEM_FINDER), NumberRange.IntRange.atLeast(1))
|
||||
))));
|
||||
}
|
||||
|
||||
|
|
|
@ -39,18 +39,7 @@ public class PonyDiets implements DietView {
|
|||
PonyDiets::new
|
||||
);
|
||||
|
||||
/*public static final PacketCodec<RegistryByteBuf, PonyDiets> PACKET_CODEC = PacketCodec.ofStatic((buffer, diets) -> {
|
||||
buffer.writeMap(diets.diets, (b, r) -> b.writeRegistryKey(Race.REGISTRY.getKey(r).get()), (b, e) -> e.toBuffer(b));
|
||||
buffer.writeCollection(diets.effects.values(), (b, e) -> e.toBuffer(b));
|
||||
}, buffer -> {
|
||||
return new PonyDiets(
|
||||
buffer.readMap(b -> Race.REGISTRY.get(b.readRegistryKey(Race.REGISTRY_KEY)), DietProfile::new),
|
||||
FoodGroup.PACKET_CODEC.collect(PacketCodecUtils.toMap(FoodGroup::id)).decode(buffer)
|
||||
);
|
||||
});*/
|
||||
|
||||
public static PonyDiets getInstance() {
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.function.Supplier;
|
|||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.item.enchantment.SimpleEnchantment;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||
import com.minelittlepony.unicopia.util.Tickable;
|
||||
|
@ -21,59 +20,61 @@ import net.minecraft.nbt.NbtElement;
|
|||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
// TODO: Use a EnchantmentLocationBasedEffect for this instead
|
||||
@Deprecated
|
||||
public class Enchantments implements NbtSerialisable, Tickable {
|
||||
|
||||
private final Living<?> entity;
|
||||
|
||||
private final Set<RegistryEntry<Enchantment>> equippedEnchantments = new HashSet<>();
|
||||
private final Set<RegistryKey<Enchantment>> equippedEnchantments = new HashSet<>();
|
||||
|
||||
private final Map<RegistryEntry<Enchantment>, SimpleEnchantment.Data> data = new HashMap<>();
|
||||
private final Map<RegistryKey<Enchantment>, Data> data = new HashMap<>();
|
||||
|
||||
Enchantments(Living<?> entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends SimpleEnchantment.Data> Optional<T> getOrEmpty(RegistryEntry<Enchantment> enchantment) {
|
||||
public <T extends Data> Optional<T> getOrEmpty(RegistryKey<Enchantment> enchantment) {
|
||||
return Optional.ofNullable((T)data.get(enchantment));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends SimpleEnchantment.Data> T computeIfAbsent(RegistryEntry<Enchantment> enchantment, Supplier<T> factory) {
|
||||
public <T extends Data> T computeIfAbsent(RegistryKey<Enchantment> enchantment, Supplier<T> factory) {
|
||||
return (T)data.computeIfAbsent(enchantment, e -> factory.get());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends SimpleEnchantment.Data> T remove(RegistryEntry<Enchantment> enchantment) {
|
||||
public <T extends Data> T remove(RegistryKey<Enchantment> enchantment) {
|
||||
return (T)data.remove(enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
UEnchantments.REGISTRY.forEach(ench -> {
|
||||
UEnchantments.REGISTRY.forEach(key -> {
|
||||
var ench = entity.entryFor(key);
|
||||
int level = EnchantmentHelper.getEquipmentLevel(ench, entity.asEntity());
|
||||
|
||||
boolean active = level > 0;
|
||||
|
||||
if (active != equippedEnchantments.contains(ench)) {
|
||||
if (active != equippedEnchantments.contains(key)) {
|
||||
if (active) {
|
||||
equippedEnchantments.add(ench);
|
||||
ench.value().onEquipped(entity);
|
||||
equippedEnchantments.add(key);
|
||||
ench.value().applyLocationBasedEffects((ServerWorld)entity.asWorld(), level, null, entity.asEntity());
|
||||
} else {
|
||||
equippedEnchantments.remove(ench);
|
||||
ench.value().onUnequipped(entity);
|
||||
equippedEnchantments.remove(key);
|
||||
ench.value().removeLocationBasedEffects(level, null, entity.asEntity());
|
||||
}
|
||||
}
|
||||
|
||||
if (active) {
|
||||
ench.value().onUserTick(entity, level);
|
||||
ench.value().onTick((ServerWorld)entity.asWorld(), level, null, entity.asEntity());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -81,10 +82,8 @@ public class Enchantments implements NbtSerialisable, Tickable {
|
|||
@Override
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
NbtList list = new NbtList();
|
||||
equippedEnchantments.forEach(enchant -> {
|
||||
enchant.getKey().ifPresent(key -> {
|
||||
list.add(NbtString.of(key.getValue().toString()));
|
||||
});
|
||||
equippedEnchantments.forEach(key -> {
|
||||
list.add(NbtString.of(key.getValue().toString()));
|
||||
});
|
||||
compound.put("enchants", list);
|
||||
}
|
||||
|
@ -94,10 +93,12 @@ public class Enchantments implements NbtSerialisable, Tickable {
|
|||
equippedEnchantments.clear();
|
||||
if (compound.contains("enchants")) {
|
||||
compound.getList("enchants", NbtElement.STRING_TYPE).forEach(tag -> {
|
||||
lookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT)
|
||||
.getOptional(RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of(tag.asString())))
|
||||
.ifPresent(equippedEnchantments::add);
|
||||
equippedEnchantments.add(RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of(tag.asString())));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
public float level;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.entity;
|
|||
import java.util.List;
|
||||
|
||||
import com.minelittlepony.unicopia.*;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.item.enchantment.WantItNeedItEnchantment;
|
||||
import com.minelittlepony.unicopia.network.track.DataTracker;
|
||||
|
@ -12,7 +13,6 @@ import com.minelittlepony.unicopia.particle.FollowingParticleEffect;
|
|||
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
||||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.decoration.ItemFrameEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -203,9 +203,7 @@ public class ItemImpl implements Equine<ItemEntity> {
|
|||
}
|
||||
|
||||
public interface ClingyItem {
|
||||
ClingyItem DEFAULT = stack -> {
|
||||
return EnchantmentHelper.getLevel(UEnchantments.CLINGY, stack) > 0;
|
||||
};
|
||||
ClingyItem DEFAULT = stack -> EnchantmentUtil.getLevel(UEnchantments.CLINGY, stack) > 0;
|
||||
|
||||
boolean isClingy(ItemStack stack);
|
||||
|
||||
|
@ -215,11 +213,11 @@ public class ItemImpl implements Equine<ItemEntity> {
|
|||
}
|
||||
|
||||
default float getFollowDistance(IItemEntity entity) {
|
||||
return 6 * (1 + EnchantmentHelper.getLevel(UEnchantments.CLINGY, entity.get().asEntity().getStack()));
|
||||
return 6 * (1 + EnchantmentUtil.getLevel(UEnchantments.CLINGY, entity.get().asEntity().getStack()));
|
||||
}
|
||||
|
||||
default float getFollowSpeed(IItemEntity entity) {
|
||||
return Math.min(1, 0.02F * (1 + EnchantmentHelper.getLevel(UEnchantments.CLINGY, entity.get().asEntity().getStack())));
|
||||
return Math.min(1, 0.02F * (1 + EnchantmentUtil.getLevel(UEnchantments.CLINGY, entity.get().asEntity().getStack())));
|
||||
}
|
||||
|
||||
default void interactWithPlayer(IItemEntity entity, PlayerEntity player) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.minelittlepony.unicopia.input.Heuristic;
|
|||
import com.minelittlepony.unicopia.input.Interactable;
|
||||
import com.minelittlepony.unicopia.item.GlassesItem;
|
||||
import com.minelittlepony.unicopia.item.UItems;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.network.track.DataTracker;
|
||||
import com.minelittlepony.unicopia.network.track.DataTrackerManager;
|
||||
|
@ -197,7 +198,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
|
||||
@Override
|
||||
public boolean hasFeatherTouch() {
|
||||
return EnchantmentHelper.getEquipmentLevel(UEnchantments.FEATHER_TOUCH, entity) > 0;
|
||||
return EnchantmentUtil.getLevel(UEnchantments.FEATHER_TOUCH, entity) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.minelittlepony.unicopia.entity.ai;
|
|||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.ai.brain.MemoryModuleType;
|
||||
import net.minecraft.entity.ai.brain.sensor.Sensor;
|
||||
|
@ -22,7 +22,7 @@ public class WantItNeedItSensor extends Sensor<LivingEntity> {
|
|||
protected void sense(ServerWorld world, LivingEntity entity) {
|
||||
entity.getBrain().getOptionalMemory(MemoryModuleType.VISIBLE_MOBS).ifPresent(targets -> {
|
||||
entity.getBrain().remember(MemoryModuleType.ATTACK_TARGET, targets
|
||||
.findFirst(e -> (EnchantmentHelper.getEquipmentLevel(UEnchantments.WANT_IT_NEED_IT, e) * 10) >= entity.distanceTo(e)));
|
||||
.findFirst(e -> (EnchantmentUtil.getLevel(UEnchantments.WANT_IT_NEED_IT, e) * 10) >= entity.distanceTo(e)));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.entity.ai;
|
|||
import com.minelittlepony.unicopia.AwaitTickQueue;
|
||||
import com.minelittlepony.unicopia.EquinePredicates;
|
||||
import com.minelittlepony.unicopia.entity.Creature;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.item.enchantment.WantItNeedItEnchantment;
|
||||
import com.minelittlepony.unicopia.particle.FollowingParticleEffect;
|
||||
|
@ -10,7 +11,6 @@ import com.minelittlepony.unicopia.particle.ParticleUtils;
|
|||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
|
@ -77,7 +77,7 @@ public class WantItTakeItGoal extends BreakHeartGoal {
|
|||
if (mob.getWorld().random.nextInt(20) == 0) {
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
ItemStack stack = living.getEquippedStack(slot);
|
||||
if (EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, stack) > 0) {
|
||||
if (EnchantmentUtil.getLevel(UEnchantments.WANT_IT_NEED_IT, stack) > 0) {
|
||||
AwaitTickQueue.scheduleTask(mob.getWorld(), w -> {
|
||||
living.equipStack(slot, ItemStack.EMPTY);
|
||||
mob.tryEquip(stack);
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.minelittlepony.unicopia.input.Heuristic;
|
|||
import com.minelittlepony.unicopia.item.AmuletItem;
|
||||
import com.minelittlepony.unicopia.item.ChargeableItem;
|
||||
import com.minelittlepony.unicopia.item.UItems;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.network.Channel;
|
||||
import com.minelittlepony.unicopia.network.MsgPlayerFlightControlsInput;
|
||||
|
@ -37,7 +38,6 @@ import com.minelittlepony.unicopia.util.*;
|
|||
|
||||
import net.fabricmc.fabric.api.tag.convention.v2.ConventionalBlockTags;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LightningEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
@ -387,7 +387,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
|||
velocity.z = MathHelper.clamp(velocity.z, -maximum, maximum);
|
||||
|
||||
if (!entity.isOnGround()) {
|
||||
float heavyness = 1 + EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) * 0.009F;
|
||||
float heavyness = 1 + EnchantmentUtil.getLevel(UEnchantments.HEAVY, entity) * 0.009F;
|
||||
velocity.x /= heavyness;
|
||||
velocity.z /= heavyness;
|
||||
}
|
||||
|
@ -650,7 +650,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
|||
|
||||
float distance = (float)(motion * 20 - 3);
|
||||
|
||||
float bouncyness = EnchantmentHelper.getEquipmentLevel(UEnchantments.PADDED, entity) * 6;
|
||||
float bouncyness = EnchantmentUtil.getLevel(UEnchantments.PADDED, entity) * 6;
|
||||
|
||||
if (distance > 0) {
|
||||
wallHitCooldown = MAX_WALL_HIT_CALLDOWN;
|
||||
|
@ -746,7 +746,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
|||
}
|
||||
}
|
||||
|
||||
float heavyness = EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity);
|
||||
float heavyness = EnchantmentUtil.getLevel(UEnchantments.HEAVY, entity);
|
||||
float thrustStrength = 0.235F * thrustScale;
|
||||
|
||||
if (heavyness > 0) {
|
||||
|
@ -787,7 +787,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
|||
SoundEmitter.playSoundAt(entity, USounds.AMBIENT_WIND_GUST, SoundCategory.AMBIENT, 3, 1);
|
||||
}
|
||||
|
||||
float weight = 1 + (EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) * 0.8F) + (pony.getCompositeRace().canUseEarth() ? 1 : 0);
|
||||
float weight = 1 + (EnchantmentUtil.getLevel(UEnchantments.HEAVY, entity) * 0.8F) + (pony.getCompositeRace().canUseEarth() ? 1 : 0);
|
||||
|
||||
Vec3d airflow = WeatherConditions.getAirflow(entity.getBlockPos(), entity.getWorld())
|
||||
.multiply(0.04F * effectStrength)
|
||||
|
|
|
@ -913,7 +913,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
PlayerInventory inventory = oldPlayer.asEntity().getInventory();
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
ItemStack stack = inventory.getStack(i);
|
||||
if (EnchantmentUtil.consumeEnchantment(UEnchantments.HEART_BOUND, 1, stack, entity.getWorld().random, EnchantmentUtil.getLuck(3, oldPlayer.asEntity()))) {
|
||||
if (EnchantmentUtil.consumeEnchantment(entryFor(UEnchantments.HEART_BOUND), 1, stack, entity.getWorld().random, EnchantmentUtil.getLuck(3, oldPlayer.asEntity()))) {
|
||||
asEntity().getInventory().setStack(i, stack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class FriendshipBraceletItem extends WearableItem {
|
|||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
|
||||
if (!isSigned(stack) && (
|
||||
if (!Issuer.isSigned(stack) && (
|
||||
EquinePredicates.PLAYER_UNICORN.test(player)
|
||||
|| EquinePredicates.RACE_CAN_INFLUENCE_WEATHER.test(player)
|
||||
|| AmuletSelectors.PEARL_NECKLACE.test(player)
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
package com.minelittlepony.unicopia.item.enchantment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.attribute.EntityAttribute;
|
||||
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
||||
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
|
||||
// TODO: Replaced with EnchantmentEffectComponentTypes.ATTRIBUTES
|
||||
@Deprecated
|
||||
public class AttributedEnchantment extends SimpleEnchantment {
|
||||
|
||||
private final Map<RegistryEntry<EntityAttribute>, ModifierFactory> modifiers = new HashMap<>();
|
||||
|
||||
protected AttributedEnchantment(Options options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
public AttributedEnchantment addModifier(RegistryEntry<EntityAttribute> attribute, ModifierFactory modifierSupplier) {
|
||||
modifiers.put(attribute, modifierSupplier);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserTick(Living<?> user, int level) {
|
||||
if (shouldChangeModifiers(user, level)) {
|
||||
modifiers.forEach((attr, modifierSupplier) -> {
|
||||
EntityAttributeInstance instance = user.asEntity().getAttributeInstance(attr);
|
||||
|
||||
EntityAttributeModifier modifier = modifierSupplier.get(user, level);
|
||||
|
||||
instance.removeModifier(modifier.id());
|
||||
instance.addPersistentModifier(modifier);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequipped(Living<?> user) {
|
||||
modifiers.forEach((attr, modifierSupplier) -> {
|
||||
EntityAttributeInstance instance = user.asEntity().getAttributeInstance(attr);
|
||||
|
||||
instance.removeModifier(modifierSupplier.get(user, 1).getId());
|
||||
});
|
||||
user.getEnchants().remove(this);
|
||||
}
|
||||
|
||||
public void getModifiers(Living<?> user, int level, Map<EquipmentSlot, Multimap<EntityAttribute, EntityAttributeModifier>> output) {
|
||||
modifiers.forEach((attr, modifierSupplier) -> {
|
||||
EntityAttributeModifier modif = modifierSupplier.get(user, level);
|
||||
|
||||
for (EquipmentSlot slot : getSlots()) {
|
||||
output.computeIfAbsent(slot, s -> HashMultimap.create()).put(attr, modif);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected boolean shouldChangeModifiers(Living<?> user, int level) {
|
||||
return user.getEnchants().computeIfAbsent(this, Data::new).update(level);
|
||||
}
|
||||
|
||||
interface ModifierFactory {
|
||||
EntityAttributeModifier get(Living<?> user, int level);
|
||||
}
|
||||
}
|
|
@ -1,34 +1,32 @@
|
|||
package com.minelittlepony.unicopia.item.enchantment;
|
||||
|
||||
import java.util.UUID;
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.entity.Enchantments;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.entity.attribute.EntityAttributeModifier.Operation;
|
||||
|
||||
public class CollaboratorEnchantment extends AttributedEnchantment {
|
||||
private static final UUID TEAM_STRENGTH_UUID = UUID.fromString("5f08c02d-d959-4763-ac84-16e2acfd4b62");
|
||||
public class CollaboratorEnchantment {
|
||||
private static final Identifier TEAM_STRENGTH_ID = Unicopia.id("team_strength");
|
||||
|
||||
protected CollaboratorEnchantment(Options options) {
|
||||
super(options);
|
||||
addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier);
|
||||
protected CollaboratorEnchantment() {
|
||||
//addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldChangeModifiers(Living<?> user, int level) {
|
||||
return super.shouldChangeModifiers(user, getTeamCollectiveLevel(user, 2 + (level * 2)));
|
||||
return false;//super.shouldChangeModifiers(user, getTeamCollectiveLevel(user, 2 + (level * 2)));
|
||||
}
|
||||
|
||||
private EntityAttributeModifier getModifier(Living<?> user, int level) {
|
||||
return new EntityAttributeModifier(TEAM_STRENGTH_UUID, "Team Strength", user.getEnchants().computeIfAbsent(this, Data::new).level / 2, Operation.ADD_VALUE);
|
||||
return new EntityAttributeModifier(TEAM_STRENGTH_ID, user.getEnchants().computeIfAbsent(UEnchantments.HERDS, Enchantments.Data::new).level / 2, Operation.ADD_VALUE);
|
||||
}
|
||||
|
||||
private int getTeamCollectiveLevel(Living<?> user, int radius) {
|
||||
private static int getTeamCollectiveLevel(Living<?> user, int radius) {
|
||||
return user.findAllEntitiesInRange(radius, e -> e instanceof LivingEntity)
|
||||
.mapToInt(e -> EnchantmentHelper.getEquipmentLevel(this, (LivingEntity)e))
|
||||
.mapToInt(e -> EnchantmentUtil.getLevel(UEnchantments.HERDS, (LivingEntity)e))
|
||||
.reduce((a, b) -> a + b)
|
||||
.orElse(0);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import com.minelittlepony.unicopia.util.VecHelper;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
@ -21,11 +20,7 @@ import net.minecraft.sound.SoundCategory;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ConsumptionEnchantment extends SimpleEnchantment {
|
||||
protected ConsumptionEnchantment(Options options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
public class ConsumptionEnchantment {
|
||||
public static boolean applyConsumption(World w, BlockState state, BlockPos pos, @Nullable BlockEntity blockEntity, Entity entity, ItemStack tool) {
|
||||
|
||||
if (!(w instanceof ServerWorld world)) {
|
||||
|
@ -35,7 +30,8 @@ public class ConsumptionEnchantment extends SimpleEnchantment {
|
|||
if (tool.isEmpty() && entity instanceof LivingEntity l) {
|
||||
tool = l.getMainHandStack();
|
||||
}
|
||||
if (EnchantmentHelper.getLevel(UEnchantments.CONSUMPTION, tool) <= 0) {
|
||||
|
||||
if (EnchantmentUtil.getLevel(w, UEnchantments.CONSUMPTION, tool) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,12 @@ public interface EnchantmentUtil {
|
|||
return (int)MathHelper.clamp(baseline + luckAmplifier + dolphinsGraceAmplifier - unluckAmplifier - badOmenAmplifier, -10, 10);
|
||||
}
|
||||
|
||||
static int getLevel(RegistryKey<Enchantment> enchantment, ItemStack stack) {
|
||||
var enchantments = EnchantmentHelper.getEnchantments(stack);
|
||||
return enchantments.getEnchantments().stream()
|
||||
.filter(entry -> entry.matchesKey(enchantment)).map(enchantments::getLevel).findFirst().orElse(0);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
static int getLevel(World world, RegistryKey<Enchantment> enchantment, ItemStack stack) {
|
||||
return world.getRegistryManager().get(RegistryKeys.ENCHANTMENT).getEntry(Enchantments.LOOTING).map(entry -> {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.item.enchantment;
|
|||
|
||||
import com.minelittlepony.unicopia.UTags;
|
||||
import com.minelittlepony.unicopia.client.sound.MagicAuraSoundInstance;
|
||||
import com.minelittlepony.unicopia.entity.Enchantments;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
@ -9,13 +10,8 @@ import net.fabricmc.api.Environment;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class GemFindingEnchantment extends SimpleEnchantment {
|
||||
public class GemFindingEnchantment {
|
||||
|
||||
protected GemFindingEnchantment(Options options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserTick(Living<?> user, int level) {
|
||||
int radius = 2 + (level * 2);
|
||||
|
||||
|
@ -28,19 +24,16 @@ public class GemFindingEnchantment extends SimpleEnchantment {
|
|||
|
||||
volume = Math.max(volume, 0.04F);
|
||||
|
||||
user.getEnchants().computeIfAbsent(this, Data::new).level = (float)volume * (1.3F + level);
|
||||
user.getEnchants().computeIfAbsent(UEnchantments.GEM_FINDER, Enchantments.Data::new).level = (float)volume * (1.3F + level);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public void onEquipped(Living<?> user) {
|
||||
if (user.isClient()) {
|
||||
MinecraftClient.getInstance().getSoundManager().play(new MagicAuraSoundInstance(user.asEntity().getSoundCategory(), user, user.asWorld().getRandom()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequipped(Living<?> user) {
|
||||
user.getEnchants().remove(this).level = 0;
|
||||
user.getEnchants().remove(UEnchantments.GEM_FINDER).level = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.item.enchantment;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
|
@ -15,8 +14,8 @@ public interface HeartboundEnchantmentUtil {
|
|||
var original = combinedInventory.get(group);
|
||||
for (int i = 0; i < original.size(); i++) {
|
||||
ItemStack stack = original.get(i);
|
||||
if (EnchantmentHelper.getLevel(Enchantments.BINDING_CURSE, stack) == 0
|
||||
&& EnchantmentHelper.getLevel(UEnchantments.HEART_BOUND, stack) > 0) {
|
||||
if (EnchantmentUtil.getLevel(Enchantments.BINDING_CURSE, stack) == 0
|
||||
&& EnchantmentUtil.getLevel(UEnchantments.HEART_BOUND, stack) > 0) {
|
||||
original.set(i, ItemStack.EMPTY);
|
||||
storedCombinedInventory.get(group).set(i, stack);
|
||||
empty = false;
|
||||
|
|
|
@ -1,37 +1,14 @@
|
|||
package com.minelittlepony.unicopia.item.enchantment;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||
|
||||
import com.minelittlepony.unicopia.UTags;
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.entity.Enchantments;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.util.RegistryUtils;
|
||||
import com.minelittlepony.unicopia.util.Resources;
|
||||
|
||||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.util.profiler.Profiler;
|
||||
import net.minecraft.registry.Registries;
|
||||
|
||||
public class PoisonedJokeEnchantment extends SimpleEnchantment {
|
||||
public class PoisonedJokeEnchantment {
|
||||
|
||||
protected PoisonedJokeEnchantment(Options options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserTick(Living<?> user, int level) {
|
||||
if (user.asWorld().isClient) {
|
||||
return;
|
||||
|
@ -39,7 +16,7 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment {
|
|||
|
||||
int light = user.asWorld().getLightLevel(user.asEntity().getRootVehicle().getBlockPos());
|
||||
Random rng = user.asWorld().random;
|
||||
Data data = user.getEnchants().computeIfAbsent(this, Data::new);
|
||||
Enchantments.Data data = user.getEnchants().computeIfAbsent(UEnchantments.POISONED_JOKE, Enchantments.Data::new);
|
||||
|
||||
data.level -= rng.nextFloat() * 0.8F;
|
||||
if (rng.nextInt(Math.max(1, (light * 9) + (int)data.level)) == 0) {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.minelittlepony.unicopia.item.enchantment;
|
||||
|
||||
public interface Rarity {
|
||||
int COMMON = 10;
|
||||
int UNCOMMON = 5;
|
||||
int RARE = 2;
|
||||
int VERY_RARE = 1;
|
||||
}
|
|
@ -1,165 +0,0 @@
|
|||
package com.minelittlepony.unicopia.item.enchantment;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@Deprecated
|
||||
public class SimpleEnchantment extends Enchantment {
|
||||
|
||||
private final Options options;
|
||||
|
||||
protected SimpleEnchantment(Options options) {
|
||||
super(options.rarity, options.target, options.slots);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public void onUserTick(Living<?> user, int level) {
|
||||
|
||||
}
|
||||
|
||||
public void onEquipped(Living<?> user) {
|
||||
|
||||
}
|
||||
|
||||
public void onUnequipped(Living<?> user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptableItem(ItemStack itemStack) {
|
||||
return options.allItems || super.isAcceptableItem(itemStack);
|
||||
}
|
||||
|
||||
public EquipmentSlot[] getSlots() {
|
||||
return options.slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getMaxLevel() {
|
||||
return options.maxLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isCursed() {
|
||||
return options.cursed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isTreasure() {
|
||||
return options.treasured;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isAvailableForEnchantedBookOffer() {
|
||||
return options.traded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isAvailableForRandomSelection() {
|
||||
return options.table;
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
public float level;
|
||||
|
||||
public boolean update(int level) {
|
||||
if (level == this.level) {
|
||||
return false;
|
||||
}
|
||||
this.level = level;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Options {
|
||||
private boolean cursed;
|
||||
private boolean treasured;
|
||||
private boolean traded;
|
||||
private boolean table;
|
||||
private Rarity rarity;
|
||||
private int maxLevel = 1;
|
||||
private EquipmentSlot[] slots;
|
||||
private EnchantmentTarget target;
|
||||
private boolean allItems;
|
||||
|
||||
public static Options create(EnchantmentTarget target, EquipmentSlot... slots) {
|
||||
return new Options(target, slots);
|
||||
}
|
||||
|
||||
public static Options armor() {
|
||||
return create(EnchantmentTarget.ARMOR, UEnchantmentValidSlots.ARMOR);
|
||||
}
|
||||
|
||||
public static Options allItems() {
|
||||
return create(EnchantmentTarget.VANISHABLE, UEnchantmentValidSlots.ANY).ignoreTarget();
|
||||
}
|
||||
|
||||
Options(EnchantmentTarget target, EquipmentSlot[] slots) {
|
||||
this.slots = slots;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enchantment to apply to all items.
|
||||
*/
|
||||
public Options ignoreTarget() {
|
||||
allItems = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets how rare this enchantment is when using the enchantment table.
|
||||
* Enchantments with a higher rarity appear less often and costs the user more experience when working with it the anvil.
|
||||
*/
|
||||
public Options rarity(Rarity rarity) {
|
||||
this.rarity = rarity;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this enchantment is considered a negative effect by the game.
|
||||
*
|
||||
* Cursed enchantments are removed when repairing an item
|
||||
* and do not give the user experience points when removed using a grindstone.
|
||||
*/
|
||||
public Options curse() {
|
||||
cursed = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this enchantment should be limited to high value trades or leveled up enchanting table offers.
|
||||
*/
|
||||
public Options treasure() {
|
||||
treasured = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this enchantment should appear in villager trades.
|
||||
*/
|
||||
public Options traded() {
|
||||
this.traded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the enchantment should appear in enchanting table draws.
|
||||
*/
|
||||
public Options table() {
|
||||
this.table = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum level for the enchantment.
|
||||
*/
|
||||
public Options maxLevel(int level) {
|
||||
maxLevel = level;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,13 +7,8 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
|||
|
||||
import net.minecraft.entity.mob.HostileEntity;
|
||||
|
||||
public class StressfulEnchantment extends SimpleEnchantment {
|
||||
public class StressfulEnchantment {
|
||||
|
||||
protected StressfulEnchantment(Options options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserTick(Living<?> user, int level) {
|
||||
if (user instanceof Pony pony && pony.asEntity().age % 10 == 0) {
|
||||
int range = (level + 1) * 3;
|
||||
|
@ -27,7 +22,7 @@ public class StressfulEnchantment extends SimpleEnchantment {
|
|||
}
|
||||
|
||||
Bar bar = pony.getMagicalReserves().getEnergy();
|
||||
float targetPercent = (level / (float)getMaxLevel()) * 0.05125F;
|
||||
float targetPercent = (level / (float)user.entryFor(UEnchantments.STRESSED).value().definition().maxLevel()) * 0.05125F;
|
||||
float increase = 1F + (level * level)/100F;
|
||||
if (bar.getPercentFill() < targetPercent) {
|
||||
bar.add(increase);
|
||||
|
|
|
@ -2,142 +2,279 @@ package com.minelittlepony.unicopia.item.enchantment;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.entity.mob.UEntityAttributes;
|
||||
import com.minelittlepony.unicopia.item.enchantment.SimpleEnchantment.Options;
|
||||
|
||||
import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;
|
||||
import net.minecraft.component.EnchantmentEffectComponentTypes;
|
||||
import net.minecraft.component.type.AttributeModifierSlot;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
|
||||
import net.minecraft.enchantment.effect.AttributeEnchantmentEffect;
|
||||
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.attribute.EntityAttributeModifier.Operation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.tag.EnchantmentTags;
|
||||
import net.minecraft.registry.tag.ItemTags;
|
||||
|
||||
public interface UEnchantments {
|
||||
List<RegistryEntry<Enchantment>> REGISTRY = new ArrayList<>();
|
||||
List<RegistryKey<Enchantment>> REGISTRY = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Makes a sound when there are interesting blocks in your area.
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* - Enchanting Table
|
||||
* EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> GEM_FINDER = register("gem_finder", new GemFindingEnchantment(Options.create(EnchantmentTarget.DIGGER, UEnchantmentValidSlots.HANDS).rarity(Rarity.RARE).maxLevel(3).treasure().traded().table()));
|
||||
RegistryKey<Enchantment> GEM_FINDER = register("gem_finder");
|
||||
|
||||
/**
|
||||
* Protects against wall collisions and earth pony attacks!
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* - Enchanting Table
|
||||
* EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> PADDED = register("padded", new SimpleEnchantment(Options.armor().rarity(Rarity.UNCOMMON).maxLevel(3).traded().table()));
|
||||
RegistryKey<Enchantment> PADDED = register("padded");
|
||||
|
||||
/**
|
||||
* Allows non-flying races to mine and interact with cloud blocks
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* - Enchanting Table
|
||||
* EnchantmentTags.NON_TREASURE
|
||||
* EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> FEATHER_TOUCH = register("feather_touch", new SimpleEnchantment(Options.create(EnchantmentTarget.BREAKABLE, UEnchantmentValidSlots.HANDS).rarity(Rarity.UNCOMMON).traded().table()));
|
||||
RegistryKey<Enchantment> FEATHER_TOUCH = register("feather_touch");
|
||||
|
||||
/**
|
||||
* Heavy players move more slowly but are less likely to be flung around wildly.
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* - Enchanting Table
|
||||
* EnchantmentTags.NON_TREASURE
|
||||
* EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> HEAVY = register("heavy", new AttributedEnchantment(Options.armor().rarity(Rarity.RARE).maxLevel(4).traded().table()))
|
||||
.addModifier(EntityAttributes.GENERIC_MOVEMENT_SPEED, (user, level) -> {
|
||||
return new EntityAttributeModifier(UUID.fromString("a3d5a94f-4c40-48f6-a343-558502a13e10"), "Heavyness", (1 - level/(float)10) - 1, Operation.MULTIPLY_TOTAL);
|
||||
});
|
||||
RegistryKey<Enchantment> HEAVY = register("heavy");
|
||||
|
||||
/**
|
||||
* It's dangerous to go alone, take this!
|
||||
*
|
||||
* Weapons will become stronger the more allies you have around.
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* - Enchanting Table
|
||||
* EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> HERDS = register("herds", new CollaboratorEnchantment(Options.create(EnchantmentTarget.WEAPON, EquipmentSlot.MAINHAND).rarity(Rarity.RARE).maxLevel(3).treasure().traded().table()));
|
||||
RegistryKey<Enchantment> HERDS = register("herds");
|
||||
|
||||
/**
|
||||
* Alters gravity
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> REPULSION = register("repulsion", new AttributedEnchantment(Options.create(EnchantmentTarget.ARMOR_FEET, EquipmentSlot.FEET).rarity(Rarity.VERY_RARE).maxLevel(3).treasure().traded()))
|
||||
.addModifier(UEntityAttributes.ENTITY_GRAVITY_MODIFIER, (user, level) -> {
|
||||
return new EntityAttributeModifier(UUID.fromString("1734bbd6-1916-4124-b710-5450ea70fbdb"), "Anti Grav", (0.5F - (0.375 * (level - 1))) - 1, Operation.MULTIPLY_TOTAL);
|
||||
});
|
||||
RegistryKey<Enchantment> REPULSION = register("repulsion");
|
||||
|
||||
/**
|
||||
* I want it, I neeeed it!
|
||||
*
|
||||
* Mobs really want your candy. You'd better give it to them.
|
||||
*
|
||||
* EnchantmentTags.CURSE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> WANT_IT_NEED_IT = register("want_it_need_it", new WantItNeedItEnchantment(Options.allItems().rarity(Rarity.VERY_RARE).curse().treasure().traded()));
|
||||
RegistryKey<Enchantment> WANT_IT_NEED_IT = register("want_it_need_it");
|
||||
|
||||
/**
|
||||
* Hahaha geddit?
|
||||
*
|
||||
* Random things happen.
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* EnchantmentTags.NON_TREASURE
|
||||
* EnchantmentTags.CURSE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> POISONED_JOKE = register("poisoned_joke", new PoisonedJokeEnchantment(Options.allItems().rarity(Rarity.VERY_RARE).curse().traded()));
|
||||
RegistryKey<Enchantment> POISONED_JOKE = register("poisoned_joke");
|
||||
|
||||
/**
|
||||
* Who doesn't like a good freakout?
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* EnchantmentTags.CURSE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> STRESSED = register("stressed", new StressfulEnchantment(Options.allItems().rarity(Rarity.VERY_RARE).curse().treasure().traded().maxLevel(3)));
|
||||
RegistryKey<Enchantment> STRESSED = register("stressed");
|
||||
|
||||
/**
|
||||
* This item just wants to be held.
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* - Enchanting Table
|
||||
* EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> CLINGY = register("clingy", new SimpleEnchantment(Options.allItems().rarity(Rarity.VERY_RARE).maxLevel(6).traded().table().treasure()));
|
||||
RegistryKey<Enchantment> CLINGY = register("clingy");
|
||||
|
||||
/**
|
||||
* Items with loyalty are kept after death.
|
||||
* Only works if they don't also have curse of binding.
|
||||
*
|
||||
* Appears in:
|
||||
* - Enchanting Table
|
||||
* EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> HEART_BOUND = register("heart_bound", new SimpleEnchantment(Options.create(EnchantmentTarget.VANISHABLE, UEnchantmentValidSlots.ANY).rarity(Rarity.UNCOMMON).maxLevel(5).treasure().table()));
|
||||
RegistryKey<Enchantment> HEART_BOUND = register("heart_bound");
|
||||
|
||||
/**
|
||||
* Consumes drops whilst mining and produces experience instead
|
||||
*
|
||||
* Appears in:
|
||||
* - Trades
|
||||
* - Enchanting Table
|
||||
* EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
* EnchantmentTags.TRADEABLE
|
||||
*/
|
||||
RegistryEntry<Enchantment> CONSUMPTION = register("consumption", new ConsumptionEnchantment(Options.create(EnchantmentTarget.DIGGER, UEnchantmentValidSlots.HANDS).rarity(Rarity.VERY_RARE).treasure().table().traded()));
|
||||
RegistryKey<Enchantment> CONSUMPTION = register("consumption");
|
||||
|
||||
static void bootstrap() { }
|
||||
|
||||
static <T extends SimpleEnchantment> RegistryEntry<Enchantment> register(String name, T enchantment) {
|
||||
var entry = Registry.registerReference(Registries.ENCHANTMENT, Unicopia.id(name), enchantment);
|
||||
REGISTRY.add(entry);
|
||||
return entry;
|
||||
static RegistryKey<Enchantment> register(String name) {
|
||||
RegistryKey<Enchantment> key = RegistryKey.of(RegistryKeys.ENCHANTMENT, Unicopia.id(name));
|
||||
REGISTRY.add(key);
|
||||
return key;
|
||||
}
|
||||
|
||||
static void register(Registry<Enchantment> registry, RegistryKey<Enchantment> key, Enchantment.Builder builder) {
|
||||
Registry.register(registry, key, builder.build(key.getValue()));
|
||||
}
|
||||
|
||||
static void bootstrap() {
|
||||
// Options.table -> EnchantmentTags.IN_ENCHANTING_TABLE
|
||||
// Optiona.curse -> EnchantmentTags.CURSE
|
||||
// Options.traded -> EnchantmentTags.TRADEABLE
|
||||
|
||||
DynamicRegistrySetupCallback.EVENT.register(registries -> {
|
||||
registries.getOptional(RegistryKeys.ENCHANTMENT).ifPresent(registry -> {
|
||||
Registry<Item> items = registries.getOptional(RegistryKeys.ITEM).orElseThrow();
|
||||
|
||||
register(registry, GEM_FINDER, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.MINING_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.RARE,
|
||||
3,
|
||||
Enchantment.constantCost(1), Enchantment.constantCost(41),
|
||||
4,
|
||||
AttributeModifierSlot.HAND
|
||||
)));
|
||||
// TODO: gem finder effect
|
||||
|
||||
register(registry, PADDED, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.HEAD_ARMOR_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.UNCOMMON,
|
||||
3,
|
||||
Enchantment.constantCost(1), Enchantment.constantCost(41),
|
||||
4,
|
||||
AttributeModifierSlot.ARMOR
|
||||
)));
|
||||
register(registry, FEATHER_TOUCH, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.MINING_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.UNCOMMON,
|
||||
1,
|
||||
Enchantment.constantCost(1), Enchantment.constantCost(31),
|
||||
3,
|
||||
AttributeModifierSlot.HAND
|
||||
)));
|
||||
register(registry, HEAVY, Enchantment.builder(
|
||||
Enchantment.definition(
|
||||
items.getEntryList(ItemTags.ARMOR_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.RARE,
|
||||
4,
|
||||
Enchantment.constantCost(7), Enchantment.constantCost(23),
|
||||
2,
|
||||
AttributeModifierSlot.ARMOR
|
||||
)
|
||||
).exclusiveSet(registry.getEntryList(EnchantmentTags.ARMOR_EXCLUSIVE_SET).orElseThrow())
|
||||
.addEffect(EnchantmentEffectComponentTypes.ATTRIBUTES, new AttributeEnchantmentEffect(
|
||||
Unicopia.id("enchantment.heaviness"),
|
||||
EntityAttributes.GENERIC_MOVEMENT_SPEED,
|
||||
EnchantmentLevelBasedValue.linear(-0.1F, -0.1F),
|
||||
EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL
|
||||
)
|
||||
));
|
||||
register(registry, HERDS, Enchantment.builder(
|
||||
Enchantment.definition(
|
||||
items.getEntryList(ItemTags.WEAPON_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.RARE,
|
||||
3,
|
||||
Enchantment.constantCost(8), Enchantment.constantCost(20),
|
||||
1,
|
||||
AttributeModifierSlot.MAINHAND
|
||||
)
|
||||
));
|
||||
// TODO: Herding effect
|
||||
|
||||
register(registry, REPULSION, Enchantment.builder(
|
||||
Enchantment.definition(
|
||||
items.getEntryList(ItemTags.FOOT_ARMOR_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.VERY_RARE,
|
||||
3,
|
||||
Enchantment.constantCost(9), Enchantment.constantCost(28),
|
||||
3,
|
||||
AttributeModifierSlot.FEET
|
||||
)
|
||||
).exclusiveSet(registry.getEntryList(EnchantmentTags.ARMOR_EXCLUSIVE_SET).orElseThrow())
|
||||
.addEffect(EnchantmentEffectComponentTypes.ATTRIBUTES, new AttributeEnchantmentEffect(
|
||||
Unicopia.id("enchantment.repulsion"),
|
||||
UEntityAttributes.ENTITY_GRAVITY_MODIFIER,
|
||||
EnchantmentLevelBasedValue.linear(-0.5F, -0.375F),
|
||||
EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL
|
||||
)
|
||||
));
|
||||
|
||||
register(registry, WANT_IT_NEED_IT, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.VANISHING_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.VERY_RARE,
|
||||
1,
|
||||
Enchantment.constantCost(2), Enchantment.constantCost(10),
|
||||
4,
|
||||
AttributeModifierSlot.ANY
|
||||
)));
|
||||
// TODO: Want it need it effect
|
||||
register(registry, POISONED_JOKE, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.VANISHING_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.VERY_RARE,
|
||||
1,
|
||||
Enchantment.constantCost(2), Enchantment.constantCost(10),
|
||||
4,
|
||||
AttributeModifierSlot.ANY
|
||||
)));
|
||||
// TODO: Poisoned joke effect
|
||||
|
||||
register(registry, CLINGY, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.VANISHING_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.VERY_RARE,
|
||||
3,
|
||||
Enchantment.constantCost(2), Enchantment.constantCost(12),
|
||||
4,
|
||||
AttributeModifierSlot.ANY
|
||||
)));
|
||||
// TODO: Stressful effect
|
||||
|
||||
register(registry, CLINGY, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.EQUIPPABLE_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.VERY_RARE,
|
||||
6,
|
||||
Enchantment.constantCost(2), Enchantment.constantCost(12),
|
||||
1,
|
||||
AttributeModifierSlot.ANY
|
||||
)));
|
||||
|
||||
register(registry, HEART_BOUND, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.VANISHING_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.UNCOMMON,
|
||||
5,
|
||||
Enchantment.constantCost(6), Enchantment.constantCost(41),
|
||||
3,
|
||||
AttributeModifierSlot.ANY
|
||||
)));
|
||||
|
||||
register(registry, CONSUMPTION, Enchantment.builder(Enchantment.definition(
|
||||
items.getEntryList(ItemTags.MINING_ENCHANTABLE).orElseThrow(),
|
||||
Rarity.VERY_RARE,
|
||||
1,
|
||||
Enchantment.constantCost(10), Enchantment.constantCost(71),
|
||||
5,
|
||||
AttributeModifierSlot.MAINHAND
|
||||
)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,19 +6,13 @@ import com.minelittlepony.unicopia.particle.FollowingParticleEffect;
|
|||
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
||||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class WantItNeedItEnchantment extends SimpleEnchantment {
|
||||
public class WantItNeedItEnchantment {
|
||||
|
||||
protected WantItNeedItEnchantment(Options options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserTick(Living<?> user, int level) {
|
||||
if (user instanceof Creature && user.asWorld().random.nextInt(10) == 0) {
|
||||
ParticleUtils.spawnParticles(new FollowingParticleEffect(UParticles.HEALTH_DRAIN, user.asEntity(), 0.2F), user.asEntity(), 1);
|
||||
|
@ -26,8 +20,8 @@ public class WantItNeedItEnchantment extends SimpleEnchantment {
|
|||
}
|
||||
|
||||
public static boolean prefersEquipment(ItemStack newStack, ItemStack oldStack) {
|
||||
int newLevel = EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, newStack);
|
||||
int oldLevel = EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, oldStack);
|
||||
int newLevel = EnchantmentUtil.getLevel(UEnchantments.WANT_IT_NEED_IT, newStack);
|
||||
int oldLevel = EnchantmentUtil.getLevel(UEnchantments.WANT_IT_NEED_IT, oldStack);
|
||||
return newLevel > oldLevel;
|
||||
}
|
||||
|
||||
|
@ -38,12 +32,12 @@ public class WantItNeedItEnchantment extends SimpleEnchantment {
|
|||
}
|
||||
|
||||
public static int getLevel(ItemEntity entity) {
|
||||
return EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getStack());
|
||||
return EnchantmentUtil.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getStack());
|
||||
}
|
||||
|
||||
public static int getLevel(LivingEntity entity) {
|
||||
return EnchantmentHelper.getEquipmentLevel(UEnchantments.WANT_IT_NEED_IT, entity)
|
||||
+ EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getOffHandStack())
|
||||
+ EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getMainHandStack());
|
||||
return EnchantmentUtil.getLevel(UEnchantments.WANT_IT_NEED_IT, entity)
|
||||
+ EnchantmentUtil.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getOffHandStack())
|
||||
+ EnchantmentUtil.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getMainHandStack());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,11 @@ package com.minelittlepony.unicopia.network;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.minelittlepony.unicopia.ability.data.tree.TreeTypeLoader;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
|
||||
import com.minelittlepony.unicopia.container.SpellbookChapter;
|
||||
import com.minelittlepony.unicopia.container.SpellbookChapterLoader;
|
||||
import com.minelittlepony.unicopia.diet.PonyDiets;
|
||||
import com.sollace.fabwork.api.packets.Packet;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
|
@ -17,13 +14,13 @@ import net.minecraft.util.Identifier;
|
|||
|
||||
public record MsgServerResources (
|
||||
Map<Identifier, SpellTraits> traits,
|
||||
Map<Identifier, ?> chapters,
|
||||
Map<Identifier, SpellbookChapter> chapters,
|
||||
Map<Identifier, TreeTypeLoader.TreeTypeDef> treeTypes,
|
||||
PonyDiets diets
|
||||
) {
|
||||
public static final PacketCodec<RegistryByteBuf, MsgServerResources> PACKET_CODEC = PacketCodec.tuple(
|
||||
PacketCodecs.map(HashMap::new, Identifier.PACKET_CODEC, SpellTraits.PACKET_CODEC), MsgServerResources::traits,
|
||||
PacketCodecs.map(HashMap::new, Identifier.PACKET_CODEC, null), MsgServerResources::chapters,
|
||||
PacketCodecs.map(HashMap::new, Identifier.PACKET_CODEC, SpellbookChapter.PACKET_CODEC), MsgServerResources::chapters,
|
||||
PacketCodecs.map(HashMap::new, Identifier.PACKET_CODEC, TreeTypeLoader.TreeTypeDef.PACKET_CODEC), MsgServerResources::treeTypes,
|
||||
PonyDiets.PACKET_CODEC, MsgServerResources::diets,
|
||||
MsgServerResources::new
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.minelittlepony.unicopia.network.handler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.minelittlepony.unicopia.USounds;
|
||||
import com.minelittlepony.unicopia.ability.data.Rot;
|
||||
|
@ -13,12 +11,10 @@ import com.minelittlepony.unicopia.client.DiscoveryToast;
|
|||
import com.minelittlepony.unicopia.client.UnicopiaClient;
|
||||
import com.minelittlepony.unicopia.client.gui.TribeSelectionScreen;
|
||||
import com.minelittlepony.unicopia.client.gui.spellbook.ClientChapters;
|
||||
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.Chapter;
|
||||
import com.minelittlepony.unicopia.diet.PonyDiets;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.network.*;
|
||||
import com.minelittlepony.unicopia.network.MsgCasterLookRequest.Reply;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -26,7 +22,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.particle.ItemStackParticleEffect;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class ClientNetworkHandlerImpl {
|
||||
|
@ -77,10 +72,9 @@ public class ClientNetworkHandlerImpl {
|
|||
UnicopiaClient.getInstance().setZapAppleStage(packet.stage());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void handleServerResources(PlayerEntity sender, MsgServerResources packet) {
|
||||
SpellTraits.load(packet.traits());
|
||||
ClientChapters.load((Map<Identifier, Chapter>)packet.chapters());
|
||||
ClientChapters.load(packet.chapters());
|
||||
TreeTypes.load(packet.treeTypes());
|
||||
PonyDiets.load(packet.diets());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue