Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

NoobMaster4000

Members
  • Joined

  • Last visited

Everything posted by NoobMaster4000

  1. Hello, I have a little API mod (Or a library, core or how you want to call it) that has methods used to spawn items/mobs/etc but I have problems setting attributes/NBT to an entity. This is how I spawn an entity without armor public static void SpawnEntityNoArmor(World worldIn, int x, int y, int z, Class<? extends Entity> entity, int amount, Boolean hasCustomName, @Nullable String name, Boolean hasMessage, @Nullable EntityPlayer player, @Nullable String message, Boolean hasCustomHealth, @Nullable Integer health) { for (int b = 0; b < amount; b++) { Entity en = EntityList.newEntity(entity, worldIn); en.setPositionAndUpdate(x, y, z); if (hasCustomName) { en.setCustomNameTag(Messages.color(name)); } if (hasCustomHealth) { } worldIn.spawnEntity(en); } if (hasMessage) { Messages.sendMessage(player, message); } } I use Entity en = EntityList.newEntity(entity, worldIn); because is the only method I've found on the internet that let me spawn an entity using EntityName.class I don't know how to add to this entity an attribute/NBT because en.getEntityAttribute doesn't exists Calling the method with: EntityHelper.SpawnEntityNoArmor(worldIn, x + new Random().nextInt(12) - 6, y, z + new Random().nextInt(12) - 6, EntitySheep.class, new Random().nextInt(8) + 1, true, "jeb_", true, player, "I'm a sheep"); If you want to know what "EntityHelper" class contain is just this method above (the first one) plus some other useless methods for this question How can I set an entity Attribute using my entity spawn method or using a different method that let me dynamically choose an entity?
  2. Models must be registered in ModelRegistryEvent. @SubscribeEvent public static void onItemRegister(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(InitItems.ITEMS.toArray(new Item[0])); } @SubscribeEvent public static void onBlockRegister(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(InitBlocks.BLOCKS.toArray(new Block[0])); } @SubscribeEvent public static void onModelRegister(ModelRegistryEvent event) { for (Item item : InitItems.ITEMS) { if (item instanceof ModelManager) { ((ModelManager) item).registerModels(); } } for (Block block : InitBlocks.BLOCKS) { if (block instanceof ModelManager) { ((ModelManager) block).registerModels(); } } } public static void registerBlock(Block block, ItemBlock itemBlock) { block.setCreativeTab(Main.MISC_TAB); InitBlocks.BLOCKS.add(block); InitItems.ITEMS.add(itemBlock.setRegistryName(block.getRegistryName())); } public static void RegisterInfiniteBlockRender(Block block, int meta, String filename) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), meta, new ModelResourceLocation(new ResourceLocation(Main.MODID, filename), "inventory")); } public static void RenderInfiniteBlock(){ for (int i = 0; i < InfiniteBlockTypes.values().length; i++) { RegisterInfiniteBlockRender(InitBlocks.INFINITE_BLOCK, i, "infinite_block_" + InfiniteBlockTypes.values()[i].getName()); } } ModelBakery#registerItemVariants only tells Minecraft to load and bake these models, it does not bind them to a particular item. Use ModelLoader.setCustomModelResourceLocation. Is it wrong? public static void RegisterInfiniteBlockRender(Block block, int meta, String filename) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), meta, new ModelResourceLocation(new ResourceLocation(Main.MODID, filename), "inventory")); } public static void RenderInfiniteBlock(){ for (int i = 0; i < InfiniteBlockTypes.values().length; i++) { RegisterInfiniteBlockRender(InitBlocks.INFINITE_BLOCK, i, "infinite_block_" + InfiniteBlockTypes.values()[i].getName()); } } Off topic question: Why are my spoilers like this?
  3. Hello, I have problems rendering the itemblock with metadata client and server-side. Here's the error: This is the block class: IMetaBlockName class: ItemInfiniteBlock: RegistryHandler (to register all metadata renders) ClientProxy: Main class Init/PreInit ("proxy" point to CommonProxy class): infinite_block.json (Blockstate): { "variants": { "color=white": { "model": "testmod:infinite_block_white" }, "color=orange": { "model": "testmod:infinite_block_orange" }, "color=magenta": { "model": "testmod:infinite_block_magenta" }, "color=light_blue": { "model": "testmod:infinite_block_light_blue" }, "color=yellow": { "model": "testmod:infinite_block_yellow" }, "color=lime": { "model": "testmod:infinite_block_lime" }, "color=pink": { "model": "testmod:infinite_block_pink" }, "color=gray": { "model": "testmod:infinite_block_gray" }, "color=light_gray": { "model": "testmod:infinite_block_light_gray" }, "color=cyan": { "model": "testmod:infinite_block_cyan" }, "color=purple": { "model": "testmod:infinite_block_purple" }, "color=blue": { "model": "testmod:infinite_block_blue" }, "color=brown": { "model": "testmod:infinite_block_brown" }, "color=green": { "model": "testmod:infinite_block_green" }, "color=red": { "model": "testmod:infinite_block_red" }, "color=black": { "model": "testmod:infinite_block_black" } } } The blocks are rendered when placed but not in my inventory, is displayed the missing texture. How can I render them to see the texture client and server side?
  4. Teleport or create the explosion... It was the same. I had the same problem. Oh, okay then I didn't get teleported because low render distance (was 4)
  5. It works! thanks. A little question; if I want to teleport me far do I have to change the 64 to >64 (I mean more like "400")?
  6. But the vanilla bow is the same with my arrows, I mean same animation (in the video)
  7. public class ExplosiveArrow extends ItemArrow implements ModelManager { public ExplosiveArrow(String name) { setRegistryName(name); setUnlocalizedName(name); setCreativeTab(Main.TOOLS_N_SWORD_TAB); InitItems.ITEMS.add(this); } @Override public EntityArrow createArrow(World world, ItemStack stack, EntityLivingBase shooter) { EntitySimpleArrow arrow = new EntitySimpleArrow(world, shooter); arrow.setDamage(1); return arrow; } @Override public void registerModels() { Main.proxy.registerItemRenderer(this, 0, "inventory"); } }
  8. public class Bow extends ItemBow implements ModelManager { public Bow(String name) { setUnlocalizedName(name); setRegistryName(name); setMaxStackSize(1); setCreativeTab(Main.TOOLS_N_SWORD_TAB); InitItems.ITEMS.add(this); } @Override public void registerModels() { Main.proxy.registerItemRenderer(this, 0, "inventory"); } @Override public boolean hasEffect(ItemStack stack) { return true; } This ^^^ is my bow class. Using the vanilla bow is the same Arrow Render: public class ExplosiveArrow extends RenderArrow<EntitySimpleArrow> { public static final ResourceLocation TEXTURES = new ResourceLocation(Main.MODID + ":textures/entity/explosive_arrow.png"); public ExplosiveArrow(RenderManager manager) { super(manager); } @Override protected ResourceLocation getEntityTexture(EntitySimpleArrow entity) { return TEXTURES; } Register the arrow: public class InitEntity { public static void registerEntities() { registerEntity("explosive_arrow", EntitySimpleArrow.class, Main.ENTITY_EXPLOSIVE_ARRROW, 64, 20, false); registerEntity("teleport_arrow", EntityTeleportArrow.class, Main.ENTITY_TELEPORT_ARRROW, 64, 20, false); } private static void registerEntity(String name, Class<? extends Entity> entity, int id, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates) { EntityRegistry.registerModEntity(new ResourceLocation(Main.MODID + ":" + name), entity, name, id, Main.instance, trackingRange, updateFrequency, sendsVelocityUpdates); } }
  9. Sorry, I didn't see your question so I asked. I only added onHit The class: public class EntityTeleportArrow extends EntityArrow { public EntityTeleportArrow(World worldIn) { super(worldIn); } public EntityTeleportArrow(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } public EntityTeleportArrow(World worldIn, EntityLivingBase shooter) { super(worldIn, shooter); } @Override protected ItemStack getArrowStack() { return null; } @Override protected void onHit(RayTraceResult raytraceResultIn) { BlockPos blockpos = raytraceResultIn.getBlockPos(); if (this.shootingEntity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) this.shootingEntity; System.out.println(blockpos); int x = blockpos.getX(); int y = blockpos.getY(); int z = blockpos.getZ(); player.setPositionAndUpdate(x, y + 1, z); this.setDead(); } } }
  10. @Override protected void onHit(RayTraceResult raytraceResultIn) { BlockPos blockpos = raytraceResultIn.getBlockPos(); if (this.shootingEntity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) this.shootingEntity; System.out.println(blockpos); int x = blockpos.getX(); int y = blockpos.getY(); int z = blockpos.getZ(); world.createExplosion(player, x, y, z, 4, true); this.setDead(); } } The system.out.println prints where the arrow lands (and where it create the explosion)
  11. Work! Thanks. Now I have to know why when I use the arrow I see it fall after I shoot the arrow. I mean, it works but I shoot the arrow and it "fell" on the ground but it teleports me where it lands. How is when I shoot the arrow: 2019-10-07 15-20-40.mp4
  12. Hello, I'm trying to create an explosive arrow and I experienced one issue, using this onUpdate (Yeah copied the EntityArrow code) and using my bow (which is simply extends ItemBow) the arrow one it lands keep dying and respawn causing a horrible sound without creating any explosion. public class EntityExplosiveArrow extends EntityArrow { private int xTile; private int yTile; private int zTile; private Block inTile; private int inData; protected boolean inGround; protected int timeInGround; private int ticksInGround; private int ticksInAir; private double damage; /** The amount of knockback an arrow applies when it hits a mob. */ private int knockbackStrength; public EntityExplosiveArrow(World worldIn) { super(worldIn); } public EntityExplosiveArrow(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } public EntityExplosiveArrow(World worldIn, EntityLivingBase shooter) { super(worldIn, shooter); } @Override protected ItemStack getArrowStack() { return null; } @Override public void onUpdate() { if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI)); this.rotationPitch = (float) (MathHelper.atan2(this.motionY, (double) f) * (180D / Math.PI)); this.prevRotationYaw = this.rotationYaw; this.prevRotationPitch = this.rotationPitch; } BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile); IBlockState iblockstate = this.world.getBlockState(blockpos); Block block = iblockstate.getBlock(); if (iblockstate.getMaterial() != Material.AIR) { AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos); if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).contains(new Vec3d(this.posX, this.posY, this.posZ))) { this.inGround = true; } } if (this.arrowShake > 0) { --this.arrowShake; } if (this.inGround) { int j = block.getMetaFromState(iblockstate); if ((block != this.inTile || j != this.inData) && !this.world.collidesWithAnyBlock(this.getEntityBoundingBox().grow(0.05D))) { this.inGround = false; this.motionX *= (double) (this.rand.nextFloat() * 0.2F); this.motionY *= (double) (this.rand.nextFloat() * 0.2F); this.motionZ *= (double) (this.rand.nextFloat() * 0.2F); this.ticksInGround = 0; this.ticksInAir = 0; } else { ++this.ticksInGround; this.world.createExplosion(this, posX, posY, posZ, 4, true); this.setDead(); if (this.ticksInGround >= 1200) { this.setDead(); } } ++this.timeInGround; } else { this.timeInGround = 0; ++this.ticksInAir; Vec3d vec3d1 = new Vec3d(this.posX, this.posY, this.posZ); Vec3d vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d1, vec3d, false, true, false); vec3d1 = new Vec3d(this.posX, this.posY, this.posZ); vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (raytraceresult != null) { vec3d = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z); } Entity entity = this.findEntityOnPath(vec3d1, vec3d); if (entity != null) { raytraceresult = new RayTraceResult(entity); } if (raytraceresult != null && raytraceresult.entityHit instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer) raytraceresult.entityHit; if (this.shootingEntity instanceof EntityPlayer && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) { raytraceresult = null; } } if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) { this.onHit(raytraceresult); } if (this.getIsCritical()) { for (int k = 0; k < 4; ++k) { this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX + this.motionX * (double) k / 4.0D, this.posY + this.motionY * (double) k / 4.0D, this.posZ + this.motionZ * (double) k / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ); } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float f4 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI)); for (this.rotationPitch = (float) (MathHelper.atan2(this.motionY, (double) f4) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { ; } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float f1 = 0.99F; float f2 = 0.05F; if (this.isInWater()) { for (int i = 0; i < 4; ++i) { float f3 = 0.25F; this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ); } f1 = 0.6F; } if (this.isWet()) { this.extinguish(); } this.motionX *= (double) f1; this.motionY *= (double) f1; this.motionZ *= (double) f1; if (!this.hasNoGravity()) { this.motionY -= 0.05000000074505806D; } this.setPosition(this.posX, this.posY, this.posZ); this.doBlockCollisions(); } }
  13. Hello, I have problems spawning a structure where is player is looking at, the structure is a NBT file. How can I spawn it correctly?

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.