Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

jaxbymc42

Members
  • Posts

    17
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

jaxbymc42's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I have changed the code so that it now overrides the method. However, I think there are some problems with my raytracing method. It does not properly trace where the player is looking and grabbing that block pos.
  2. I do now realize that I wasn't using the correct method. I have changed "onItemRightClick" to "use" and now the item does function. It functions because I also added the entity to the world, as you had mentioned that I had not added it (oops). Now, it does summon lightning, but only whenever I look certain ways and my ray tracing does not work well because the lightning is not summoned where I am looking. I will try to use getLookVec (or whatever the name is) to trace instead and see how that goes.
  3. Hello! I am looking to use ray tracing to find the position of the block the player is looking at. Then, when the player right clicks the item, it summons a lightning bolt at that block's location. I have created my own code for this, but nothing is currently working (not summoning lightning at all). I am new to ray tracing but apparently this is not how it is done (question mark?). I am just looking to see what I have done wrong and to build on knowledge for the future. import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.effect.LightningBoltEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.stats.Stats; import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceContext; import net.minecraft.util.math.RayTraceContext.FluidMode; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; public class LightningWandItem extends Item { public LightningWandItem(Properties properties) { super(properties); } private RayTraceResult rayTrace(World world, PlayerEntity player) { float rotationPitch = player.getYHeadRot(); float rotationYaw = player.xRot; Vector3d eyePosition = player.getEyePosition(1.0F); // look vector float f2 = MathHelper.cos(-rotationYaw * ((float)Math.PI / 180F) - (float)Math.PI); float f3 = MathHelper.sin(-rotationYaw * ((float)Math.PI / 180F) - (float)Math.PI); float f4 = -MathHelper.cos(-rotationPitch * ((float)Math.PI / 180F)); float f5 = MathHelper.sin(-rotationPitch * ((float)Math.PI / 180F)); float f6 = f3 * f4; float f7 = f2 * f4; double rayTraceDistance = 54; // from start pos, add look vector multiplied by rayTraceDistance Vector3d endPosition = eyePosition.add((double)f6 * rayTraceDistance, (double)f5 * rayTraceDistance, (double)f7 * rayTraceDistance); return world.clip(new RayTraceContext(eyePosition, endPosition, RayTraceContext.BlockMode.OUTLINE, FluidMode.NONE, player)); } public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { if(!worldIn.isClientSide) { ItemStack stack = playerIn.getItemInHand(handIn); RayTraceResult result = this.rayTrace(worldIn, playerIn); if(result instanceof BlockRayTraceResult) { BlockPos pos = ((BlockRayTraceResult) result).getBlockPos(); Block block = worldIn.getBlockState(pos).getBlock(); if(block != Blocks.AIR) { if(worldIn instanceof ServerWorld) { LightningBoltEntity lightningEntity = new LightningBoltEntity(EntityType.LIGHTNING_BOLT, worldIn); lightningEntity.setPos(pos.getX(), pos.getY(), pos.getZ()); playerIn.awardStat(Stats.ITEM_USED.get(this)); if (!playerIn.abilities.mayfly) { stack.hurtAndBreak(1, playerIn, (p_219998_1_) -> { p_219998_1_.broadcastBreakEvent(handIn); }); } } } return new ActionResult<ItemStack>(ActionResultType.SUCCESS, stack); } else if(result instanceof EntityRayTraceResult) { Entity entity = ((EntityRayTraceResult) result).getEntity(); if(worldIn instanceof ServerWorld) { Vector3d entityPos = entity.position(); LightningBoltEntity lightningEntity = new LightningBoltEntity(EntityType.LIGHTNING_BOLT, worldIn); lightningEntity.setPos(entityPos.x(), entityPos.y(), entityPos.z()); playerIn.awardStat(Stats.ITEM_USED.get(this)); if (!playerIn.abilities.mayfly) { stack.hurtAndBreak(1, playerIn, (p_219998_1_) -> { p_219998_1_.broadcastBreakEvent(handIn); }); } } return new ActionResult<ItemStack>(ActionResultType.SUCCESS, stack); } playerIn.getItemInHand(handIn); } return super.use(worldIn, playerIn, handIn); } }
  4. How exactly do I go about using LivingEquipmentChangeEvent?
  5. public class HoneyArmorItem extends ArmorItem { public HoneyArmorItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) { super(materialIn, slot, builder); } @Override public void onArmorTick(ItemStack stack, World world, PlayerEntity player) { if(player.inventory.armorItemInSlot(0).getItem() == ItemInit.HONEY_BOOTS.get() && player.inventory.armorItemInSlot(1).getItem() == ItemInit.HONEY_LEGGINGS.get() && player.inventory.armorItemInSlot(2).getItem() == ItemInit.HONEY_CHESTPLATE.get() && player.inventory.armorItemInSlot(3).getItem() == ItemInit.HONEY_HELMET.get()) { player.getAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(new AttributeModifier("MaxHealth", 4.0f, AttributeModifier.Operation.ADDITION)); } else { super.onArmorTick(stack, world, player); player.getAttribute(SharedMonsterAttributes.MAX_HEALTH).removeModifier(new AttributeModifier("MaxHealth", 4.0f, AttributeModifier.Operation.ADDITION)); } } }
  6. I tried applying modifiers straight out but then I ran into the issue of infinitely adding 2 more hearts.
  7. I have made a set of armor that, when the full set is worn, the player is granted with 2 additional hearts. Whenever you take the armor off, the two extra hearts disappear but are still "there" and the player acts as though he has 12 hearts when only 10 are shown (until the player takes enough damage to lose those 2 extra hearts then it is like vanilla MC with 10 hearts). I was just wondering what else to do to check and remove the extra life so when the armor is off, the player has only 10 hearts (not the extra 2 hearts that are "there" till damage gets rid of them). public class HoneyArmorItem extends ArmorItem { public HoneyArmorItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) { super(materialIn, slot, builder); } @Override public void onArmorTick(ItemStack stack, World world, PlayerEntity player) { if(player.inventory.armorItemInSlot(0).getItem() == ItemInit.HONEY_BOOTS.get() && player.inventory.armorItemInSlot(1).getItem() == ItemInit.HONEY_LEGGINGS.get() && player.inventory.armorItemInSlot(2).getItem() == ItemInit.HONEY_CHESTPLATE.get() && player.inventory.armorItemInSlot(3).getItem() == ItemInit.HONEY_HELMET.get()) { player.getAttributes().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(24); } else { super.onArmorTick(stack, world, player); player.getAttributes().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20); } } }
  8. Okay. I realized I made up a method and also did not check if a player is in creative mode or not to shrink the item stack.
  9. Hello! I am currently trying to add an item that, upon right click, gives the player some experience by spawning some xp orbs on the players location. I thought this was correct but clearly it isn't. When right clicked, the edible experience item does not do anything. Pastebin for edible experience class: https://pastebin.com/5u1vCrx6 Thank you for your time.
  10. I thought that the lines below did that in my main class: @SubscribeEvent public static void onRegisterItems(final RegistryEvent.Register<Item> event) { final IForgeRegistry<Item> registry = event.getRegistry(); BlockInit.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(block -> { final Item.Properties properties = new Item.Properties().group(ChrispyModItemGroup.instance); final BlockItem blockItem = new BlockItem(block, properties); blockItem.setRegistryName(block.getRegistryName()); registry.register(blockItem); }); LOGGER.debug("Registered BlockItems!"); }
  11. Since moving everything to deferred registries, my mod's blocks are not in the game. The ore gen generates the ores underground and the blocks appear with textures and all but there is no possible way of obtaining the blocks (not in creative menu, /give doesn't work, middle clicking the ore doesn't work). The blocks can't even be crafted. The only leading bit of information I have is the log says this for every one of my mod's blocks when loading a world: "[Server thread/ERROR] [minecraft/LootTableManager]: Couldn't parse loot table chrispymod:blocks/cyan_redstone_lamp com.google.gson.JsonSyntaxException: Expected name to be an item, was unknown string 'chrispymod:cyan_redstone_lamp'" There are also parsing errors when loading recipes. My loot tables have not been moved and I did not encounter this issue before switching to deferred registries. I have attached ChrispyMod.java (Main), BlockInit.java, and my latest.log. If something will not load or you need more info, let me know. I am genuinely stuck and have no idea what is wrong. Any help is appreciated. Thank you for your time. ChrispyMod.java BlockInit.java latest.log
  12. I took your advice and now the item is working... kind of. The only issue now is that it won't shoot in the y-range (up or down). It only shoots straight out no matter how high or low I look. Basically, I used the code from GhastEntity like you had mentioned and targetted the PlayerEntity instead of the livingentity variable but with negative values so the fireball shot away from the player. https://pastebin.com/Q9RwgBNf
  13. Okay, so I have changed a bunch of code and now the fireball shoots but only in one general direction (it varies a little bit on the direction every time I throw it). The fireballs fly into the +X and +Z plane. I don't understand raytracing very well as I haven't worked with it much up until this point. https://pastebin.com/Xt9M3Rkd
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.