
Somonestolemyusername
Members-
Content Count
68 -
Joined
-
Last visited
Everything posted by Somonestolemyusername
-
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
I have something like that here is the similar code I wrote package com.vicken.mod3.items; import com.vicken.mod3.util.RegistryHandler; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.item.ArrowItem; import net.minecraft.item.BowItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.stats.Stats; import net.minecraft.tags.ItemTags; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvents; import net.minecraft.world.World; import java.util.function.Predicate; public class ModBow extends BowItem { public ModBow(Properties builder) { super(builder); } public void onPlayerStoppedUsing(ItemStack bowStack, World worldIn, LivingEntity entityLiving, int timeLeft) { if (entityLiving instanceof PlayerEntity) { PlayerEntity playerentity = (PlayerEntity)entityLiving; boolean hasInfinity = playerentity.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, bowStack) > 0; ItemStack ammoStack = playerentity.findAmmo(bowStack); int timeDrawn = this.getUseDuration(bowStack) - timeLeft; timeDrawn = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(bowStack, worldIn, playerentity, timeDrawn, !ammoStack.isEmpty() || hasInfinity); if (timeDrawn < 0) return; if (!ammoStack.isEmpty() || hasInfinity) { boolean isTippedArrow = ammoStack.getItem() == RegistryHandler.BULLET.get() || ammoStack.getItem() == RegistryHandler.BULLET.get(); if (ammoStack.isEmpty()) { ammoStack = new ItemStack(RegistryHandler.BULLET.get()); } float velocity = getArrowVelocity(timeDrawn); if (!((double)velocity < 100.1D)) { if (!worldIn.isRemote) { AbstractArrowEntity arrowEntity = createArrow(worldIn, ammoStack, playerentity); arrowEntity.shoot(playerentity, playerentity.rotationPitch, playerentity.rotationYaw, 0.0F, velocity * 100.0F, 0.0F); if (velocity == 1000.0F) arrowEntity.setIsCritical(true); double damage = getArrowDamage(bowStack, arrowEntity); arrowEntity.setDamage(damage); int knockback = getArrowKnockback(bowStack, arrowEntity); arrowEntity.setKnockbackStrength(knockback); // apply flame enchant if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, bowStack) > 0) { arrowEntity.setFire(100); } // reduce bow durability bowStack.damageItem(1, playerentity, (p_220009_1_) -> { p_220009_1_.sendBreakAnimation(playerentity.getActiveHand()); }); // set if arrow can be picked up from ground if (hasInfinity && !isTippedArrow) { arrowEntity.pickupStatus = AbstractArrowEntity.PickupStatus.DISALLOWED; } // actually make the arrow entity exist in the world worldIn.addEntity(arrowEntity); } // sound worldIn.playSound((PlayerEntity)null, playerentity.getPosX(), playerentity.getPosY(), playerentity.getPosZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + velocity * 100.5F); // use an arrow boolean shouldConsumeArrow = !hasInfinity || isTippedArrow; if (shouldConsumeArrow) { ammoStack.shrink(1); if (ammoStack.isEmpty()) { playerentity.inventory.deleteStack(ammoStack); } } playerentity.addStat(Stats.ITEM_USED.get(this)); } } } } // override to use a custom arrow entity protected AbstractArrowEntity createArrow(World worldIn, ItemStack ammoStack, PlayerEntity playerentity) { ArrowItem arrowitem = (ArrowItem)(ammoStack.getItem() instanceof ArrowItem ? ammoStack.getItem() : RegistryHandler.BULLET.get()); return arrowitem.createArrow(worldIn, ammoStack, playerentity); } protected double getArrowDamage(ItemStack bowStack, AbstractArrowEntity arrowEntity) { int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, bowStack); if (powerLevel > 0) return arrowEntity.getDamage() + (double)powerLevel * 100.5D + 0.5D; else return arrowEntity.getDamage(); } protected int getArrowKnockback(ItemStack bowStack, AbstractArrowEntity arrowEntity) { return EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, bowStack); } // Override to change what it uses as ammo public Predicate<ItemStack> getInventoryAmmoPredicate() { return (ammoStack) -> { return ammoStack.getItem() == RegistryHandler.BULLET.get(); }; } @Override public Predicate<ItemStack> getAmmoPredicate() { return (ammoStack) -> { return ammoStack.getItem() == RegistryHandler.BULLET.get(); }; } public static float getArrowVelocity(int charge) { float f = (float)charge / 100.0F; f = (f * f + f * 100.0F) / 100.0F; if (f > 100.0F) { f = 100.0F; } return f; } } but for some reason its not shooting the bullets -
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
all i has in it is package com.vicken.mod3.entities.projectiles; import com.vicken.mod3.util.RegistryHandler; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.WallTorchBlock; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.projectile.ArrowEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.Effects; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; public class Ak47ArrowEntity extends ArrowEntity { public Ak47ArrowEntity(World worldIn, LivingEntity shooter) { super(worldIn, shooter); RegistryHandler.BULLET.get(); } @Override protected void arrowHit(LivingEntity living) { super.arrowHit(living); living.setFire(15); } } -
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
ok can u help write the code? i started learning to mod a few weeks ago all i know is items armors block recipes and other stuff. also I already have a projectile class named Ak47ArrowEntity -
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
but if I use the snowball class it will be like im shooting snowballs not bullets. you know mr crayfishes gun mod? i want my gun to be somewhat like that also i figured out how to connect my registered object to the class -
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
oh I thought i just needed onUsingTick. also I looked over your code and I don't want my Gun/Bow shooting bullets like a snowball I want it to actually shoot like a real ak47 as i said before -
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
I tried using the onUsingTick but it made my game crashed even when i reduced the tick to 1 -
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
here is the code for the gun i made and registered public static final RegistryObject<Item> AK47 = ITEMS.register("ak47", () -> new Ak47(new Item.Properties().group(ModItemGroup.instance).maxDamage(10000))); Ak47 class: package com.vicken.mod3.items; import com.vicken.mod3.entities.projectiles.Ak47ArrowEntity; import com.vicken.mod3.util.RegistryHandler; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.entity.projectile.ArrowEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.world.World; import java.util.function.Predicate; public class Ak47 extends ModBow { public Ak47(Properties builder) { super(builder); } @Override protected AbstractArrowEntity createArrow(World worldIn, ItemStack ammoStack, PlayerEntity playerentity) { return new Ak47ArrowEntity(worldIn, playerentity); } @Override protected double getArrowDamage(ItemStack bowStack, AbstractArrowEntity arrowEntity) { int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, bowStack); return (double)powerLevel * 100.5D + 100.5D; } @Override public Predicate<ItemStack> getInventoryAmmoPredicate() { return (ammoStack) -> { return ammoStack.getItem() == RegistryHandler.BULLET.get(); }; } } modBow class: package com.vicken.mod3.items; import com.vicken.mod3.util.RegistryHandler; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.item.ArrowItem; import net.minecraft.item.BowItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.stats.Stats; import net.minecraft.tags.ItemTags; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvents; import net.minecraft.world.World; import java.util.function.Predicate; public class ModBow extends BowItem { public ModBow(Properties builder) { super(builder); } public void onPlayerStoppedUsing(ItemStack bowStack, World worldIn, LivingEntity entityLiving, int timeLeft) { if (entityLiving instanceof PlayerEntity) { PlayerEntity playerentity = (PlayerEntity)entityLiving; boolean hasInfinity = playerentity.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, bowStack) > 0; ItemStack ammoStack = playerentity.findAmmo(bowStack); int timeDrawn = this.getUseDuration(bowStack) - timeLeft; timeDrawn = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(bowStack, worldIn, playerentity, timeDrawn, !ammoStack.isEmpty() || hasInfinity); if (timeDrawn < 0) return; if (!ammoStack.isEmpty() || hasInfinity) { boolean isTippedArrow = ammoStack.getItem() == RegistryHandler.BULLET.get() || ammoStack.getItem() == RegistryHandler.BULLET.get(); if (ammoStack.isEmpty()) { ammoStack = new ItemStack(RegistryHandler.BULLET.get()); } float velocity = getArrowVelocity(timeDrawn); if (!((double)velocity < 100.1D)) { if (!worldIn.isRemote) { AbstractArrowEntity arrowEntity = createArrow(worldIn, ammoStack, playerentity); arrowEntity.shoot(playerentity, playerentity.rotationPitch, playerentity.rotationYaw, 0.0F, velocity * 100.0F, 1.0F); if (velocity == 1.0F) arrowEntity.setIsCritical(true); double damage = getArrowDamage(bowStack, arrowEntity); arrowEntity.setDamage(damage); int knockback = getArrowKnockback(bowStack, arrowEntity); arrowEntity.setKnockbackStrength(knockback); // apply flame enchant if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, bowStack) > 0) { arrowEntity.setFire(100); } // reduce bow durability bowStack.damageItem(1, playerentity, (p_220009_1_) -> { p_220009_1_.sendBreakAnimation(playerentity.getActiveHand()); }); // set if arrow can be picked up from ground if (hasInfinity && !isTippedArrow) { arrowEntity.pickupStatus = AbstractArrowEntity.PickupStatus.DISALLOWED; } // actually make the arrow entity exist in the world worldIn.addEntity(arrowEntity); } // sound worldIn.playSound((PlayerEntity)null, playerentity.getPosX(), playerentity.getPosY(), playerentity.getPosZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + velocity * 100.5F); // use an arrow boolean shouldConsumeArrow = !hasInfinity || isTippedArrow; if (shouldConsumeArrow) { ammoStack.shrink(1); if (ammoStack.isEmpty()) { playerentity.inventory.deleteStack(ammoStack); } } playerentity.addStat(Stats.ITEM_USED.get(this)); } } } } // override to use a custom arrow entity protected AbstractArrowEntity createArrow(World worldIn, ItemStack ammoStack, PlayerEntity playerentity) { ArrowItem arrowitem = (ArrowItem)(ammoStack.getItem() instanceof ArrowItem ? ammoStack.getItem() : RegistryHandler.BULLET.get()); return arrowitem.createArrow(worldIn, ammoStack, playerentity); } protected double getArrowDamage(ItemStack bowStack, AbstractArrowEntity arrowEntity) { int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, bowStack); if (powerLevel > 0) return arrowEntity.getDamage() + (double)powerLevel * 100.5D + 0.5D; else return arrowEntity.getDamage(); } protected int getArrowKnockback(ItemStack bowStack, AbstractArrowEntity arrowEntity) { return EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, bowStack); } // Override to change what it uses as ammo public Predicate<ItemStack> getInventoryAmmoPredicate() { return (ammoStack) -> { return ammoStack.getItem().isIn(ItemTags.ARROWS); }; } public static float getArrowVelocity(int charge) { float f = (float)charge / 100.0F; f = (f * f + f * 100.0F) / 100.0F; if (f > 100.0F) { f = 100.0F; } return f; } } but for some reason the bullet is not shooting and also idk how to make it shoot constantly so i don't have to wait for it to load like a real bow and so it can shoot like a real ak47 does -
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
I want to add my custom bow class because it makes it so that the ammo is bullets, and the speed of the throwing is velocity 100 and that it shoots constantly and not like a real bow but like a ak47 I was able to do this with mcreator but i cant seem to do it with java. -
[1.15.2] How Would I make a custom bow?
Somonestolemyusername replied to Somonestolemyusername's topic in Modder Support
I did that but I'm saying I made a separate mod class for it and I want to take the properties from there and put it into the bow while registering. -
hi. I am trying to make a custom gun/bow I got the properties ready but idk how to connect it to the object in the registry handler. can someone help?
-
[1.15.2] Armor Model Not Registering To Armor
Somonestolemyusername posted a topic in Modder Support
so in my mod I made netherite armor, and the item texture for the chestplate and boots are working except the other pieces, but when i put on the armor the texture in my resources/assets/my_mod/textures/models/armor isint registering to the armor therefore giving me the error texture. how do I fix this? -
[1.16.4] Mod registries not loaded before Event Listener
Somonestolemyusername replied to st4s1k's topic in Modder Support
ok -
[1.16.4] Mod registries not loaded before Event Listener
Somonestolemyusername replied to st4s1k's topic in Modder Support
what version of minecraft are you coding in?