Jump to content

Gepardius

Members
  • Posts

    34
  • Joined

  • Last visited

Everything posted by Gepardius

  1. Another topic that I have: If I want to create skill points, example teleport. I've created a global static variable inside the ability class: public class Ability { public static int teleport; and then I increase the variable with: Ability.teleport += 1; On the server the teleport variable is stored as long as the server is running, once I reset the server the variable is reset and null again. Which in theory should not be an issue since the server is always running. And on the client it is the same, as long as I don't shut down the client the variable is stored and I can enter/exit as much as I like and don't lose the value of the variable. However, how would I store the value of a variable inside the world save?
  2. I understood that the Double with capital D is an object, used for complex methods, whereas double with non-capital d can be used for simple computation/methods. In general there aren't many cases where you could go wrong using Double instead of double and vice-versa. At least for simple projects as in Minecraft modding. Please do correct me, if I am in any way wrong.
  3. You're right, but this Double value might be null in the future, whereas double value cannot be null. I'll change it to just double for now, since it is a fixed value for now.
  4. So the update: Your code works on both client and server. The issue before was that I kept the server running, made changes in the editor and only restarted the client. Then I expected the same code to magically run on the server as well... Very dumb mistake on my part. @Override public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { Double distance = 500.0D; if (player instanceof ServerPlayer serverPlayer) { HitResult viewedBlock = player.pick(distance, 0.0F, false); Double x = viewedBlock.getLocation().x; Double y = viewedBlock.getLocation().y; Double z = viewedBlock.getLocation().z; y += 1; player.teleportToWithTicket(x, y, z); // serverPlayer.connection.teleport(x, y, z, 0.0F, 0.0F); } return super.use(level, player, hand); } So I ended up using the .teleportToWithTicket as Luis_ST initially suggested, so I don't have to adapt the head positioning.
  5. I'll try it once I get back in a few days and post back. Thank you for taking the time.
  6. Nope still nothing happens the ifs are never accessed: if (player instanceof ServerPlayer){ System.out.println("nothing happens"); // player.teleportToWithTicket(x, y, z); } if (!level.isClientSide) { System.out.println("nothing happens"); ((ServerPlayer) player).connection.teleport(x, y, z, 1, 1); // player.teleportToWithTicket(x, y, z); } I thank you for your effort and time. I'll be gone for a few days now, so I won't be able to reply. I appreciate your help!
  7. Yes singleplayer with client. No multiplayer through client (localhost). This one "I know but later on I might change it through custom leveling." is not important for now. Later on I want to implement custom levels, which will increase/decrease this double figure.
  8. On the client yes, on the server no. Have you got any idea why? rayTraceDistance = 500.D; I know but later on I might change it through custom leveling. Full code: import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.HitResult; import static net.minecraftforge.client.gui.ForgeIngameGui.rayTraceDistance; public class teleportItem extends Item { public teleportItem(Properties pProperties) { super(pProperties); } @Override public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand pUsedHand) { rayTraceDistance = 500.D; HitResult viewedBlock = player.pick(rayTraceDistance, 0.0F, false); Double x = viewedBlock.getLocation().x; Double y = viewedBlock.getLocation().y; Double z = viewedBlock.getLocation().z; y += 1; if (player instanceof ServerPlayer){ System.out.println("nothing happens"); // player.teleportToWithTicket(x, y, z); } if (!level.isClientSide) { System.out.println("nothing happens"); ((ServerPlayer) player).connection.teleport(x, y, z, 1, 1); // player.teleportToWithTicket(x, y, z); } rayTraceDistance = 20.0D; return super.use(level, player, pUsedHand); } }
  9. Very basic question again... I am not applying changes to the server, when using the InteractionResultHolder method: @Override public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand pUsedHand) { rayTraceDistance = 500.D; HitResult viewedBlock = player.pick(rayTraceDistance, 0.0F, false); Double x = viewedBlock.getLocation().x; Double y = viewedBlock.getLocation().y; Double z = viewedBlock.getLocation().z; y += 1; if (player instanceof ServerPlayer){ System.out.println("nothing happens"); // player.teleportToWithTicket(x, y, z); } if (!level.isClientSide) { System.out.println("nothing happens"); ((ServerPlayer) player).connection.teleport(x, y, z, 1, 1); // player.teleportToWithTicket(x, y, z); } rayTraceDistance = 20.0D; return super.use(level, player, pUsedHand); } In theory shouldn't both of these ifs be triggered from the server?
  10. I am checking the instance now, but I don't know what to input as the last two elements. if (player instanceof ServerPlayer){ ((ServerPlayer) player).connection.teleport(x, y, z, 0, 0); }
  11. I tried with Player#teleportToWithTicket, unfortunately it does not work: if (!level.isClientSide) { player.teleportToWithTicket(x, y, z); } But I can't figure out how to try the ServerPlayer#connection and ServerGamePacketListenerImpl#teleport yet, so I'll have to get back to you once I do
  12. Aha. It worked when I connected just with: localhost. Everything works normally, except the teleporting. I guess it is not possible to teleport player on the server with: player.setPos(x, y, z); // or player.teleportTo(x, y, z); Is there another server teleport method?
  13. Hmmm... I've accepted the eula, changed online mode to false and now I only have Minecraft server window open. How do I connect to it? I tried through the client but I must be doing something wrong.
  14. The server starts without interruptions, but I'd have to upload the mod into the run folder in order to real-life test it right, which will take some time? For the moment I'll just have to believe it will work on the server as well.
  15. Btw. If I use pPlayer instead of assigning Entity through Minecraf.getInstance() as below: @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { // entity.pick(rayTraceDistance, 0.0F, false); // Entity entity = Minecraft.getInstance().getCameraEntity(); rayTraceDistance = 500.0D; HitResult viewedBlock = pPlayer.pick(rayTraceDistance, 0.0F, false); Double x = viewedBlock.getLocation().x; Double y = viewedBlock.getLocation().y; Double z = viewedBlock.getLocation().z; y += 1; if (!pLevel.isClientSide){ pPlayer.teleportTo(x, y, z); } pPlayer.fallDistance = 0.0f; rayTraceDistance = 20.0D; return super.use(pLevel, pPlayer, pUsedHand); } Then it works as before and it solves it right?
  16. If I use this one: HitResult viewedBlock = getPlayerPOVHitResult(pLevel, pPlayer, ClipContext.Fluid.NONE); I can only teleport around 5-10 blocks. Is there another server side method to get rayTrace?
  17. It gets me the x, y, z of my crosshair position. Initial value of the rayTraceDistance is 20.0D, therefore you can only get x, y, z in that specter, however once I increase it, I can get positions from much further. I used it from here: https://github.com/MinecraftForge/MinecraftForge/blob/bb4818630c0c6cdd7c4178b4d77dc406153c2bcb/src/main/java/net/minecraftforge/client/gui/overlay/ForgeGui.java#L680 So you reckon I have to change the way I get x, y and z?
  18. Of course, here you go: import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.TargetBlock; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.entity.ProjectileImpactEvent; import static net.minecraftforge.client.gui.ForgeIngameGui.rayTraceDistance; public class teleportItem extends Item { public teleportItem(Properties pProperties) { super(pProperties); } @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { // entity.pick(rayTraceDistance, 0.0F, false); Entity entity = Minecraft.getInstance().getCameraEntity(); rayTraceDistance = 500.0D; HitResult viewedBlock = entity.pick(rayTraceDistance, 0.0F, false); Double x = viewedBlock.getLocation().x; Double y = viewedBlock.getLocation().y; Double z = viewedBlock.getLocation().z; y += 1; if (!pLevel.isClientSide){ pPlayer.teleportTo(x, y, z); } pPlayer.fallDistance = 0.0f; rayTraceDistance = 20.0D; return super.use(pLevel, pPlayer, pUsedHand); } }
  19. Does it make a difference, since I'm only using it to get x, y, z? The changes are then applied both to client and server.
  20. I am having issues with setting effects to the entities, am I doing something wrong? I am trying to freeze the movement of the given entity. List<Entity> ent = level.getEntities(player, minMax); for (Entity entko : ent) { entko.setTicksFrozen(100); entko.hurt(DamageSource.IN_WALL, entityDamage/2); } .setTicksFrozen(int) should freeze the entity right? .hurt works as it should, therefore why wouldn't other methods work on the same entity?
  21. Works like a charm thank you! I ended up using the method getEntities(Entity, AABB): AABB minMax = new AABB(x, y, z, xMax, y+nOfBlocksUp, zMax); List<Entity> ent = level.getEntities(player, minMax); for (Entity entko : ent) { entko.hurt(DamageSource.IN_WALL, entityDamage/2); }
  22. A basic question: Since entities do not have fixed positions, is there a way to get all entities, ex. ahead of the player 10 blocks, and then deal damage/apply effects to each one?
  23. For anyone else with the same question. This gets me the block that is in the Player's crosshair. I'm increasing the rayTraceDistance, which is 20.0D by default, so the Player is able to teleport farther. Entity entity = Minecraft.getInstance().getCameraEntity(); rayTraceDistance = 500.0D; HitResult viewedBlock = entity.pick(rayTraceDistance, 0.0F, false); Double x = viewedBlock.getLocation().x; Double y = viewedBlock.getLocation().y; Double z = viewedBlock.getLocation().z; rayTraceDistance = 20.0D;
  24. Thank you warjort, works perfectly! Do you know this by heart? Or how did you find it, because I'm struggling with finding decent documentation...
  25. Another basic question: From which class can the Targeted Block: X, Y, Z (seen in F3 mode) be acquired?
×
×
  • Create New...

Important Information

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