-
-
Notifications
You must be signed in to change notification settings - Fork 76
Add entity API #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev/0.8
Are you sure you want to change the base?
Add entity API #549
Conversation
Here's a script that I've been testing with: https://pastebin.com/uCH39VEm |
Before I start reviewing Since this adds a wider palette of features and due to the fact that this includes a breaking change, could you change the target branch to |
Done |
Greetings The build seems to fail, I am not sure if the issues came with the change of the target branch, but they are there You can either open the build log from teamcity by clicking on "Details" or you just could try to build it locally |
My bad, it builds now |
You still didn't fix the checkstyle violations |
Foremost, thanks for the PR and I really like your idea The changes look good, but I didn't inspect them too deeply. I will take some time this week to review your changes and test them a bit for me |
Would it have made more sense to implement this with peripheral methods instead of polluting the global namespace? You could return a userdata from the scan method, return all the information by default, or just add another method to the peripheral for looking up data by uuid |
Originally I started with adding a
It was already the case before that some functions returned different entity data than others for no real reason.
You could return all data, but there is a lot of information available now. It feels almost wrong to lump almost all information on the entity into one huge table. This would be NBT, almost all runtime data, and all persistent data. If you just need to get the positions of entities then this is all useless information.
Something like |
After looking at some of my changes again though, I think it would make sense for |
I am currently discussing that a bit with some of the CC community in the CC discord. I know that additions to the global API are not welcome in the community. AP already does unconventional things that I want to eliminate in 0.8, and I'd hate to add more. |
Damn thats unfortunate, I wasn't aware of that. It's an issue of usability and code quality vs global pollution then. It's a shame that an entity API isn't available in CC itself. I guess a rough compromise could be standardizing the entity data returned in different parts of this mod. So pretty much chucking everything into one huge table, but making sure that happens consistently in every peripheral function where an entity is retrieved. It would be worth documenting this standard entity table somewhere. Another alternative is turning the Player Detector peripheral into an Entity Detector peripheral. All functionality of the entity API could be put in the Entity Detector. |
I support that idea you could also participate in the small discussion in the #modmaking chat on the cc discord |
One idea I like is to still add all the entity API functions to the environmental detector but to separate them a bit, put them into a table which you can retrieve using So maybe you want to go with that? I will also convert this to a draft until we agree on a method |
For the idea of turning the Player Detector into an Entity Detector: I think a The biggest consideration with the potential Entity Detector is if its okay for it to have the 4 player-specific things. These 4 things cant really be removed, so its just if it makes sense or not. If it doesn't make sense, then it might not make sense to turn the Player Detector into an Entity Detector. I'm not sure, I'd like your opinion. |
Merging the two peripherals is an interesting idea, but I don't really like it. Merging them would create one peripheral with maybe too many functions imo which wouldn't keep it simple Developing the Player Detector and the Environment Detector separately would be my way to go. I would simply accept the duplicates, as there are apparently only 2 functions (getPlayerPos and getOnlinePlayers) Keeping the player related functions (isPlayerInX... getPlayersInX...) and events to the player detector would make it simpler for the user imo to just have player related functions in one dedicated block while there would be the more advanced entity api in the Environment Detector |
Sweet. I'm going away for a week but I'll work on that when I get back |
Greetings @lonevox |
I took quite a hiatus from making my pack which is why I completely disappeared, sorry about that. I'll try getting the PR ready with the discussed changes within the next few days. |
@SirEndii I'm having trouble exposing the EntityAPI class as a table through the EnvironmentDetectorPeripheral like you suggested. Here's what I assume would work, but isn't: @LuaFunction(mainThread = true)
public final EntityAPI getEntityAPI() {
return new EntityAPI();
} It successfully returns a table, but the table is empty, even though there are 6 LuaFunctions in EntityAPI. Any ideas? |
Can you check the log? |
src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java
Outdated
Show resolved
Hide resolved
src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/apis/EntityAPI.java
Outdated
Show resolved
Hide resolved
src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/apis/EntityAPI.java
Outdated
Show resolved
Hide resolved
Thanks for your contribution! ❤️ Still don't know if query with UUID is a good move, because this change force users do more main thread invokes, it increased the response time, and may decrease the ease of use. |
This means that you can get a UUID from calling searchAnimals, which you could then use in the EntityAPI.
It does decrease ease of use in that you need to manage UUIDs in Lua, but it allows for the |
src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/apis/EntityAPI.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Kevin Z <[email protected]> Signed-off-by: lonevox <[email protected]>
src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/apis/EntityAPI.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Kevin Z <[email protected]> Signed-off-by: lonevox <[email protected]>
Ok, so when an entity is not exists any more, the entity API will throw a java error, we should not expect that, instead we should return |
src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/apis/EntityAPI.java
Outdated
Show resolved
Hide resolved
Hm and with the entity API, you can get any entities data once you know their UUID, no matter where they are. That probably is a little bit too powerful, may be abused, and not what we expect. I'd ask @SirEndii's opinion for that. Currently two solutions I can think of:
However both of them will make EntityAPI depends on the peripheral's status again |
I'm doing slightly weird validation by using Pair, but it is better than before. It would be nice if Java had an |
I would prefer your option one, seems to be the simplest, and it would follow the same logic as with other functions and peripherals |
I'm currently opting for having @LuaFunction
public final EntityAPI getEntityAPI() {
return new EntityAPI(getPeripheralOwner());
} This means that within the
Or There is also a whole other issue of the fact that a malicious player could get their hands on a victims |
Sorry for not answering, I completely forgot this PR I would prefer the use of SphereOperation, your second option sounds more reasonable to me
If the function creates a new Entity API for every Maybe you're right, and the best way is to move all the functions into the EnvDetector itself. I at least would now prefer that |
Greetings @lonevox |
I just have an idea that you should not try to use UUID to index entity data at all, you can just returns a table include a method that takes no argument for extra information, such as: {
id = x,
uuid = xx,
name = xxx,
type = xxxx,
getAdvancedInfo = function() return <wrappedJavaMap> end,
getNBT = function() return <convertedNBTData> end,
} |
PLEASE READ THE GUIDELINES BEFORE MAKING A CONTRIBUTION
What kind of change does this PR introduce? (Bug fix, feature, ...)
Feature.
What is the current behavior? (You can also link to an open issue here)
Calling
EnvironmentDetectorPeripheral.scanEntities()
gives only a small amount of information on each entity. I felt like this could be used to a greater potential.What is the new behavior (if this is a feature change)?
Instead of getting a table with a small amount of data when calling
EnvironmentDetectorPeripheral.scanEntities()
, UUIDs for entities are now the only thing that is returned. These can be used with the new entity API. For example,entity.getNBT(uuid)
returns the NBT data of the entity with the given UUID.The entity API itself can be disabled in config, as well as the individual functions within it that could be deemed exploitative on servers.
A
PlayerDetectorPeripheral.getPlayerUUID(username)
Lua function has also been added so that you can make use of the entity API when using aPlayerDetectorPeripheral
.I have also expanded the amount of entity information you get when calling
LuaConverter.completeEntityToLua(entity)
. This function can be called via the entity API withentity.getData(uuid)
.Does this PR introduce a breaking change? (What changes might users need to make in their scripts due to this PR?)
Yes, any calls to
EnvironmentDetectorPeripheral.scanEntities()
will need to use the entity API to get the data that it used to give you.Calls to
AutomataEntityHandPlugin.searchAnimals()
now have position information in a table with the keyrelativePos
. This was a side-effect of cleaning upLuaConverter.completeEntityToLua(entity)
to not require anItemStack
to be passed to it.Other information:
I can make a PR for the docs if this PR is to be merged.