121 lines
5.1 KiB
Java
121 lines
5.1 KiB
Java
package net.mcreator.target.item;
|
|
|
|
import com.google.common.collect.HashMultimap;
|
|
import com.google.common.collect.Multimap;
|
|
import net.mcreator.target.TargetMod;
|
|
import net.mcreator.target.client.renderer.item.LightSaberItemRenderer;
|
|
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.world.entity.EquipmentSlot;
|
|
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.minecraft.world.level.Level;
|
|
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.core.animation.AnimationController;
|
|
import software.bernie.geckolib.core.animation.AnimationState;
|
|
import software.bernie.geckolib.core.animation.RawAnimation;
|
|
import software.bernie.geckolib.core.object.PlayState;
|
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
|
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import java.util.function.Consumer;
|
|
|
|
public class LightSaberItem extends SwordItem implements GeoItem {
|
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
|
public String animationProcedure = "empty";
|
|
public static ItemDisplayContext transformType;
|
|
|
|
public LightSaberItem() {
|
|
super(Tiers.NETHERITE, 10, -1.8f, new Item.Properties().rarity(Rarity.EPIC));
|
|
}
|
|
|
|
@Override
|
|
public void initializeClient(Consumer<IClientItemExtensions> 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;
|
|
}
|
|
|
|
private PlayState idlePredicate(AnimationState event) {
|
|
if (transformType != null && transformType.firstPerson()) {
|
|
if (this.animationProcedure.equals("empty")) {
|
|
event.getController().setAnimation(RawAnimation.begin().thenLoop("animation.lightsaber.idle"));
|
|
return PlayState.CONTINUE;
|
|
}
|
|
}
|
|
return PlayState.STOP;
|
|
}
|
|
|
|
private PlayState procedurePredicate(AnimationState event) {
|
|
if (transformType != null && transformType.firstPerson()) {
|
|
if (!this.animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
|
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
|
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
|
this.animationProcedure = "empty";
|
|
event.getController().forceAnimationReset();
|
|
}
|
|
} else if (this.animationProcedure.equals("empty")) {
|
|
return PlayState.STOP;
|
|
}
|
|
}
|
|
return PlayState.CONTINUE;
|
|
}
|
|
|
|
@Override
|
|
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
|
AnimationController procedureController = new AnimationController(this, "procedureController", 0, this::procedurePredicate);
|
|
data.add(procedureController);
|
|
AnimationController idleController = new AnimationController(this, "idleController", 0, this::idlePredicate);
|
|
data.add(idleController);
|
|
}
|
|
|
|
@Override
|
|
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
|
return this.cache;
|
|
}
|
|
|
|
@Override
|
|
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) {
|
|
Multimap<Attribute, AttributeModifier> 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, TargetMod.ATTRIBUTE_MODIFIER, 0.2f, AttributeModifier.Operation.MULTIPLY_BASE));
|
|
|
|
}
|
|
return map;
|
|
}
|
|
|
|
@Override
|
|
public int getEnchantmentValue() {
|
|
return 22;
|
|
}
|
|
|
|
@Override
|
|
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
|
|
return enchantment.category == EnchantmentCategory.BREAKABLE || enchantment.category == EnchantmentCategory.WEAPON;
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(ItemStack itemstack, Level world, List<Component> list, TooltipFlag flag) {
|
|
super.appendHoverText(itemstack, world, list, flag);
|
|
}
|
|
}
|