Jump to content

Warven22

Members
  • Posts

    10
  • Joined

  • Last visited

Recent Profile Visitors

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

Warven22's Achievements

Tree Puncher

Tree Puncher (2/8)

1

Reputation

  1. Please forgive this additional bump, but I want to assist future google visitors by sharing my solution. I have found a solution by using a combination of two different functions: ProjectileUtil.getEntityHitResult & Item.getPlayerPOVHitResult. getEntityHitResult doesn't take into account player's rotation. getPlayerPOVHitResult is for blocks, but takes into account player's rotation. So by using the positions from getPlayerPOVHitResult, creating a bounding box from it, and using the loop for entities in getEntityHitResult, it creates a raycast function that fires from the player's eyes to where they are pointing. I'm not sure if any of that is right, but one thing I'm sure of is it works. If you increase the range to a high number, you can detect an entity quite far away. public static EntityHitResult getPlayerPOVHitResult(Player player) { float playerRotX = player.getXRot(); float playerRotY = player.getYRot(); Vec3 startPos = player.getEyePosition(); float f2 = Mth.cos(-playerRotY * ((float)Math.PI / 180F) - (float)Math.PI); float f3 = Mth.sin(-playerRotY * ((float)Math.PI / 180F) - (float)Math.PI); float f4 = -Mth.cos(-playerRotX * ((float)Math.PI / 180F)); float additionY = Mth.sin(-playerRotX * ((float)Math.PI / 180F)); float additionX = f3 * f4; float additionZ = f2 * f4; double d0 = ZapEffect.RANGE; Vec3 endVec = startPos.add((double)additionX * d0, (double)additionY * d0, (double)additionZ * d0); AABB startEndBox = new AABB(startPos, endVec); Entity entity = null; for(Entity entity1 : player.level.getEntities(player, startEndBox, (val) -> true)) { AABB aabb = entity1.getBoundingBox().inflate(entity1.getPickRadius()); Optional<Vec3> optional = aabb.clip(startPos, endVec); if (aabb.contains(startPos)) { if (d0 >= 0.0D) { entity = entity1; startPos = optional.orElse(startPos); d0 = 0.0D; } } else if (optional.isPresent()) { Vec3 vec31 = optional.get(); double d1 = startPos.distanceToSqr(vec31); if (d1 < d0 || d0 == 0.0D) { if (entity1.getRootVehicle() == player.getRootVehicle() && !entity1.canRiderInteract()) { if (d0 == 0.0D) { entity = entity1; startPos = vec31; } } else { entity = entity1; startPos = vec31; d0 = d1; } } } } return (entity == null) ? null:new EntityHitResult(entity); }
  2. I should have made it more clear that I did try that solution and what I actually did: Vec3 start = player.getEyePosition(); Vec3 addition = player.getLookAngle().multiply(new Vec3(1000000D, 1000000D, 1000000D)); return ProjectileUtil.getEntityHitResult( player.level, player, start, start.add(addition), player.getBoundingBox().expandTowards(addition).inflate(1000000D), (val) -> true); It didn't seem to work, as the range doesn't seem as big as it should be, needing me to be a few blocks (around 10) away rather than anything in view.
  3. I've tried expandingTowards using player.getLookAngle().multiply(new Vec3(10000D, 10000D, 10000D)); rather than the player's movement (since movement can be 0), along with an inflate of a similarly large number. My range seems to have increased, but not as expected, as if I'm not visualizing how these changes to the bounding box actually affects anything. Can I set up this bounding box to be drawn in the debug elsewhere? I feel like I do not understand how the ProjectileUtil works. I don't like the idea that I'm "shooting" the player towards a point, but it seems to be the only way. Is there no other way for this to be done? No raycast function? No better way all the other modders use?
  4. I need to know how to get the mob a player is pointing at from some distance (not just regular reach distance). I looked around quite a lot in both Google and source code, but I find myself stumped, confused, and unsure. I attempted this: public static EntityHitResult getTargetedEntity(Player player) { Vec3 start = player.getEyePosition(); Vec3 addition = player.getLookAngle().multiply(new Vec3(10000D, 10000D, 10000D)); return ProjectileUtil.getEntityHitResult( player.level, player, start, start.add(addition), player.getBoundingBox().expandTowards(player.getDeltaMovement()).inflate(1.0D), (val) -> true); } It seems to work, but the range is very short regardless of the number I multiply with. Am I misunderstanding this function? Is there a better way to get the entity the player is pointing at?
  5. Yep, this worked wonderfully. Thank you so much for this clever solution! Yep, reflection worked without issue.
  6. I'm working on a mod where an effect grants the player the ability to jump out of water higher than usual. I need an event or some kind of identifier so I can adjust the delta movement to make the jump higher. Looking back at the Forge source, I see that jumpInLiquid exists, called when an entity is jumping while inside liquid. I assume the jumping out portion is just when the player gets high enough in water that the water stops slowing the vertical speed down. The LivingJumpEvent isn't called when this water jump occurs, only when jumpFromGround is called, so I can't use that event. So I need to understand how I can check for the instant when the player is 1. jumping, and 2. jumping out of water. Do I need to check when the jump key is pressed and do my own calculations & checks? Perhaps adjust vertical swim speed instead? Or maybe check to see if the block below the player is water when they previously were in water and now aren't.
  7. Vanilla is Minecraft without any mods. If a mod talks about "enhanced vanilla", or "vanilla with sprinkles", it's implying that it's regular Minecraft with only slight changes or additions that do not alter the feel of the normal game.
  8. I gave this a shot, but it didn't fix the issue. Nothing debug-wise seemed off. ItemStacks matched up properly, item duration was as expected, etc. Messing around in Minecraft itself, I clicked a chest. The item in question in my inventory disappeared. I tried taking the item directly from the mod ItemGroup, and the drinking worked like normal. If the item was droppable, its drinking would work. If it disappeared when I tried to drop it, it was one of the ones with bugged drinking. What I'm using to add the item to the inventory after a special block is interacted with in onBlockActivated: player.addItemStackToInventory(new ItemStack(ModItems.CAN_EXPRESSO, 1)); Is this the incorrect way to handle it? I also tried using the player's inventory to add a stack directly, but both approaches caused this bugged drink.
  9. EDIT: It had nothing to do with the item. It was entirely on how it was given to the player. The player right-clicks a block that then gives the item directly to the player's inventory. However, while debugging and using the logger, I noticed onBlockActivated called twice. I found out this is because it runs the function for the server and client. So, thinking "I DoN'T WaNT The functIOn To be cALlED TwicE", I told the function to stop early if the world being given is a ServerWorld, so it'd only run on the client. This is dumb. When the item was used by the client, the server didn't think it existed, causing it to disappear when dropped, and not work correctly otherwise. By removing that code, it ran correctly (without doing things like giving the item twice as I thought it would). Post all related code when on a support forum, folks. The problem may not be what you think it is. I am currently working on a mod that involves a drinkable item. Here's the code for said item: package com.warven22.sodapop.items; import com.warven22.sodapop.init.ModItemGroups; import net.minecraft.item.Food.Builder; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.UseAction; public class ExpressoCan extends Item { public ExpressoCan() { super(new Item.Properties().group(ModItemGroups.MOD_ITEM_GROUP). maxStackSize(64). food(new Builder().setAlwaysEdible().build())); } @Override public UseAction getUseAction(ItemStack stack) { return UseAction.DRINK; } } The drinking animation starts just fine, but after the normal drinking time should end, the arm returns to normal, but the sounds continue beyond. My speed stays low during the use, so it appears as if I'm still drinking. The event onItemUseFinish doesn't call either, as I assume the usage is never finishing. I attempted to try it without overriding getUseAction, but the same problem occurs with the eating animation, with the particles joining the continuing sound. The animation would stop when I let go of the mouse, but the item would stay in my inventory, and the normal "burp" sound never played. I checked using a vanilla Minecraft potion and food item. Both acted normally. Sometimes, after drinking a vanilla potion, the mod item would be consumable normally, but this was inconsistent and rarely happened. I searched the forum and google extensively to try and find someone with the same issue, but I have been unsuccessful. I used existing mod GitHub repositories to see if there was something I was just missing in my code. However, their code doesn't look far off from mine. I am stumped, as this item has very little code attached to it for it to break. Perhaps I'm just missing something crucial? I am new to modding.
×
×
  • Create New...

Important Information

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