Context
I'm writing a fabric mod that needs to replace blocks in the world.
Code
Currently Im using World#setBlockState(pos, state)
BlockPos pos = new BlockPos(x, y, z);
BlockState state = Blocks.STONE.getDefaultState();
world.setBlockState(pos, state);
Problem
This seems to work, but if I right-click the replaced blocks, they turn back into the block they were before
I also tried this Block.replace(world.getBlockState(pos), state, world, pos), but this reproduces the same.
For now, the mod is only supposed to be used on client-side with minecraft-1.17.1.
Question
Is this because the client cannot modify the world in that way?
If not, what could be the issue and how can I fix it?
Such as you mentionned, it's on the client-side. So, you can change everything, it will only be visual.
It replaced the block when right-click because the server send the real block present on the world (instead of visual one).
If you want to do something like that, it can be difficult. All client that are manually placing block on server are cheat, because they are making something that is not allowed in basic minecraft.
But, maybe there is possibilities :
Use event to change the block that will be placed, and instead of placing the default one and change it after, you can directly change it on the server.
Run a command to change the block such as /setblock (wiki)
Related
Title says it all, I just wanna detect when a player joins a server client-side, and also how would I send a message to the client, not through the server? (the mod is supposed to send a message when the player joins and play a sound when you are not moving on a server like hypixel where it wont have the mod) weird mod, I know (Also this is done in 1.8, if that matters much)
Two choices, both with some downsides:
ClientConnectedToServerEvent, although it fires on a different thread than usual, and may fire slightly earlier than you want
EntityJoinWorldEvent, although it fires in a lot of other cases too, so you'd have to do some additional checks to make sure it's actually the player joining that triggered it
i want to get block material and direction/rotation, then save it to .txt file and in future reading this data and set material and direction/rotation for another block
I try to get material something like this:
tempLocation.getBlock().getType().toString()
for example when block is LOG, it does not distinguish the type and returns just "LOG", thus it does not recognize the type of LOG, For example i would like to write information about this is a jungle log.
Another case when I want to save the direction/rotation of a block and set it for another block in the future, i try used:
tempLocation.getBlock().getState().getData().toString()
but it returns the material information to me as is:
LEGACY_DIRT(0)
but I don't know how to use this information to set the direction of the block
I am using spigot version 1.16.3
I saw that a lot has changed since version 1.13+. How can I now correctly retrieve material type and block direction/rotation, and how to set this information without using outdated interfaces?
For people with a similar problem
I solved my problem by using:
getBlockData().getAsString()
and
setBlockData(Bukkit.getServer().createBlockData(takenAsString))
I am running in the following:
I have an eclipse plugin(Luna/JVM 1.8) that presents some information to the user in a CTabItem. In this CTabItem, I have a class that updates a TextViewer's widget contents using asyncExec(....).
A brute force approach of getTextWidget().append(String) process the String[] inside the UI/asyncExec();
This logic has worked reliably in OS X (El Capitan). I am using linux (openSuse Leap) now and the updates rarely show up in the TextViewer. I have checked and the runnable inside the asyncExec(...) gets called.
The rest of the UI elements work normally in both OSs.
What do I need to change or am I missing? This seems more due to my lack of understanding of cross-platform SWT than anything else.
Thanks a lot!
I made 2 simple changes:
Instead of calling getTextWidget().append(String) I am using a StringBuilder and making just one call to getTextWidget().append(String).
After this I call refresh().
These two did the trick.
Eclipse is awesome for writing java programs but today I find that it's awesome to trick new coders like me. #_#
I write a snippet as following,
public static void main(String[] args) {
for(int i=0;i<3;i++){
System.out.println("i = " + i);
}
}
then I add a breakpoint at the line of "System.out.print....", click "Debug" button, eclipse goes to the "Debug" perspective and the line of breakpoint is highlighted, then I move the cursor over variable "i", its value is "0" as expected.
And then, I select the "i++" and click "Inspect"(or press "Ctrl+Shift+I") once, I move the cursor over variable "i", its value changed to "1". I repeat "Inspect" again, the value of i changed to "2"......(its value will add by 1 every time I clicked the "Inspect")!!
Why does this happend!? I ONLY want to watch the value of "i" for debug propuse, DO NOT want to really change its value until I step into next statement. I think that "Inspect", as well as "Display" are only for viewing the variable/expression, they should not impact the value, but in this case, it doesn't work as I expect to.
Could anyone tell me what went wrong?
My eclipse version info:
Version: Indigo Service Release 2
Build id: 20120216-1857
If you inspect an expression, eclipse has to execute that expression so you can get the value. Therefore, if you inspect i++, eclipse adds one to i.
Think about it this way: If instead of i++, you inspected myFunction(i), would you expect eclipse to execute the function "myFunction" to get the value? It's the same with i++.
If you are concerned about displaying/showing values while debugging and do you want to be sure not affecting the value, you should select the variable or expression and use the "Watch" option.
This will track the variable/expression value without executing, just updating the new value each time this is run. I think is the most secure way.
As Pablo mentioned, it has to evaluate the code in order to tell you what value it returns. You could instead put a watch on "i+1" and that would give you the value you want without the side effect you don't want.
Basically, you need to be aware of any side effects of anything you launch, whether from the "main" code or from the debugging tools. As Erhannis mentioned, this is very useful at times for modifying values while debugging your code. (For example, you can verify that a tweak/fix is indeed helpful before actually tweaking your code.)
You were expecting "an isolate area" but this would be extremely hard to do, especially in an object-oriented context where many objects are linked to many other objects. Running the whole thing in parallel might sometimes work, but you'd lose the tweaking ability above. And in any context, you'd run into tons of problems with fighting over resources; e.g. both copies trying to read/write a particular file such as a log file. Also, the two execution paths could diverge, leading to incorrect/misleading watch values.
So, preventing such side effects is not really a feasible option here and would rarely be useful anyway. Just expect that the watches can both reflect and affect the code execution.
I like eclipse save actions feature, but I can't get rid of one little annoying thing. I use sorting members and methods on save.
The good thing is, eclipse moves member/method to correct position, alphabetically.
The bad thing is, when I am writing method and save it, eclipse moves method but not current caret position. So basically, I press CTRL+S and end somehwere at completely other place then I was before, so I have to scroll up/down to find new location of my method.
Is there some kind of workaround?
I am using Eclipse 3.6 Helios atm.
It sounds like a bug, try submitting it to eclipse at this site.
As a workaround - but not the best one, you can use Ctrl-O to find the method.
2 more workaround options:
Set a //TODO return here in the line that you want to return to, then you can filter the task view by a specific todo.
Put breakpoint before saving.
Generally I prefer not to use options like this, since when working with other poeple in a large scale project, it can cause a lot of noise. I mean that if you make a change to an existing file, then save it and then the format happen. next step you will commit this file to the repository. when someone or even you try to look at the diff of the change, it will be cluttered with all the formatting and sorting. So I prefer doing it as an independent change.