-
Gepardius changed their profile photo
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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?
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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.
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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.
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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.
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
I'll try it once I get back in a few days and post back. Thank you for taking the time.
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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!
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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.
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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); } }
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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?
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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); }
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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?
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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.
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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.
-
Destroy / Remove blocks (10x10x10) when the block is clicked with an item.
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?
IPS spam blocked by CleanTalk.