I don't know if is easy/performant to implement but will be wonderful to have some event like
OnPleyerEnterBiome()
OnPlayerLeaveBiome()
For region i don't think is supper important because we already have OnEnterSector ...
Thx.
I don't know if is easy/performant to implement but will be wonderful to have some event like
OnPleyerEnterBiome()
OnPlayerLeaveBiome()
For region i don't think is supper important because we already have OnEnterSector ...
Thx.
I do some experiment on crossing border around 0,0 with a mix of differently sector type. My conclusion is:
- close to border line of a sector, a biome from a region (example grass from Default/Ocean) can extend in neighbor sector for some blocks and are not cut along border line.
So is unreliable to read biome on sector enter to get region type because that cross border biome overlaps. Inside sector at some distance from margin of sector data is accurate.
Maybe a quick fix to detect on what type of sector enter is to read data not from chunk just entered sector, but from a chunk close to middle of sector and from that data to conclude what type of sector is it:
- Default/ocean
- Dry
- Cold
I make some function who work this way when enter some sector:
1. Read data from table Sectors from Chunks.db
2. if sector is here, sector have some chunks modified, already visited and from column region read exact sector type
3. if not here, you entered a new sector, read a sample chunk for example from middle of that sector, read a biome from here and determine sector type.
Maybe red51 will expose via API, sector type!
Maybe region type can be read directly from table Sectors from Chunks.db
But this work only for a changed sector (have at least one chunk altered and saved in db)! If you just enter a new sector and don't modify anything, sector data is not write on this table before any chunk is modified.
Here my -1,-1 sector is a Arid/Dessert.
After some override of a sector, i see values for column region:
1 - Default
2 - Ocean
3 - Arid
4 - Cold
Ah, so you don't want to detect particular biome but whole type of region aka sector type (Default-Ocean / Dry / Cold)?
Hmm maybe time when check event? i suppose you check on PlayerEnterSectorEvent ? If so, if read player position still on chunk of old sector? maybe use position of chunk from getNewPlayerPosition() and not chunk from actual player. I think Event PlayerEnterSectorEvent occur before enter sector.
Note: Probable not that is cause. See following posts about overlap biome along border of sectors.
I test it with some locations and always get same things as in F3 Info.
Not sure what is wrong for you!
I just use something like :
Hi.
I used bellow code to get a biome.
final byte[] rawLOD=World.getChunk(p.getChunkPosition().x, p.getChunkPosition().z).getRawLODTerrain(); // raw LOD data of chunk of player position
So if i suppose correct, a code between
- 1 and 49 is a Default (or Ocean) region
- 50 and 99 is a Cold region
- 100 -149 is a Arid region
BTW:
In same chunk you can have differently biome for each block position. In old java game i think biome was tied to whole chunk, not individual block positions from chunk?
About shearing sheeps, basically this is handled by PlayerNpcInteractionEvent, but I just realized that this is way too limited... this definitely needs some better handling which provides more information about the actual interaction type. Right now it's triggered if you just press F, but it's also triggered when shearing sheeps etc. I will put this on my list (but I'm not sure if this will make it into the next hotfix)!
Here i think about a more generic event like PlayerUseAction. This can be triggered basically when player use equipped item, like rope to leash, shear to shear a shep, knife to skin, knife on tanning rack, bucket to get milk, bucket to get water, etc. and maybe more like use on bread to get half bread, on melon to get slices, etc.
But maybe I can still get an event (e.g. "PlayerNpcLeashEvent" or smth like that) added with the next hotfix
That will be fantastic!
Display MoreSorry, I forgot to mention this
Yes, this bug was indeed fixed with the latest server update, however, it's only fixed on servers. There was no update for the game, so a plugin using this event will work in multiplayer, but not in singleplayer (a fix for the game will probably be available in the next couple of days).
The API event does turn the tanning rack into a (fake) meta object (that's why it's not null), but calling any methods on it won't work...
Not sure about the best solution for now... maybe it would help if the event just had a getRelatedObject() method (which returns the ObjectElement instead of a MetaObject). Or maybe an additional getRelatedObjectDefinition() helps (so getMetaObject() would return null for the tanning rack, but getRelatedObjectDefinition() would still return the tanning rack definition)?
Perhaps it might also work if there was a place target enum provided (which would contain values like "Persistent", "MetaObject", "TanningRack" etc)
I think on a long run the best is to threat them as metaobject, even if game not supplementary do some processing to them.
On short term probable one enum with target will be very good to know exactly where item is placed (help in future too if other case will appear) and a getRelatedObjectDefinition() to can get definition (where item was placed in tanning rack or gramophone?) for sure is helpful.
And second thing on item pickup (hide,leather,disk) can be do a fake event PlayerItemPickup (cancelable of course)? I see this event is not trigger at all for tanning rack. On place event is triggered, but on pickup no event.
I don't see mention anywhere as issue is fixed, but after server update from yesterday, it seems new event PlayerPlaceItemEvent is fixed!
I test with a few metaobjects:
- Furnace - ok
- drying rack - ok
- oven - ok
- grill - ok
- skewer - ok
- grinder - ok
-paper press - ok
But with tanning rack i encountered a new issue. I don't think is related with first one but same code who works for other station here give error because when i call method to retrieve definition of metaobject, return null if metaobject is a tanning rack!
ObjectInfoDefinition def= station.getObjectInfoDefinition(); // <-- Here for tanning rack return null !!!
print("Player %s place a item %s into %s located at coordinate %.2f %.2f %.2f",p.getName(),item.getName(),def.name,pos.x,pos.y,pos.z);
from log:
[10:49:11] [ADMIN MESSAGE] (Notification) EXCEPTION OCCURRED IN PLUGIN 'TestRw' (AUTHOR: Bamse) <-- here i put a hide in tanning rack
at PLUGIN_CLASS_LOADER//bamse.rw.PermanentItemPlacement2.onPlayerPlaceItem(PermanentItemPlacement2.java:32)
Note (after more research):
It seems tanning rack is a special object and not a metaobject? Maybe must threat same as a meta object? I can pickup hide from him and no event PlayerPickupItemEvent fired at all! (New event
PlayerPlaceItemEvent is fired).
So no way to know if item (hide or leather) is take from tanning rack or how to deny take item from him on some condition?
Thx
Bamse
BTW. Problem is not particularly with a furnace, but other metaobjects too like grill, oven,etc.
Hi
First thx for adding this new event!
Now i try to use but i hit some issue. For persistent item placement it work as expected, but it is a issue when try to add items on a metabject (furnace, grill). For example when i want to put ore in furnace, ore gone from inventory but on furnace don't appear nothing and i can put in same slot over and over new ore. If i don't use at all new event i can put items in metaobjects! it's like, with new event activated is canceled by default when put items in metaobjects!
For testing purpose i use following code:
print("Player %s place a item %s into %s located at coordinate %.2f %.2f %.2f",p.getName(),item.getName(),def.name,pos.x,pos.y,pos.z);
print("Player %s place a persistent item %s at coordinates %.2f %.2f %.2f",p.getName(),item.getName(),pos.x,pos.y,pos.z);
if (item.isPersistent()) { // type==WorldItemType.PersistentDynamic || type==WorldItemType.PersistentStatic
print(" Try to pickup a permanent item placed! Check permission and deny if not a friend with building right!");
print(" Try to pickup a item from a craft station! Check permission and deny if not a owner or friend with inventory right!");
// here cancel event if player don't have right to pickup items from crafting stations (furnace,grill,etc.)
From logs:
[Java] Player Bamse place a item ironore into furnace located at coordinate 1699.72 94.30 1788.76 <--- Here i placed a ore in furnace, but in furnace appear nothing
[Java] Player Bamse picked a WorldItem ironore of type MetaObject <--- here i take a ore from furnace
[Java] Try to pickup a item from a craft station! Check permission and deny if not a owner or friend with inventory right!
SERVER: PLAYER Bamse (76561198869958751) PLACED ITEM steakburned @ (1698.98, 93.82, 1784.41) <--- Here i placed a persistent item
[Java] Player Bamse picked a WorldItem steakburned of type PersistentStatic <--- Here i pickup a persistent item
[Java] Try to pickup a permanent item placed! Check permission and deny if not a friend with building right!
Thx
Bamse
Maybe it'll help you
Thx Devidian for another posibility. But your code don't stop interaction with any animals, not just pickable? But i think that is ok because i don't see a use of interaction with animals beside pickup, yet.
About breeding of animals.
So far i breed some cows, pigs and horses
- For horse i always i get variant 0 (light brown) even mother are different variants.
- For cow i always get same variant as mother
So question is any got male version of adult from babies get from breeding? Or i was exceptionally unlucky and i got all babies as female variant when they grow, or is something wrong and no male from breeding? Some other player reported same thing, just female.
I make some progress but i don't know how to cancel PlayerMouseButtonEvent (it seems this event don't have setCanceled(true) method ...
But i even if find a method to cancel mouse press button i don't think this is the best approach because left button is used very heavy in game ..
Idealy i want some Event who is triggered on start of special action of equipped item like "Catch Animal", "Shear sheep", etc ...
Hi!
I try to control, via API, when animals can be leashed with a rope. I looked in API but not yet any clue how to detect when a player leash a animal and eventually deny this if some conditions are meet. If any have any hint, that will be very appreciated!
Thx.
Bamse
Hi
If i cancel event PlayerInventoryAddItemEvent when i try to pickup a small animal, it's normal to animal got removed from world, even if i cancel event and in inventory not get Item of category NPC?
print("Player %s triggered PlayerInventoryAddItemEvent with a item %s as category %s from origin %s",p.getName(),item.getName(),def.category,origin.name());
evt.setCancelled(true); // Bug?? animals removed from world and even if i cancel event, animal is destroyed
Thx.
Bamse
Hi!
I searched on API events to can interact with item placement / pickup item placed but not find any. They are exist and i missed? Something like:
If this type of event are not yet in API i can use another solution to detect if player want to place a permanent item and eventually stop it? Same for pickup permanent item?
Maybe another solution can be to extend PlayerPickupItemEvent() with a method to get source of item pickedup.
Source can be:
- Ground - for item dropped on ground
- PermanentItem - for items placed permanently
- CraftStation - For items take from crafting station (ex: ingots / ore from furnace, meat/dried meat from Drying rack, meat/cooked meat from grill/oven, etc.)
- etc.
In meantime maybe is a solution for this problem which i don't see it!
Thx in advance!
Bamse