jabelar
Members-
Posts
3266 -
Joined
-
Last visited
-
Days Won
39
Everything posted by jabelar
-
[Solved]Letting Client Player know It Needs to read NBT
jabelar replied to jredfox's topic in Modder Support
Guys, most arguments in life are usually about a difference in terminology. jredfox, the reason why you are frustrating diesieben07 is that your terminology isn't really the best. Yes, NBT data is involved in storing data related to a player, but the way it gets to the client is not by reading it directly from disk. Your use of the term "cached" is also not very correct as it has a very specific meaning. I do understand what you're trying to say though -- sometimes the client seems to get out of sync with the data you expect. However, it may actually be that the server has lost the data and the client is actually in sync. That is why diesieben07 keeps asking to understand the exact nature of the bug. The way it is supposed to work is that the server will save and load data on the player using NBT format (technically serialized and deserialized when written to disk). You can see in the log where it says "saving players". I believe that in addition to saving when you ask it to save, it also saves every 45 seconds or something like that. When you load the game again, and if you log in again as the same player, then the server will read that NBT back. All that though is on the server. For the client, it relies on the server sending packets with the information. Now the thing is that there isn't just one packet, there is some for position and motion, there is some for inventory, some for capabilities, and so forth. This should all work automatically. So diesieben07's main point is that if you lose player data it must be happening on the server. The client will automatically be synced. I find it hard to believe though that the server would actually lose the data, so I think the problem is probably that it does not think you're logged in as the same player. I noticed earlier in the thread that you said the UUID is changing, but that means you're not logging in as the same player. I also see that you posted a console log earlier that said "[16:48:29] [main/INFO]: Setting user: Player120". That means that you're not logging in properly -- every time you run will be a different player. What you need to do in Eclipse is set your login information in the Run Configuration. To do this you need to edit the run configuration and add "--username=<your e-mail address> --password=<your password>" where you put in your Minecraft login credentials. You definitely cannot test player data save/loading without logging in properly. -
Yes, sorry it is too lazy to ask this. Why ask other people to go to their PC, open up their IDE, find the interface class, then type it up for you here? People asking questions here don't seem to understand that the people answering here have to work -- DO RESEARCH -- to come up with the answers. It is only fair to ask others to work for you when (a) you just need an initial hint (which diesieben07 already gave you), (b) you've tried yourself (c) the answer might also be interesting to that person. And the "whole try and error" approach is what people should be doing to learn.
-
It can be whatever, but it represents locations in the world (block pos) which I think are often manipulated as double. But certainly you can convert.
-
Get a list of every entity registered and know if it is a mob?
jabelar replied to Insane96MCP's topic in Modder Support
Okay so I think what you want to do is scan through the list of entities, including other mods which is why you can't just use a fixed list of known mobs, and present them in a GUI. Because you don't know the names of entities from other mods, you can't use the entity names. Using instanceof is logically correct, but is somewhat wasteful -- you're running all the creation code for the entity just to test what it is and then throw it away. However, honestly, if you just did that once during the post-init phase of loading I think that is perfectly fine. Definitely don't do it every time you show the GUI though! However, if you want to do things in a way that is both logically correct and performance-optimized, you will want to just look at the classes as listed in the registry. In Java you can test if one class is a subclass of another by using the isAssignableFrom() method. So if you use EntityMob.class.isAssignableFrom(EntityWhatever.class) it should tell you that EntityWhatever is a mob. -
Well one thing I think you're missing is the coordinates of the area itself. I would have four double fields (or have a "rectangle" class) with four double fields that represent x1, z1, x2, z2 in the world. I would then have setter and getter methods for those points. In the write to NBT, I would write the four double values and in the read from NBT I would read the four double values. Also, you should look at the official forge documentation for worldsavedata https://mcforge.readthedocs.io/en/latest/datastorage/worldsaveddata/.
-
Custom Advancement Tab doesn't have a background.
jabelar replied to drok0920's topic in Modder Support
It probably didn't find your background texture resource. Do you have texture in the right place? Does the console log give errors about a missing texture? -
[1.12] how to remove vanilla blocks from registry
jabelar replied to OsHeaven's topic in Modder Support
What is going wrong exactly? You should check that your code is actually executing by either setting a breakpoint and running in debug mode or putting a console print statement inside the if statement. Assuming that it does run, then it should work. If you look at the call hierarchy for the HarvestDropsEvent, it is called by the fireHarvestDrops() which is called either by harvest methods or the drop with chance methods. The harvest methods will either do some silk touch drops or will call the drop with chance methods. In all cases, the actual item entities creates are directly from the drops list. -
[1.12] how to remove vanilla blocks from registry
jabelar replied to OsHeaven's topic in Modder Support
Are you sure? I think the event returns all the drops and you can fully replace it if you want. -
You just need to create an NBT compound that contains your data of your area class, which may be a simple as the name to identify the compound as an Area and four integers (two sets to define two corners of the rectangle). If you have NBT tag it is very easy to append to world data and also to serialize into packets. I think the byte buffer helper class has ability to write / read NBT from packet payloads and world save data is already NBT so you just add your data and it will automatically get saved and loaded (you'll still need to read it out after loading) to and from file.
-
That's interesting. It didn't help but I understand it could be a problem. I actually did it that way because ItemStack itself has an EMPTY that is static final. But I realize now that that probably is intended to only be used for comparing things to, not to be used to be assigned to things. But even that is kinda dangerous -- like imagine a container starts with slots all set to EMPTY (common) and your code takes that stack and increases the size or adds an item, rather than replacing the whole stack..... Okay, back to the problem I think I have some insight. The problem is the order of the init capabilities, or maybe I should say that the loading of NBT doesn't like it if there is already an NBT present. As far as I can tell the order of loading a saved itemstack goes like this: ItemStack is constructed using the ItemStack(NBTCompound) constructor which: Reads any "capNBT" for capabilities Reads other regular item stack stuff -- item, amount and metadamage Checks to make sure that the information is valid (i.e. that the item exists, amount is positive, damage is valid range) calls ItemStack.ForgeInit(). ForgeInit() is responsible for instantiating the capabilities. It: calls the raw item's initCapabilities() which returns a new FluidHandler. During construction of the FluidHandler: I set the fluid stack to "EMPTY" (now based on diesieben07's recommendation I make a copy of it). So it is the problem -- I'm setting the actual fluid stack instance to empty even though the fluid NBT data has already been read in. To fix it i have to modify the constructor of the fluid handler to check for existing NBT data and then instantiate the fluid stack accordingly. Sort of makes sense, but a little tricky. I think a lot of people make fluid containers that are simply full or empty and have then created a two-item approach. But if you want to preserve levels in between you need a single item that handles the loading of previous level... Anyway SOLVED!
-
Okay, so something is definitely weird. to debug this issue I handled the PlayerEvent.SaveToFile and LoadFromFile events and printed out the player inventory in each case. Then I started a game and put a full (amount = 1000) item slime bag in my inventory and then saved and quit. Then I loaded the game. Here is the console output: [23:17:30] [Server thread/INFO]: Saving and pausing game... Saving Player To File With main inventory: 1xitem.slime_bag@0 {Fluid:{FluidName:"slime",Amount:1000}} 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null [23:17:30] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.EventHandler:onEvent:2053]: [23:17:30] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Copy of Copy of'/overworld [23:17:31] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Copy of Copy of'/the_nether [23:17:31] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Copy of Copy of'/the_end [23:17:32] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.MainMod:fmlLifeCycle:227]: Server stopping [23:17:32] [Server thread/INFO]: Stopping server [23:17:32] [Server thread/INFO]: Saving players Saving Player To File With main inventory: 1xitem.slime_bag@0 {Fluid:{FluidName:"slime",Amount:1000}} 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null [23:17:32] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.EventHandler:onEvent:2053]: [23:17:32] [Server thread/INFO]: MistMaestro lost connection: Disconnected [23:17:32] [Server thread/INFO]: MistMaestro the Wise left the game [23:17:32] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.EventHandler:onEvent:1830]: Player logged out Saving Player To File With main inventory: 1xitem.slime_bag@0 {Fluid:{FluidName:"slime",Amount:1000}} 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null [23:17:32] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.EventHandler:onEvent:2053]: [23:17:32] [Server thread/INFO]: Stopping singleplayer server as player logged out [23:17:32] [Server thread/INFO]: Saving worlds [23:17:32] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Copy of Copy of'/overworld [23:17:32] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Copy of Copy of'/the_nether [23:17:32] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Copy of Copy of'/the_end [23:17:32] [Server thread/INFO] [FML]: Unloading dimension 0 [23:17:32] [Server thread/INFO] [FML]: Unloading dimension -1 [23:17:32] [Server thread/INFO] [FML]: Unloading dimension 1 [23:17:33] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.items.fluidcontainers.ItemSlimeBag:getSubItems:117]: Filled bag and adding as sub-item = 1xitem.slime_bag@0 with amount = 1000 [23:17:33] [Server thread/INFO] [FML]: Applying holder lookups [23:17:33] [Server thread/INFO] [FML]: Holder lookups applied [23:17:33] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.MainMod:fmlLifeCycle:241]: Server stopped [23:17:37] [Server thread/INFO]: Starting integrated minecraft server version 1.12.1 [23:17:37] [Server thread/INFO]: Generating keypair [23:17:37] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.MainMod:fmlLifeCycle:183]: Server about to start [23:17:37] [Server thread/INFO] [FML]: Injecting existing registry data into this server instance [23:17:37] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.items.fluidcontainers.ItemSlimeBag:getSubItems:117]: Filled bag and adding as sub-item = 1xitem.slime_bag@0 with amount = 1000 [23:17:38] [Server thread/INFO] [FML]: Applying holder lookups [23:17:38] [Server thread/INFO] [FML]: Holder lookups applied [23:17:38] [Server thread/INFO] [FML]: Loading dimension 0 (Copy of Copy of Copy of Copy of) (net.minecraft.server.integrated.IntegratedServer@ab956e8) [23:17:38] [Server thread/INFO]: Loaded 488 advancements [23:17:38] [Server thread/INFO] [FML]: Loading dimension 1 (Copy of Copy of Copy of Copy of) (net.minecraft.server.integrated.IntegratedServer@ab956e8) [23:17:38] [Server thread/INFO] [FML]: Loading dimension -1 (Copy of Copy of Copy of Copy of) (net.minecraft.server.integrated.IntegratedServer@ab956e8) [23:17:38] [Server thread/INFO]: Preparing start region for level 0 [23:17:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.MainMod:fmlLifeCycle:199]: Server starting [23:17:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.MainMod:fmlLifeCycle:213]: Server started [23:17:39] [Server thread/INFO]: Changing view distance to 12, from 10 [23:17:39] [Netty Local Client IO #1/INFO] [FML]: Server protocol version 2 [23:17:39] [Netty Server IO #3/INFO] [FML]: Client protocol version 2 [23:17:39] [Netty Server IO #3/INFO] [FML]: Client attempting to join with 5 mods : [email protected],[email protected],[email protected],[email protected],[email protected] [23:17:39] [Netty Local Client IO #1/INFO] [FML]: [Netty Local Client IO #1] Client side modded connection established [23:17:39] [Server thread/INFO] [FML]: [Server thread] Server side modded connection established Loading Player from File With main inventory: 1xitem.slime_bag@0 {Fluid:{FluidName:"slime",Amount:0}} 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null 1xtile.air@0 null [23:17:39] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.EventHandler:onEvent:2069]: [23:17:39] [Server thread/INFO]: MistMaestro[local:E:e05009fa] logged in with entity id 5235 at (102.5, 66.0, 254.5) [23:17:39] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.EventHandler:onEvent:1060]: NameFormat event for username = MistMaestro [23:17:39] [Server thread/INFO]: MistMaestro the Wise joined the game So you see that it saves with a fluid tag amount = 1000 but then it loads with amount = 0. What's going on here?
-
So in my main event handler class (yes the class is subscribed and all my other events work) I have put simple methods to print to console the player main inventory during the PlayerEvent.SaveToFile and PlayerEvent.LoadFromFile events. My code is simply: @EventBusSubscriber public class EventHandler { @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(SaveToFile event) { EntityPlayer thePlayer = event.getEntityPlayer(); InventoryPlayer theInventory = thePlayer.inventory; // DEBUG System.out.println("Saving Player To File With main inventory:"); System.out.println(theInventory.mainInventory); } @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(LoadFromFile event) { EntityPlayer thePlayer = event.getEntityPlayer(); InventoryPlayer theInventory = thePlayer.inventory; // DEBUG System.out.println("Loading Player from File With main inventory:"); System.out.println(theInventory.mainInventory); } } But the console output doesn't ever print out these statements. For example, when saving the game it shows: [21:46:30] [Server thread/INFO]: Saving and pausing game... [21:46:30] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Really Cool Worl'/overworld [21:46:30] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Really Cool Worl'/the_nether [21:46:30] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Really Cool Worl'/the_end [21:46:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.MainMod:fmlLifeCycle:227]: Server stopping [21:46:38] [Server thread/INFO]: Stopping server [21:46:38] [Server thread/INFO]: Saving players [21:46:38] [Server thread/INFO]: MistMaestro lost connection: Disconnected [21:46:38] [Server thread/INFO]: MistMaestro left the game [21:46:38] [Server thread/INFO]: Stopping singleplayer server as player logged out [21:46:38] [Server thread/INFO]: Saving worlds [21:46:38] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Really Cool Worl'/overworld [21:46:38] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Really Cool Worl'/the_nether [21:46:38] [Server thread/INFO]: Saving chunks for level 'Copy of Copy of Really Cool Worl'/the_end [21:46:38] [Server thread/INFO] [FML]: Unloading dimension 0 [21:46:38] [Server thread/INFO] [FML]: Unloading dimension -1 [21:46:38] [Server thread/INFO] [FML]: Unloading dimension 1 [21:46:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.items.fluidcontainers.ItemSlimeBag:initCapabilities:90]: initCapabilities for ItemSlimeBag with NBT = null and Cap NBT = null [21:46:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.items.fluidcontainers.ItemSlimeBag:initCapabilities:90]: initCapabilities for ItemSlimeBag with NBT = null and Cap NBT = null [21:46:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.items.fluidcontainers.ItemSlimeBag:initCapabilities:90]: initCapabilities for ItemSlimeBag with NBT = null and Cap NBT = null [21:46:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.items.fluidcontainers.ItemSlimeBag:initCapabilities:90]: initCapabilities for ItemSlimeBag with NBT = null and Cap NBT = null [21:46:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.items.fluidcontainers.ItemSlimeBag:initCapabilities:90]: initCapabilities for ItemSlimeBag with NBT = null and Cap NBT = {} [21:46:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.items.fluidcontainers.ItemSlimeBag:getSubItems:117]: Filled bag and adding as sub-item = 1xitem.slime_bag@0 with amount = 1000 [21:46:38] [Server thread/INFO] [FML]: Applying holder lookups [21:46:38] [Server thread/INFO] [FML]: Holder lookups applied [21:46:38] [Server thread/INFO] [STDOUT]: [com.blogspot.jabelarminecraft.examplemod.MainMod:fmlLifeCycle:241]: Server stopped [22:05:56] [main/INFO]: Stopping! [22:05:56] [main/INFO]: SoundSystem shutting down... [22:05:56] [main/WARN]: Author: Paul Lamb, www.paulscode.com As you can see i doesn't show the save to file print statement. However, tracing the call hierarchy, not only should the statement print but it looks like actually the game saves every 45 seconds (in the MinecraftServer tick() method for example) let alone when actually saving. Any reasons why these events might not fire?
-
Well the first thing I'd ask is whether the areas can be represented "algorithmically" or if they need to be block by block. For example, if the GUI involves drawing rectangles to define the area then really only two points need to be saved per rectangle and I'm assuming there wouldn't be a great many overall areas. In other words, if you want to save rectangular areas I don't think you need to store information for every block within that area. For rectangles I'd just create a simple class to store the two corners and then make a list of those rectangles. I would probably save it on the server side as world data with a simply serializer. My next question is what exactly you mean by "protect" but assuming you mean it is not modifiable by players you can basically override/intercept all the player interaction with the blocks and cancel it if is within the areas. Lastly, for syncing between client and server it may happen "automatically" if the modifiability is determined by the server. I'm not sure exactly how breaking blocks works, but several things send the user input (the mouse click) to the server that then takes the action (or in your case prevents the action) and then the results are automatically synced back to client. However, there are other things like movement where the client tries to do some processing to make it smoother and that might cause visual glitches while the server sync catches up. So if you want client itself to be aware of the protected area, I would simply send a custom packet to the client whenever a player joins the world and resend any updates to all players if there is a change in the area definitions.
-
[Unsolved] Porting Mod from 1.7.10 to 1.8.9
jabelar replied to Uselessness's topic in Modder Support
Well you can only really figure out the new methods if you know what the old ones were doing. There are some things that are simple changes (like just new name for method) between versions, but other things are majorly different. Like maybe you need to start using separate thread for networking, maybe the code now has to start using blockstates and so forth. But if you insist, then what you need to do is load up both versions in your IDE (like Eclipse). In the 1.7.10 referenced libraries find those methods and figure out which class they are in, which parameters and such and even where roughly they are listed within the class. Then in the 1.8.9 referenced libraries look in the same area to see if they are simply re-named or if there is something similar that looks like it forms the same function. You can also go through the type hierarchy for the class and scan the names of all the methods to see if there is anything that looks promising. If it wasn't a simple change to the name or parameter list, then it might be a more major change. In that case you should look up the change lists for the method name and see if someone commented on removing it and gave hint on what replaces it. -
So I'm still having trouble with a custom item that holds fluid. Based on a lot of debug tracing, console print statements, and rewriting my code again from scratch, I feel pretty confident that client and server are syncing generally. I see a lot of packets going back and forth, with the itemstacks containing the expected fluid values. However, if I save and then load again, all items that are full of fluid in the player inventory show up as empty. I looked at how other fluid items work such as Universal Bucket and some other mods, but they all seem to use a "two item" system where the empty bucket is a separate item. That doesn't really work for me because I don't want to just be empty/full but want to retain other fluid levels in between. Furthemore I don't see any reason why it shouldn't work -- the level is saved in the NBT. It's driving me crazy. As far as I know, the ItemStack gets the capability NBT appended as part of the fluid handling system, and I explicitly write/update that NBT every time the item is used to fill or drain a block. So as far as I can say the NBT is working in game, but failing to save and load? What can be wrong? My code: https://github.com/jabelar/ExampleMod-1.12/blob/master/src/main/java/com/blogspot/jabelarminecraft/examplemod/items/fluidcontainers/ItemSlimeBag.java Note that right now I'm using a bucket texture for testing, but you can find the empty and full versions of the "slime bag" item in the Miscellaneous creative tab if you go through the trouble of trying to run my code.
-
There is already a public field called onGround you can use that already takes care of this. It is already updated for you. There is also a field called isAirborne but as far as I can see that is set but never really used. onGround is probably what you want and if you want to know if it is airborne, probably use !onGround (although you can play with isAirborne to see if it works for you).
-
So I've been playing around with items that are fluid handlers and while I can get the functionality to work I've been having trouble with the models and also with the client not retaining the fluid levels after a save / load. It seems clear to me that it is a client-server sync issue, but I'm not entirely sure how to fix it for a couple reasons. First of all, if I change NBT data (or in this case the item fluid handler adjusts NBT) on the server, what is the expected mechanism for the client to get that info? For me it often appears to work but i think that is because the code is also running simultaneously on the client, but problems with save/load lead me to believe that the server side isn't really managing things. So I thought maybe I should send a custom packet, or initiate a vanilla sync packet, but realized there doesn't really seem to be a UUID to reference for ItemStacks. So it seems to me that for example if I am showing an itemstack in the player inventory (on client) there isn't really any specific way to reference the server version of the same thing, except for the fact that it is in the same slot. Due to that, it seems (and I can see this when I trace the code) that there is actually a lot of "replacement copies" of itemstacks going on. For example, it seems that each time I open the player inventory it actually constructs new versions of the itemstacks and so forth. And it seems that each time a player uses an ItemStack in his hand, the server creates a new ItemStack. This sort of makes sense, but also makes it difficult for me to understand how to sync them properly. In fact is isn't really clear which direction I should be syncing -- from server to client or client to server. Right-clicking presumably sends a message to the server at some point, and when server gets the message I think it creates a new copy of the ItemStack to work with. This is very different than Entity syncing where there is only one instance and you reference it by UUID. Question 1) For an ItemStack in player's hand, if you want it to change state (i.e. NBT data changes) on right-clicking on something, how does that work in terms of syncing between client and server? Is there no syncing (because code runs on both sides)? Or does it run on client and some packet is sent to server saying "update what's in my hand"? Or does it run on server and there is some packet sent to client saying "update what's in your hand"? Question 2) What vanilla packets are involved in syncing ItemStack information? How are ItemStacks references across client and server? Is there a UUID or are they simply re-created when the packets are received? Question 3) When you save then load, how are ItemStacks in the player inventory supposed to get synced to the saved NBT data? Question 4) The Item class itself has a getShareData() mechanism that seems to be related to NBT, but it's not clear to me when that gets called. I don't see it happening much in my console logs. Basically I want an ItemStack state to change when used using right-click and want that state to persist after saving then loading. I have the right-click working but not the saving / loading.
-
Well, that is a problem with your texture for the top. I'm not sure whether the blocks in your picture are meant to be wet or dry but one of those or both of those textures aren't good. Try copying a vanilla texture for the grass top into those locations first and that should fix it. Then use a graphics editor to figure it out. I think that you either didn't make the texture size right or something. In other words, I think you have a texture file in the right place but it doesn't have the right thing in it.
-
Get a list of every entity registered and know if it is a mob?
jabelar replied to Insane96MCP's topic in Modder Support
For sure it is also a waste of performance I assume. Why go through all the trouble of constructing it? But it is important to teach the reasoning behind why his code didn't work, not just tell someone "copy an answer from Stack Overflow". I wanted the person to understand when instanceof applies and when it doesn't. -
Get a list of every entity registered and know if it is a mob?
jabelar replied to Insane96MCP's topic in Modder Support
The reason your code wasn't working was because instance of is meant for comparing instances. The class you get is not an instance of that class. If it was then you could do things like call the instance methods from it. So as Draco pointed out you need to look at the standard Java ways of doing it. If you want to work with the classes, then you need to use the isAssignableFrom() method with the classes, or conversely you need to create an instance of the class (like call its constructor) then do instanceof. -
[1.10.2] Disabling crafting recipe for certain players
jabelar replied to Bloopers's topic in Modder Support
I also had another idea. Maybe you could just use the GuiOpen event to intercept the various crafting GUIs and replace the GUI with your own and add the code you need to check player and prevent recipes. -
[1.10.2] Disabling crafting recipe for certain players
jabelar replied to Bloopers's topic in Modder Support
InI 1.12 with the JSON approach you can do conditional recipes. It wasn't clear if you wanted to do this for your own recipes or also for vanilla. In the first place you would just create conditional recipes, and in the latter case you would replace the vanilla recipes (which are now in a registry) with your own. I have tutorial tip information that covers this in more detail here: http://jabelarminecraft.blogspot.com/p/minecraft-modding-ore-dictionary.html look halfway down the page to the sections regarding replacing recipes and conditional recipes. I know you wanted to do it in 1.10, but maybe you should consider doing it in 1.12. -
[solved][1.10.2] How to sync entity living from server to client?
jabelar replied to Dustpuppy's topic in Modder Support
Maybe look at how the vanilla name tags work. -
I usually feel bad having people actually debugging my code, rather just want to understand the ideas. But sometimes it is about the details so appreciate you looking at it: here is link to the item class within my github repository. https://github.com/jabelar/ExampleMod-1.12/blob/master/src/main/java/com/blogspot/jabelarminecraft/examplemod/items/fluidcontainers/ItemSlimeBag.java If you actually go as far as to try to run it, look at the miscellaneous tab in creative and grab the last two items "Bag" and "Slime Bag". Then go into survival and convince yourself that they work (Slime Bag can place Slime and turn into Bag and vice versa) then while at least one of them is filled save and load. You'll see all Slime Bags become Bags.