mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Create a component for sunglasses breaking
This commit is contained in:
parent
0f1c2069e7
commit
50ca68e52a
6 changed files with 70 additions and 10 deletions
|
@ -102,7 +102,7 @@ public interface USounds {
|
|||
SoundEvent ITEM_ROCK_LAND = BLOCK_STONE_HIT;
|
||||
RegistryEntry.Reference<SoundEvent> ITEM_MUFFIN_BOUNCE = BLOCK_NOTE_BLOCK_BANJO;
|
||||
|
||||
SoundEvent ITEM_SUNGLASSES_SHATTER = BLOCK_GLASS_BREAK;
|
||||
RegistryEntry<SoundEvent> ITEM_SUNGLASSES_SHATTER = Registries.SOUND_EVENT.getEntry(BLOCK_GLASS_BREAK);
|
||||
|
||||
SoundEvent ITEM_APPLE_ROT = register("item.apple.rot");
|
||||
SoundEvent ITEM_BRACELET_SIGN = register("item.bracelet.sign");
|
||||
|
|
|
@ -26,7 +26,7 @@ public class UEntityTypeTagProvider extends FabricTagProvider<EntityType<?>> {
|
|||
EntityType.CREEPER,
|
||||
EntityType.VILLAGER, EntityType.WANDERING_TRADER, EntityType.PILLAGER, EntityType.ILLUSIONER, EntityType.EVOKER, EntityType.WITCH,
|
||||
EntityType.TURTLE,
|
||||
EntityType.BLAZE, //TODO: 1.20.5 EntityType.BREEZE,
|
||||
EntityType.BLAZE, EntityType.BREEZE,
|
||||
EntityType.SHEEP, EntityType.PIG, EntityType.GOAT,
|
||||
EntityType.RABBIT, EntityType.POLAR_BEAR, EntityType.PANDA,
|
||||
EntityType.COW, EntityType.MOOSHROOM,
|
||||
|
|
|
@ -31,6 +31,8 @@ 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.component.BreaksIntoItemComponent;
|
||||
import com.minelittlepony.unicopia.item.component.UDataComponentTypes;
|
||||
import com.minelittlepony.unicopia.item.enchantment.EnchantmentUtil;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.network.track.DataTracker;
|
||||
|
@ -381,13 +383,18 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
this.attacker = attacker;
|
||||
}
|
||||
|
||||
if (magical.isIn(UTags.DamageTypes.BREAKS_SUNGLASSES)) {
|
||||
ItemStack glasses = GlassesItem.getForEntity(entity).stack();
|
||||
if (glasses.isOf(UItems.SUNGLASSES)) {
|
||||
// TODO: BreaksIntoItemComponent
|
||||
ItemStack broken = glasses.withItem(UItems.BROKEN_SUNGLASSES);
|
||||
BreaksIntoItemComponent afterBroken = glasses.get(UDataComponentTypes.ITEM_AFTER_BREAKING);
|
||||
|
||||
if (afterBroken != null && afterBroken.damageType().contains(magical.getTypeRegistryEntry())) {
|
||||
if (afterBroken != null) {
|
||||
afterBroken.getItemAfterBreaking().ifPresent(b -> {
|
||||
ItemStack broken = glasses.withItem(b);
|
||||
TrinketsDelegate.getInstance(entity).setEquippedStack(entity, TrinketsDelegate.FACE, broken);
|
||||
afterBroken.getBreakingSound().ifPresent(sound -> {
|
||||
playSound(USounds.ITEM_SUNGLASSES_SHATTER, 1, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.block.cloud.CloudBedBlock;
|
|||
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity;
|
||||
import com.minelittlepony.unicopia.entity.mob.UEntities;
|
||||
import com.minelittlepony.unicopia.item.cloud.CloudBedItem;
|
||||
import com.minelittlepony.unicopia.item.component.BreaksIntoItemComponent;
|
||||
import com.minelittlepony.unicopia.item.component.UDataComponentTypes;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.item.group.ItemGroupRegistry;
|
||||
|
@ -33,6 +34,7 @@ import net.minecraft.util.Rarity;
|
|||
import net.minecraft.util.UseAction;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.Registries;
|
||||
|
||||
public interface UItems {
|
||||
|
@ -225,7 +227,14 @@ public interface UItems {
|
|||
.maxDamage(16)
|
||||
.rarity(Rarity.UNCOMMON), 0), ItemGroups.TOOLS);
|
||||
|
||||
GlassesItem SUNGLASSES = register("sunglasses", new GlassesItem(new Item.Settings().maxCount(1)), ItemGroups.COMBAT);
|
||||
GlassesItem SUNGLASSES = register("sunglasses", new GlassesItem(new Item.Settings()
|
||||
.maxCount(1)
|
||||
.component(UDataComponentTypes.ITEM_AFTER_BREAKING, new BreaksIntoItemComponent(
|
||||
UTags.DamageTypes.BREAKS_SUNGLASSES,
|
||||
RegistryKey.of(RegistryKeys.ITEM, Unicopia.id("broken_sunglasses")),
|
||||
USounds.ITEM_SUNGLASSES_SHATTER.getKey().get())
|
||||
)
|
||||
), ItemGroups.COMBAT);
|
||||
GlassesItem BROKEN_SUNGLASSES = register("broken_sunglasses", new GlassesItem(new Item.Settings().maxCount(1)), ItemGroups.COMBAT);
|
||||
|
||||
Item CLAM_SHELL = register("clam_shell", new Item(new Item.Settings()), ItemGroups.INGREDIENTS);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.minelittlepony.unicopia.item.component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
import net.minecraft.entity.damage.DamageType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public record BreaksIntoItemComponent(
|
||||
TagKey<DamageType> damageType,
|
||||
RegistryKey<Item> itemAfterBreaking,
|
||||
RegistryKey<SoundEvent> breakingSound
|
||||
) {
|
||||
public static final Codec<BreaksIntoItemComponent> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
TagKey.codec(RegistryKeys.DAMAGE_TYPE).fieldOf("damage_type").forGetter(BreaksIntoItemComponent::damageType),
|
||||
RegistryKey.createCodec(RegistryKeys.ITEM).fieldOf("item_after_breaking").forGetter(BreaksIntoItemComponent::itemAfterBreaking),
|
||||
RegistryKey.createCodec(RegistryKeys.SOUND_EVENT).fieldOf("breaking_sound").forGetter(BreaksIntoItemComponent::breakingSound)
|
||||
).apply(instance, BreaksIntoItemComponent::new));
|
||||
public static final PacketCodec<RegistryByteBuf, BreaksIntoItemComponent> PACKET_CODEC = PacketCodec.tuple(
|
||||
Identifier.PACKET_CODEC.xmap(id -> TagKey.of(RegistryKeys.DAMAGE_TYPE, id), key -> key.id()), BreaksIntoItemComponent::damageType,
|
||||
RegistryKey.createPacketCodec(RegistryKeys.ITEM), BreaksIntoItemComponent::itemAfterBreaking,
|
||||
RegistryKey.createPacketCodec(RegistryKeys.SOUND_EVENT), BreaksIntoItemComponent::breakingSound,
|
||||
BreaksIntoItemComponent::new
|
||||
);
|
||||
|
||||
public Optional<Item> getItemAfterBreaking() {
|
||||
return Registries.ITEM.getOrEmpty(itemAfterBreaking());
|
||||
}
|
||||
|
||||
public Optional<SoundEvent> getBreakingSound() {
|
||||
return Registries.SOUND_EVENT.getOrEmpty(breakingSound);
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ public interface UDataComponentTypes {
|
|||
ComponentType<Charges> CHARGES = register("charges", builder -> builder.codec(Charges.CODEC).packetCodec(Charges.PACKET_CODEC));
|
||||
ComponentType<Appearance> APPEARANCE = register("appearance", builder -> builder.codec(Appearance.CODEC).packetCodec(Appearance.PACKET_CODEC));
|
||||
ComponentType<DietProfile> DIET_PROFILE = register("diet_profile", builder -> builder.codec(DietProfile.CODEC).packetCodec(DietProfile.PACKET_CODEC));
|
||||
ComponentType<BreaksIntoItemComponent> ITEM_AFTER_BREAKING = register("item_after_breaking", builder -> builder.codec(BreaksIntoItemComponent.CODEC).packetCodec(BreaksIntoItemComponent.PACKET_CODEC));
|
||||
|
||||
private static <T> ComponentType<T> register(String name, UnaryOperator<ComponentType.Builder<T>> builderOperator) {
|
||||
return Registry.register(Registries.DATA_COMPONENT_TYPE, Unicopia.id(name), builderOperator.apply(ComponentType.builder()).build());
|
||||
|
|
Loading…
Reference in a new issue