优化火箭的代码

This commit is contained in:
17146 2024-05-30 14:00:57 +08:00
parent 881afe900c
commit 4251b968eb
2 changed files with 24 additions and 41 deletions

View file

@ -2,7 +2,6 @@ package net.mcreator.target.client.screens;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.mcreator.target.init.TargetModAttributes;
import net.mcreator.target.init.TargetModItems; import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModTags; import net.mcreator.target.init.TargetModTags;
import net.minecraft.client.CameraType; import net.minecraft.client.CameraType;

View file

@ -1,22 +1,20 @@
package net.mcreator.target.item.common.ammo; package net.mcreator.target.item.common.ammo;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import net.mcreator.target.client.renderer.item.RocketItemRenderer; import net.mcreator.target.client.renderer.item.RocketItemRenderer;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.item.AnimatedItem; import net.mcreator.target.item.AnimatedItem;
import net.mcreator.target.tools.ParticleTool;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item;
import net.minecraft.world.item.*; import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.client.extensions.common.IClientItemExtensions; import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.animatable.GeoItem;
@ -28,7 +26,6 @@ import software.bernie.geckolib.core.animation.RawAnimation;
import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
public class Rocket extends Item implements GeoItem, AnimatedItem { public class Rocket extends Item implements GeoItem, AnimatedItem {
@ -37,7 +34,7 @@ public class Rocket extends Item implements GeoItem, AnimatedItem {
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
public Rocket() { public Rocket() {
super(new Item.Properties().stacksTo(16).rarity(Rarity.COMMON)); super(new Item.Properties().stacksTo(16));
} }
@Override @Override
@ -57,7 +54,7 @@ public class Rocket extends Item implements GeoItem, AnimatedItem {
transformType = type; transformType = type;
} }
private PlayState idlePredicate(AnimationState event) { private PlayState idlePredicate(AnimationState<Rocket> event) {
if (transformType != null && transformType.firstPerson()) { if (transformType != null && transformType.firstPerson()) {
if (this.animationProcedure.equals("empty")) { if (this.animationProcedure.equals("empty")) {
event.getController().setAnimation(RawAnimation.begin().thenLoop("animation.rpg.idle")); event.getController().setAnimation(RawAnimation.begin().thenLoop("animation.rpg.idle"));
@ -67,7 +64,7 @@ public class Rocket extends Item implements GeoItem, AnimatedItem {
return PlayState.STOP; return PlayState.STOP;
} }
private PlayState procedurePredicate(AnimationState event) { private PlayState procedurePredicate(AnimationState<Rocket> event) {
if (transformType != null && transformType.firstPerson()) { if (transformType != null && transformType.firstPerson()) {
if (!this.animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) { if (!this.animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure)); event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
@ -96,43 +93,30 @@ public class Rocket extends Item implements GeoItem, AnimatedItem {
} }
@Override @Override
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) { public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack) {
if (equipmentSlot == EquipmentSlot.MAINHAND) { Multimap<Attribute, AttributeModifier> map = super.getAttributeModifiers(slot, stack);
ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder(); if (slot == EquipmentSlot.MAINHAND) {
builder.putAll(super.getDefaultAttributeModifiers(equipmentSlot)); map = HashMultimap.create(map);
builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Item modifier", 6d, AttributeModifier.Operation.ADDITION)); map.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Item modifier", 6d, AttributeModifier.Operation.ADDITION));
builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Item modifier", -2.4, AttributeModifier.Operation.ADDITION)); map.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Item modifier", -2.4, AttributeModifier.Operation.ADDITION));
return builder.build();
} }
return super.getDefaultAttributeModifiers(equipmentSlot); return map;
} }
@Override @Override
public void appendHoverText(ItemStack itemstack, Level world, List<Component> list, TooltipFlag flag) { public boolean hurtEnemy(ItemStack stack, LivingEntity entity, LivingEntity source) {
super.appendHoverText(itemstack, world, list, flag); if (entity.level() instanceof ServerLevel level && Math.random() < 0.25) {
level.explode(source, source.getX(), source.getY() + 1, source.getZ(), 6, Level.ExplosionInteraction.NONE);
level.explode(null, source.getX(), source.getY() + 1, source.getZ(), 6, Level.ExplosionInteraction.NONE);
if (!source.level().isClientSide() && source.getServer() != null) {
ParticleTool.spawnMediumExplosionParticles(source.level(), source.getPosition(0));
} }
@Override stack.shrink(1);
public boolean hurtEnemy(ItemStack itemstack, LivingEntity entity, LivingEntity sourceentity) {
boolean retval = super.hurtEnemy(itemstack, entity, sourceentity);
if (Math.random() >= 0.25) return retval;
if (entity.level() instanceof ServerLevel level) {
level.explode(sourceentity, sourceentity.getX(), sourceentity.getY() + 1, sourceentity.getZ(), 6, Level.ExplosionInteraction.NONE);
level.explode(null, sourceentity.getX(), sourceentity.getY() + 1, sourceentity.getZ(), 6, Level.ExplosionInteraction.NONE);
if (!sourceentity.level().isClientSide() && sourceentity.getServer() != null) {
// TODO what the hell is this?
sourceentity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, sourceentity.position(), sourceentity.getRotationVector(), sourceentity.level() instanceof ServerLevel ? (ServerLevel) sourceentity.level() : null, 4,
sourceentity.getName().getString(), sourceentity.getDisplayName(), sourceentity.getServer(), sourceentity), "playsound target:target:mediumexp");
}
}
if (sourceentity instanceof Player player) {
player.getInventory().clearOrCountMatchingItems(p -> TargetModItems.ROCKET.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots());
} }
return retval; return super.hurtEnemy(stack, entity, source);
} }
@Override @Override