Jump to content

SciPunk

Members
  • Posts

    44
  • Joined

  • Last visited

Posts posted by SciPunk

  1. I have my throwable item, which I want it to spin when it is in the air and stick to the surface when it hits a block but I can´t figure out, my item uses a sprite renderer, here´s my code

     

    Item class

     
     
     
     
    Spoiler
    
    public class ItemBatarang extends Item{
    
    
    
        public ItemBatarang(Properties properties) {
            super(properties);
            setRegistryName("item_batarang");
        }
    
    
        @Override
        public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
    
            ItemStack stack = playerIn.getHeldItem(handIn);
            Vec3d look = playerIn.getLookVec();
            EntityBatarang batarang = new EntityBatarang(1.0D,1.0D,1.0D,worldIn);
            batarang.setPosition(playerIn.getPosX() + look.x , playerIn.getPosY() + look.y + 1, playerIn.getPosZ() + look.z);
            batarang.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F,1.5F,0.0F);
            if (!worldIn.isRemote) {
                worldIn.addEntity(batarang);
            }
    
            worldIn.playSound(null,playerIn.getPosition(), SoundEvents.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS,1.0f,1.0f);
    
            return new ActionResult<ItemStack>(ActionResultType.SUCCESS, stack);
        }
    }
    

    Entity class

     
     
     
     
    Spoiler
    
    public class EntityBatarang extends ProjectileItemEntity {
    
    
    
        public EntityBatarang(double x, double y, double z, World worldIn) {
            super(EntitiesHolder.BATARANG, x, y, z, worldIn);
        }
    
        public EntityBatarang( LivingEntity livingEntityIn, World worldIn) {
            super(EntitiesHolder.BATARANG, livingEntityIn, worldIn);
        }
    
        public EntityBatarang(EntityType<EntityBatarang> entityBatarangEntityType, World world) {
            super(EntitiesHolder.BATARANG, world);
        }
    
        @Override
        public IPacket<?> createSpawnPacket() {
            return NetworkHooks.getEntitySpawningPacket(this);
        }
    
        @Override
        protected Item getDefaultItem() {
            return ItemHolder.BATARANG;
        }
    
        @Override
        protected void onImpact(RayTraceResult result) {
    
            if (result.getType() == RayTraceResult.Type.ENTITY) {
                ((EntityRayTraceResult)result).getEntity().attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 5.0F);
            }
    
            if (result instanceof EntityRayTraceResult) {
                EntityRayTraceResult entityRayTraceResult = (EntityRayTraceResult) result;
                if(entityRayTraceResult.getEntity() instanceof MobEntity) {
                    MobEntity entity = (MobEntity) entityRayTraceResult.getEntity();
    
                    double d0 = (double)entity.getPosX() ;
                    double d1 = (double)entity.getPosY() + 1D;
                    double d2 = (double)entity.getPosZ();
    
    
    
                    entity.addPotionEffect(new EffectInstance(Effects.SLOWNESS,120,2));
    
    
    
                    this.world.playSound(entity.getPosX(),entity.getPosY(),entity.getPosZ(), SoundEvents.BLOCK_ANVIL_HIT, SoundCategory.AMBIENT,1,1,true);
                  //3400
    
                    this.remove();
    
                } else if(entityRayTraceResult.getEntity() instanceof PlayerEntity) {
    
                    PlayerEntity entity = (PlayerEntity) entityRayTraceResult.getEntity();
    
                    entity.addPotionEffect(new EffectInstance(Effects.SLOWNESS,120,2));
    
    
    
                }
    
            }
    
            else if (result instanceof BlockRayTraceResult) {
    
                BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) result;
                double x = this.getPosX();
                double y = this.getPosY();
                double z = this.getPosZ();
    
                this.setMotion(x,y,z);
    
    
    
    
    
            }
    
        }
    
    
    
        public static EntityType register() {
            return EntityType.Builder.<EntityBatarang>create(EntityBatarang::new, EntityClassification.MISC).size(0.8F, 0.8F).build("batarang").setRegistryName(ComicUniverse.MODID,"batarang");
        }
    
        @Override
        public void tick() {
            super.tick();
    
    
            this.motionMultiplier.rotatePitch(5);
    
    
    
    
        }
    }

    ClientProxy class (where it renders)

     
     
     
     
    Spoiler
    
    public class ClientProxy implements IProxy {
        @Override
        public void init() {
    
            ScreenManager.registerFactory(BlockHolder.BLOCKGENERATOR_CONTAINER, GUIGenerator::new);
            ScreenManager.registerFactory(BlockHolder.SUITFABRICATOR_CONTAINER, GUISuitfabricator::new);
            RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.RADIOACTIVE_SPIDER, RadioactiveSpiderRenderer::new);
            RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.SMOKE_PELLET, renderManager -> new SpriteRenderer<EntitySmokePellet>(renderManager, Minecraft.getInstance().getItemRenderer()));
            RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.BATARANG, renderManager -> new SpriteRenderer<EntityBatarang>(renderManager, Minecraft.getInstance().getItemRenderer()));
    
    
        }
    

     

  2. 23 minutes ago, diesieben07 said:

    The version of addParticle you are using only does something on the client. You are only ever calling it on the server, so nothing happens.

    To spawn particles on the server you have to use ServerWorld#spawnParticle, however you should try to only spawn particles client-side, if possible, to avoid unnecessary network traffic.

    Thanks a lot, so for this case I should render it on the server-side? as I want other players to see the smoke

  3. Hi, I'm trying to make a smoke bomb, here's my code but the particles doesn't seem to render

    My code:

    public class EntitySmokePellet extends ProjectileItemEntity {
    
        public static final EntityType<EntitySmokePellet> BATARANG = register();
    
    
    
        protected EntitySmokePellet(EntityType<? extends ThrowableEntity> type, World worldIn) {
            super(EntitiesHolder.SMOKE_PELLET,worldIn);
    
    
        }
    
    
    
    
        @Override
        public IPacket<?> createSpawnPacket() {
            return NetworkHooks.getEntitySpawningPacket(this);
        }
    
    
        protected EntitySmokePellet(double x, double y, double z, World worldIn) {
            super(EntitiesHolder.SMOKE_PELLET, x, y, z, worldIn);
    
        }
    
        protected EntitySmokePellet(EntityType<? extends ThrowableEntity> type, LivingEntity livingEntityIn, World worldIn) {
            super(EntitiesHolder.SMOKE_PELLET, livingEntityIn, worldIn);
        }
    
        protected Item getDefaultItem() {
            return ItemHolder.SMOKE_PELLETE;
        }
        @Override
        protected void onImpact(RayTraceResult result) {
    
            if (!this.world.isRemote) {
    
    
                if (result instanceof EntityRayTraceResult) {
                    EntityRayTraceResult entityRayTraceResult = (EntityRayTraceResult) result;
                    if(entityRayTraceResult.getEntity() instanceof MobEntity) {
                        MobEntity entity = (MobEntity) entityRayTraceResult.getEntity();
    
                        double d0 = (double)entity.getPosX() + 0.5D;
                        double d1 = (double)entity.getPosY();
                        double d2 = (double)entity.getPosZ() + 0.5D;
    
    
    
                        entity.addPotionEffect(new EffectInstance(Effects.SLOWNESS,120,5));
                        entity.addPotionEffect(new EffectInstance(Effects.NAUSEA,120,5));
                        entity.addPotionEffect(new EffectInstance(Effects.BLINDNESS,120,5));
                        entity.world.addParticle(ParticleTypes.LARGE_SMOKE,d0,d1,d2,0,0,0);
    
                        this.remove();
    
                    }
    
                }
    
                else if (result instanceof  BlockRayTraceResult) {
    
                    BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) result;
    
                    for (int i = 0; i <= 25; i++) {
                        this.world.addParticle(ParticleTypes.LARGE_SMOKE,blockRayTraceResult.getPos().getX() , blockRayTraceResult.getPos().getY() , blockRayTraceResult.getPos().getZ(), 0, 0,0);
                    }
    
    
    
                    this.remove();
                }
            }
        }
    
    
    
        public static EntityType register() {
            return EntityType.Builder.<EntitySmokePellet>create(EntitySmokePellet::new, EntityClassification.MISC).size(0.8F, 0.8F).build("smoke_pellet").setRegistryName(ComicUniverse.MODID,"smoke_pellet");
        }
    
    
    }
    
  4. Made a custom projectile, with it's own renderer but the when I right click to throw the projectile it spawns a... pig instead of my custom texture lol

     

    Item class

     
     
     
     
    Spoiler
    
    public class ItemBatarang extends Item {
    
    
        public ItemBatarang(Item.Properties properties) {
            super(properties);
            setRegistryName("item_batarang");
    
        }
    
        public AbstractArrowEntity createBatarang(World worldIn, ItemStack stack, LivingEntity shooter) {
            ArrowEntity arrowentity = new ArrowEntity(worldIn, shooter);
            arrowentity.setPotionEffect(stack);
            return arrowentity;
        }
    
    
    
    
    
        @Override
        public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
    
            ItemStack stack = playerIn.getHeldItem(handIn);
            Vec3d look = playerIn.getLookVec();
           EntityBatarang batarang = new EntityBatarang(1.0D,1.0D,1.0D,worldIn);
            batarang.setPosition(playerIn.getPosX() + look.x * 1D, playerIn.getPosY() + look.y * 1D, playerIn.getPosZ() + look.z + look.z * 1D);
            batarang.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F,1.5F,0.5F);
            if (!worldIn.isRemote) {
                worldIn.addEntity(batarang);
            }
    
            worldIn.playSound(null,playerIn.getPosition(), SoundEvents.BLOCK_ANVIL_HIT, SoundCategory.PLAYERS,1.0f,1.0f);
    
            return new ActionResult<ItemStack>(ActionResultType.SUCCESS, stack);
        }
    }
    

    Entity class

     
     
     
     
    Spoiler
    
    public class EntityBatarang extends ThrowableEntity {
    
        public static final EntityType<EntityBatarang> BATARANG = register();
    
    
    
        protected EntityBatarang(EntityType<? extends ThrowableEntity> type, World worldIn) {
            super(BATARANG,worldIn);
    
    
        }
    
    
        @Override
        public IPacket<?> createSpawnPacket() {
    
            return NetworkHooks.getEntitySpawningPacket(this);
    
        }
    
        protected EntityBatarang(double x, double y, double z, World worldIn) {
            super(EntityBatarang.BATARANG, x, y, z, worldIn);
    
        }
    
        protected EntityBatarang(EntityType<? extends ThrowableEntity> type, LivingEntity livingEntityIn, World worldIn) {
            super(EntityBatarang.BATARANG, livingEntityIn, worldIn);
        }
    
        protected Item getDefaultItem() {
            return ItemHolder.BATARANG;
        }
        @Override
        protected void onImpact(RayTraceResult result) {
    
            if (!this.world.isRemote) {
    
    
                if (result instanceof EntityRayTraceResult) {
                    EntityRayTraceResult entityRayTraceResult = (EntityRayTraceResult) result;
                    if(entityRayTraceResult.getEntity() instanceof MobEntity) {
                        MobEntity entity = (MobEntity) entityRayTraceResult.getEntity();
    
                        entity.setFire(20);
                        entity.setHealth(0);
                    }
    
                }
            }
        }
    
        @Override
        protected void registerData() {
    
        }
    
        public static EntityType register() {
            return EntityType.Builder.<EntityBatarang>create(EntityBatarang::new, EntityClassification.MISC).size(0.8F, 0.8F).build("batarang").setRegistryName(ComicUniverse.MODID,"batarang");
        }
    }
    
    
    
    

    Entity Renderer

     
     
     
     
    Spoiler
    
    public class BatarangRenderer extends EntityRenderer<EntityBatarang> {
        private static final ResourceLocation TEXTURE = new ResourceLocation(ComicUniverse.MODID,"textures/materials/batman_chest_part.png");
    
        public BatarangRenderer(EntityRendererManager renderManager) {
            super(renderManager);
    
    
            renderManager.getFontRenderer().drawStringWithShadow("Batarang",0,0.5f,2);
        }
    
    
    
        @Override
        public void render(EntityBatarang entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
    
            super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
        }
    
    
    
    
        @Override
        public ResourceLocation getEntityTexture(EntityBatarang entity) {
            return TEXTURE;
        }
    }
    

     

  5. 10 hours ago, MoxLotus said:

    Instead of creating a new RayTraceResult you should have an instanceof test and cast event.getRayTraceResult.

     

    As for your question, does it do what you expect if you always cancel the event?

    Got it, thanks! no, it was just for testing purposes now I got to figure out the "catch" also I noticed that with this code if I get hit by 2 arrows consecutively it crashes:

    @SubscribeEvent
    public static void onProjectileHitEvent(ProjectileImpactEvent event) {
    
    
            if (event.getRayTraceResult() instanceof EntityRayTraceResult) {
                EntityRayTraceResult entityRayTraceResult = (EntityRayTraceResult) event.getRayTraceResult();
    
                if (entityRayTraceResult.getEntity() instanceof PlayerEntity) {
    
                    PlayerEntity playerEntity = (PlayerEntity) entityRayTraceResult.getEntity();
                    if (playerEntity.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemHolder.BATMAN_CHEST) {
    
                        event.setCanceled(true);
    
                    }
    
                     }
                }
            }
  6. 8 hours ago, MoxLotus said:

    From AbstractArrowEntity::tick

    
    EntityRayTraceResult entityraytraceresult = this.rayTraceEntities(vec3d2, vec3d3);
    if (entityraytraceresult != null) {
       raytraceresult = entityraytraceresult;
    }
    
    if (raytraceresult != null && raytraceresult.getType() == RayTraceResult.Type.ENTITY) {
       Entity entity = ((EntityRayTraceResult)raytraceresult).getEntity();
       Entity entity1 = this.getShooter();
       if (entity instanceof PlayerEntity && entity1 instanceof PlayerEntity && !((PlayerEntity)entity1).canAttackPlayer((PlayerEntity)entity)) {
          raytraceresult = null;
          entityraytraceresult = null;
       }
    }
    
    if (raytraceresult != null && raytraceresult.getType() != RayTraceResult.Type.MISS && !flag && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) {
       this.onHit(raytraceresult);
       this.isAirBorne = true;
    }

    The event is fired in that fourth if statement. You should be able to get the Enity the arrow hit (if any) from the EntityRayTraceResult. Then I suppose you'll want to find out if the Entity is a player and if they were facing the appropriate direction at the time.

    Hi, thanks for the tip, tried to implement it to my code but I just can't seem to get it to work, tried to do it without the condition of the player looking at it for testing purposes and I just couldn't make it work, do you have any idea why? Here's my code: 

    @SubscribeEvent
    public static void onProjectileHitEvent(ProjectileImpactEvent event) {
    
    
            EntityRayTraceResult entityRayTraceResult = new EntityRayTraceResult(event.getEntity(), event.getRayTraceResult().getHitVec());
    
            Entity entity = entityRayTraceResult.getEntity();
    
            if (entity instanceof PlayerEntity) {
    
                PlayerEntity playerEntity = (PlayerEntity) entity;
                if (playerEntity.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemHolder.BATMAN_CHEST) {
                    event.setCanceled(true);
                }
    
            }
        }
    
  7. How could I make behavior on the player that when the player sees the projectile "catches it" e.g a skeleton shoots the player but if the player is facing the arrow the player catches the projectile so far the event I think it has to do something with it is ProjectileImpactEvent, however, I'm not entirely sure how could I write that behavior. Here's my code

     

    @SubscribeEvent
    public static void onProjectileCatchEvent(ProjectileImpactEvent event) {
    
        if (event.getEntity() instanceof ArrowEntity) {
         event.setCanceled(true);
        }
    }

     

  8. On 2/1/2020 at 12:18 PM, diesieben07 said:

    The documentation is outdated.

    Recipe types are now in vanilla and no longer patched-in by Forge.

     

    You can create your own by implementing IRecipeSerializer and registering it (it's just a normal registry entry like blocks, etc.).

    You can then refer to this from your recipe file like vanilla already does.

    Thanks! but how could I register I'm kinda confused I implemented the interface and the methods but I'm not entirely sure how can I register the recipes, and how can I use them for my custom container(crafting table) this is my code 

    public class SuitsRecipes implements IRecipeSerializer {
    
    
        public SuitsRecipes() {
            
        }
    
    
        @Override
        public IRecipe<?> read(ResourceLocation recipeId, JsonObject json) {
            return null;
        }
    
        @Nullable
        @Override
        public IRecipe<?> read(ResourceLocation recipeId, PacketBuffer buffer) {
            return null;
        }
    
        @Override
        public void write(PacketBuffer buffer, IRecipe recipe) {
    
        }
    
        @Override
        public Object setRegistryName(ResourceLocation name) {
            return null;
        }
    
        @Nullable
        @Override
        public ResourceLocation getRegistryName() {
            return null;
        }
    
        @Override
        public Class getRegistryType() {
            return null;
        }
    }
  9. 1.- You have to register the event in a class like this 

    public class YourEventClassEventHandler {
        @SubscribeEvent
        public static void negateFallDamage(LivingFallEvent event) {
    
            if (event.getEntityLiving() instanceof PlayerEntity) {
    
    
                PlayerEntity playerEntity = (PlayerEntity) event.getEntityLiving();
    
                if (playerEntity.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemHolder.BATMAN_CHEST) {
                    event.setCanceled(true);
                }
    
            }
    
        }
    
    
        @SubscribeEvent
        public static void onRenderPlayerPre(RenderPlayerEvent.Pre event) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
    
            if (player.isElytraFlying() && player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemHolder.BATMAN_CHEST) {
    
    
    
                event.getRenderer().getEntityModel().bipedRightArm.showModel = false;
                event.getRenderer().getEntityModel().bipedRightArmwear.showModel = true; //70 varillas 45 de cemento
                event.getRenderer().getEntityModel().bipedLeftArm.showModel = false;
                event.getRenderer().getEntityModel().bipedLeftArmwear.showModel = true;
                event.getRenderer().getEntityModel().bipedBody.showModel = false;
    
    
    
    
            }
    
        }
    
        @SubscribeEvent
        public static void onRenderPlayerPost(RenderPlayerEvent.Post event) {
            PlayerEntity player = event.getPlayer();
            
        }
    }

    as you can see the onRenderPlayerPre method handles the render of the player, there you can get the model and hide the body parts you want, then you can register the events in the constructor of your mod like this:

    MinecraftForge.EVENT_BUS.register(YourEventClassHandler.class);
  10.  

    Managed to change the player model for my custom elytra, however whenever I toggle the " Elytra Fly" some weird small arms appear even though I set their visibility to false, this is my code:

    @SubscribeEvent
    public static void onRenderPlayerPre(RenderPlayerEvent.Pre event) {
        PlayerEntity player = (PlayerEntity) event.getEntity();
    
        if (player.isElytraFlying() && player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemHolder.BATMAN_CHEST) {
    
    
    
         event.getRenderer().getEntityModel().bipedRightArm.showModel = false;
            event.getRenderer().getEntityModel().bipedRightArmwear.showModel = false; 
         event.getRenderer().getEntityModel().bipedLeftArm.showModel = false;
            event.getRenderer().getEntityModel().bipedLeftArmwear.showModel = false;
            event.getRenderer().getEntityModel().bipedBody.showModel = false;
    
    
    
    
        }
    
    
    }

     

    The weird arms I got:

     2020-01-29_14_15_35.png.9e73e7bd7a2a65f56ac6b8f774898b7b.png2020-01-29_14_15_33.png.528bba66fa05206e04e1032dee14342c.png

  11. On 1/26/2020 at 10:33 PM, Cadiboo said:

    It’s definitely possible to change the player model’s pose. I would look at vanilla’s code and see where it’s done from, poke around a bit and see if there are any events you can use or if there is anything that you can replace to get what you want.

    Managed to change the player model thanks, however whenever I toggle the " Elytra Fly" some weird small arms appear even though I set their visibility to false, this is my code:

    @SubscribeEvent
    public static void onRenderPlayerPre(RenderPlayerEvent.Pre event) {
        PlayerEntity player = (PlayerEntity) event.getEntity();
    
        if (player.isElytraFlying() && player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemHolder.BATMAN_CHEST) {
    
    
    
         event.getRenderer().getEntityModel().bipedRightArm.showModel = false;
            event.getRenderer().getEntityModel().bipedRightArmwear.showModel = false; 
         event.getRenderer().getEntityModel().bipedLeftArm.showModel = false;
            event.getRenderer().getEntityModel().bipedLeftArmwear.showModel = false;
            event.getRenderer().getEntityModel().bipedBody.showModel = false;
    
    
    
    
        }
    
    
    }

     

    The weird arms I got:

     2020-01-29_14_15_35.png.9e73e7bd7a2a65f56ac6b8f774898b7b.png2020-01-29_14_15_33.png.528bba66fa05206e04e1032dee14342c.pngThe 

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.