-
Posts
34 -
Joined
-
Last visited
Gepardius's Achievements
Tree Puncher (2/8)
0
Reputation
-
Gepardius changed their profile photo
-
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?
-
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.
-
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.
-
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!
-
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); } }
-
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?
-
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?