CreeperHost Presents Chickens

CreeperHost Presents Chickens

2M Downloads

Adding the interacting with item to other chickens than just the smart chicken

Waterspark63 opened this issue Β· 6 comments

commented

Basically the title, is it possible to add a config option to allow chickens to be interacted with a item, preferably as a alternate way to 'breed' custom chickens? (Clicking coal on a chicken to get a coal chicken, etc). If not no worries.

commented

First, I feel I need to explain that I'm not officially part of the team that supports or develops the mod; just an enthusiastic fan trying to help others the best I'm able πŸ˜ƒ

Second, in short, I like the idea, and you are correct that in a way, it is already being used. However, I only warn that the implementation may not be as easy as just changing a couple lines of code. It may indeed require an entirely new version to how the mod currently works, an addon that is dependent on the current mod, or a new stand-alone mod entirely.

To clarify, I should start by explaining what I mean by "hard-coding" versus the lookup table approach. By hard-coding, I mean that the book is specifically called out in the mod's code itself. It works by looking for any click action (specifically right-click) taken by the player. Then, it checks if the target of the click action was a "minecraft:chicken" entity. If so, was the item in the player's hand a "minecraft:book"? If the answer to all of these is "yes", then the "minecraft:chicken" entity is replaced with a "chickens:smart_chicken" entity.

Coding the mod to work in this way is fine if the list of items is small. As it is, the only two things the mod is concerned with is the book for the smart chicken, or the chicken catcher to turn the entity into an item. The problem comes when trying to expand the list. Though we as players don't see anything, for every item that can perform an action like the book, there is a small delay for each calculation the game and mod code have to do to tell what the resulting action is supposed to accomplish. The longer the list of items the game has to check to validate if it is supposed to create a specific chicken, the more delays get added. At some point, it will reach a value that players CAN and WILL notice. In addition, implementing the code for other items as it is written for the book would mean a significantly larger code file. It would also mean that the list of items would be predetermined (so no ability to customize).

So then the other option is to add a lookup table or something similar to how the config file currently works. And to be honest, this is where my lack of coding knowledge really begins to show πŸ€¦β€β™‚οΈ I know enough to know that it SHOULD be possible, given that the config file works. However, I don't know enough to be able to explain HOW the config file works. Through my own experimentation, I do know that a completely custom chicken can be added, but either a mod like kubejs or knowledge on creating custom datapacks is necessary or else function/look/naming (or a combination) don't behave or look right for the custom chicken, if they work at all.

Apologies for the novel. Hope this helps 😁

commented

Apologies for the late reply, things have been a bit hectic for me.

If this is a stupid idea, then feel free to tell me, as I don't know mc modding that well, but what about just adding a single option to the configs for the chickens? As far as I'm aware, you already basically have the logic for the click on chicken, theoretically (correct me if I'm wrong), what if instead of it grabbing the book in the hard code, it just checks the option in the chicken config itself? I don't know if the config is loaded by then or not, but if it is, couldn't you have it iterate through the different chickens, and get the value of 'convert-item' or something, (and if it's a valid item), and if it matches, it converts the chicken to the referenced config chicken? I'm not too good at making optimized code, but in idea would that work?

commented

Ah, no worries! If I came across as expecting that you were so then I apologize.

That is fair, I also don't really know minecraft modding, so I could just not realize the extent of the work needed to add that functionality. And your not wrong about the increasing delay with larger and larger lists, though I do wonder if forge has a entity clicked event or something. If the mod could be searching specifically for a entity being clicked, rather than any and all right click events, that might help with some of the speed issue, but that more depends on if forge has that functionality or not.

I don't know if it would help with speed or not, but it could also be a option to have all the converted items loaded into a list or map on world/game load, and have a key, value of item, chicken, whichever object would be most optimized for this kinda thing, having a cached list for the items to check might help, and might be able to pull from the idea of FastSuite, having the list reordered by the last/most commonly used items to make searching a bit quicker.

Again, I probably don't realize the scope of things, more just kinda brainstorming ideas that might make it work.

And no worries for the novel, it was nice reading it ^^ Sorry if I don't have the.. volume to reply with a novel of my own πŸ˜„

EDIT:
It actually seems like they do, unless I'm misunderstanding the method used:
playerInteractEvent(PlayerInteractEvent.EntityInteract event)

commented

I don't think it would be impossible, but from what I can tell from the code, implementing it would almost be a new mod unto itself. Just as an example, the book to create a smart chicken is hard-coded. However, the implementation for what two chickens breed to make a new chicken is open-ended. To allow the flexibility to "click item on chicken, get item-chicken", that hard-coding would either become massive and messy to check each item in the game (and we're just talking vanilla, forget modded 🀯), or would need to be completely rewritten.

On the other hand, it would also help expand the ways in which new chickens could be created. One thing I try to do when I add custom chickens myself is use a chicken I would otherwise overlook. That way, they all get used at least once, and it forces me to be more strategic on which chickens I start with.

commented

EDIT: It actually seems like they do, unless I'm misunderstanding the method used: playerInteractEvent(PlayerInteractEvent.EntityInteract event)

Actually, that's the exact command the mod uses πŸ˜† So I am wrong that it's not EVERY right-click action. However, it IS specifically looking for a book:
if(!player.getItemInHand(event.getHand()).isEmpty() && player.getItemInHand(event.getHand()).getItem() == Items.BOOK)

I imagine that there probably IS a way to have the mod look through a predefined, editable list during start-up in place of the "Items.BOOK", the same way the config file is used. Unfortunately, I just don't have enough coding knowledge, and Java knowledge especially, to be able to suggest a good way to implement the idea.

As for the role miscommunication/misunderstanding/whatever, apology accepted πŸ˜ƒand I apologize, as well. Regardless of whether you had the impression that I am more involved with the project, I can understand how I potentially gave the impression (and therefore assumed that I had already done so). I do tend to over-explain a lot πŸ˜… especially with things I enjoy.

commented

There probably is, but as I said before, I'm ok with coding, but not necessarily with making optimized code x3 It'd be cool for that to be a natural feature, but I can understand why if it doesn't, as your point of the expanding list causing a delay is fair.

Don't apologize for over-explaining, as I do the exact same thing xD You don't need to apologize for that with me.

If anyone is interested in the idea, I did get a semi working script version of it for kubejs, you just have to add/modify it to your needs ^^

const clickItems= {
	item1: `MOD:ITEM1`,
	item2: `MOD:ITEM2`
}

onEvent(`item.entity_interact`, event => {
	if(!event.target.player && event.target.type == `minecraft:chicken`) {
		Object.keys(clickItems).forEach(key => {
			if(event.item.id === clickItems[key]) {
				event.item.count--;
				event.target.y = -200;
				event.server.runCommandSilent(`summon chickens:${key}_chicken ${event.player.x} ${event.player.y+1} ${event.player.z}`);
				event.target.health = 1;
			}
		});
	}
});