package net.mcreator.superbwarfare.item; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.client.renderer.item.LightSaberItemRenderer; import net.mcreator.superbwarfare.init.ModSounds; import net.mcreator.superbwarfare.tools.SoundTool; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.item.*; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentCategory; import net.minecraftforge.client.extensions.common.IClientItemExtensions; import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.UUID; import java.util.function.Consumer; public class LightSaber extends SwordItem implements GeoItem, AnimatedItem { private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public String animationProcedure = "empty"; public static ItemDisplayContext transformType; public LightSaber() { super(Tiers.NETHERITE, 10, -1.8f, new Item.Properties().rarity(Rarity.EPIC)); } @Override public void initializeClient(Consumer consumer) { super.initializeClient(consumer); consumer.accept(new IClientItemExtensions() { private final BlockEntityWithoutLevelRenderer renderer = new LightSaberItemRenderer(); @Override public BlockEntityWithoutLevelRenderer getCustomRenderer() { return renderer; } }); } public void getTransformType(ItemDisplayContext type) { transformType = type; } @Override public void registerControllers(AnimatableManager.ControllerRegistrar data) { } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.cache; } @Override public Multimap getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) { Multimap map = super.getDefaultAttributeModifiers(equipmentSlot); UUID uuid = new UUID(equipmentSlot.toString().hashCode(), 0); if (equipmentSlot == EquipmentSlot.MAINHAND) { map = HashMultimap.create(map); map.put(Attributes.MOVEMENT_SPEED, new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER, 0.2f, AttributeModifier.Operation.MULTIPLY_BASE)); } return map; } @Override public int getEnchantmentValue() { return 22; } @Override public boolean isEnchantable(ItemStack stack) { return true; } @Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { return enchantment.category == EnchantmentCategory.BREAKABLE || enchantment.category == EnchantmentCategory.WEAPON; } @Override public void setAnimationProcedure(String procedure) { this.animationProcedure = procedure; } @Override public boolean isDamageable(ItemStack stack) { return false; } @Override public boolean onEntitySwing(ItemStack itemstack, LivingEntity entity) { boolean retval = super.onEntitySwing(itemstack, entity); entity.playSound(ModSounds.LIGHT_SABER.get(), 1f, 1f); if (entity instanceof ServerPlayer serverPlayer) { SoundTool.playLocalSound(serverPlayer, ModSounds.LIGHT_SABER.get(), 1f, 1f); } return retval; } }