Advertisement
Guest User

Error MCreator with entity

a guest
Jul 21st, 2023
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.08 KB | Source Code | 0 0
  1.  
  2. package net.mcreator.whitevuwsmodformachinima.entity;
  3.  
  4. import net.minecraftforge.fml.relauncher.SideOnly;
  5. import net.minecraftforge.fml.relauncher.Side;
  6. import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
  7. import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
  8. import net.minecraftforge.fml.client.registry.RenderingRegistry;
  9.  
  10. import net.minecraft.world.biome.Biome;
  11. import net.minecraft.world.World;
  12. import net.minecraft.util.ResourceLocation;
  13. import net.minecraft.util.DamageSource;
  14. import net.minecraft.item.Item;
  15. import net.minecraft.entity.SharedMonsterAttributes;
  16. import net.minecraft.entity.EnumCreatureAttribute;
  17. import net.minecraft.entity.EntityCreature;
  18. import net.minecraft.entity.Entity;
  19. import net.minecraft.client.renderer.entity.RenderLiving;
  20.  
  21. import net.mcreator.whitevuwsmodformachinima.ElementsWhiteVuwsmodformachinima;
  22.  
  23. import java.util.Iterator;
  24. import java.util.ArrayList;
  25.  
  26. @ElementsWhiteVuwsmodformachinima.ModElement.Tag
  27. public class EntityHand extends ElementsWhiteVuwsmodformachinima.ModElement {
  28.     public static final int ENTITYID = 1;
  29.     public static final int ENTITYID_RANGED = 2;
  30.     public EntityHand(ElementsWhiteVuwsmodformachinima instance) {
  31.         super(instance, 2);
  32.     }
  33.  
  34.     @Override
  35.     public void initElements() {
  36.         elements.entities.add(() -> EntityEntryBuilder.create().entity(EntityCustom.class)
  37.                 .id(new ResourceLocation("whitevuwsmodformachinima", "hand"), ENTITYID).name("hand").tracker(64, 3, true).egg(-1, -1).build());
  38.     }
  39.  
  40.     private Biome[] allbiomes(net.minecraft.util.registry.RegistryNamespaced<ResourceLocation, Biome> in) {
  41.         Iterator<Biome> itr = in.iterator();
  42.         ArrayList<Biome> ls = new ArrayList<Biome>();
  43.         while (itr.hasNext())
  44.             ls.add(itr.next());
  45.         return ls.toArray(new Biome[ls.size()]);
  46.     }
  47.  
  48.     @SideOnly(Side.CLIENT)
  49.     @Override
  50.     public void preInit(FMLPreInitializationEvent event) {
  51.         RenderingRegistry.registerEntityRenderingHandler(EntityCustom.class, renderManager -> {
  52.             return new RenderLiving(renderManager, new Modelhand(), 0.5f) {
  53.                 protected ResourceLocation getEntityTexture(Entity entity) {
  54.                     return new ResourceLocation("whitevuwsmodformachinima:textures/texture.png");
  55.                 }
  56.             };
  57.         });
  58.     }
  59.     public static class EntityCustom extends EntityCreature {
  60.         public EntityCustom(World world) {
  61.             super(world);
  62.             setSize(0.6f, 1.8f);
  63.             experienceValue = 5;
  64.             this.isImmuneToFire = false;
  65.             setNoAI(!false);
  66.             enablePersistence();
  67.         }
  68.  
  69.         @Override
  70.         public EnumCreatureAttribute getCreatureAttribute() {
  71.             return EnumCreatureAttribute.UNDEFINED;
  72.         }
  73.  
  74.         @Override
  75.         protected boolean canDespawn() {
  76.             return false;
  77.         }
  78.  
  79.         @Override
  80.         protected Item getDropItem() {
  81.             return null;
  82.         }
  83.  
  84.         @Override
  85.         public net.minecraft.util.SoundEvent getAmbientSound() {
  86.             return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation(""));
  87.         }
  88.  
  89.         @Override
  90.         public net.minecraft.util.SoundEvent getHurtSound(DamageSource ds) {
  91.             return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.generic.hurt"));
  92.         }
  93.  
  94.         @Override
  95.         public net.minecraft.util.SoundEvent getDeathSound() {
  96.             return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.generic.death"));
  97.         }
  98.  
  99.         @Override
  100.         protected float getSoundVolume() {
  101.             return 1.0F;
  102.         }
  103.  
  104.         @Override
  105.         protected void applyEntityAttributes() {
  106.             super.applyEntityAttributes();
  107.             if (this.getEntityAttribute(SharedMonsterAttributes.ARMOR) != null)
  108.                 this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(0D);
  109.             if (this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED) != null)
  110.                 this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3D);
  111.             if (this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH) != null)
  112.                 this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10D);
  113.             if (this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) != null)
  114.                 this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3D);
  115.         }
  116.     }
  117.  
  118. public static class Modelhand extends Entity extends EntityModel<T> {
  119.     public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation("modid", "hand_model"), "main");
  120.     private final ModelPart bone;
  121.     private final ModelPart bone2;
  122.     private final ModelPart bone3;
  123.     private final ModelPart bone4;
  124.     private final ModelPart bb_main;
  125.     public Modelhand(ModelPart root) {
  126.         this.bone = root.getChild("bone");
  127.         this.bone2 = root.getChild("bone2");
  128.         this.bone3 = root.getChild("bone3");
  129.         this.bone4 = root.getChild("bone4");
  130.         this.bb_main = root.getChild("bb_main");
  131.     }
  132.     public static LayerDefinition createBodyLayer() {
  133.         MeshDefinition meshdefinition = new MeshDefinition();
  134.         PartDefinition partdefinition = meshdefinition.getRoot();
  135.         PartDefinition bone = partdefinition.addOrReplaceChild("bone", CubeListBuilder.create().texOffs(16, 18).addBox(-0.75F, -14.0F, -4.0F, 1.5F, 5.0F, 2.0F, new CubeDeformation(0.0F))
  136.         .texOffs(0, 25).addBox(-0.5F, -18.0F, -3.75F, 1.0F, 4.0F, 1.5F, new CubeDeformation(0.0F))
  137.         .texOffs(14, 25).addBox(-0.35F, -21.0F, -3.5F, 0.75F, 3.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F));
  138.         PartDefinition bone2 = partdefinition.addOrReplaceChild("bone2", CubeListBuilder.create().texOffs(8, 18).addBox(-0.75F, -14.0F, -1.75F, 1.5F, 5.0F, 2.0F, new CubeDeformation(0.0F))
  139.         .texOffs(24, 17).addBox(-0.5F, -18.0F, -1.5F, 1.0F, 4.0F, 1.5F, new CubeDeformation(0.0F))
  140.         .texOffs(10, 25).addBox(-0.35F, -21.0F, -1.25F, 0.75F, 3.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F));
  141.         PartDefinition bone3 = partdefinition.addOrReplaceChild("bone3", CubeListBuilder.create().texOffs(0, 18).addBox(-0.75F, -14.0F, 0.5F, 1.5F, 5.0F, 2.0F, new CubeDeformation(0.0F))
  142.         .texOffs(22, 23).addBox(-0.5F, -18.0F, 0.75F, 1.0F, 4.0F, 1.5F, new CubeDeformation(0.0F))
  143.         .texOffs(6, 25).addBox(-0.35F, -21.0F, 1.0F, 0.75F, 3.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F));
  144.         PartDefinition bone4 = partdefinition.addOrReplaceChild("bone4", CubeListBuilder.create().texOffs(0, 0).addBox(-0.75F, -14.0F, 3.0F, 1.5F, 5.0F, 2.0F, new CubeDeformation(0.0F))
  145.         .texOffs(22, 11).addBox(-0.5F, -18.0F, 3.25F, 1.0F, 4.0F, 1.5F, new CubeDeformation(0.0F))
  146.         .texOffs(23, 0).addBox(-0.35F, -21.0F, 3.5F, 0.75F, 3.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F));
  147.         PartDefinition bb_main = partdefinition.addOrReplaceChild("bb_main", CubeListBuilder.create().texOffs(0, 0).addBox(-1.0F, -9.0F, -4.0F, 2.0F, 9.0F, 9.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F));
  148.         PartDefinition cube_r1 = bb_main.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(22, 5).addBox(-1.0F, -2.0F, -1.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -6.5442F, -6.6651F, 0.5236F, 0.0F, 0.0F));
  149.         PartDefinition cube_r2 = bb_main.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(13, 0).addBox(-1.0F, -2.0F, -1.5F, 2.0F, 4.0F, 3.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -3.0801F, -4.6651F, 0.5236F, 0.0F, 0.0F));
  150.         return LayerDefinition.create(meshdefinition, 32, 32);
  151.     }
  152.     @Override
  153.     public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
  154.     }
  155.     @Override
  156.     public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
  157.         bone.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
  158.         bone2.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
  159.         bone3.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
  160.         bone4.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
  161.         bb_main.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
  162.     }
  163. }
  164. }
  165.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement