Other mods items in procedures.

Started by MantecolWP on

Topic category: Help with modding (Java Edition)

Last seen on 07:32, 14. Apr 2021
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Other mods items in procedures.
Fri, 04/09/2021 - 06:38 (edited)

I'm trying to make a procedure that needs to give the player a certain item from other mod
I don't know how to code so I need help as I was unable to find any tutorial. I know that it might be possible with editing the code of the procedure but I can't make it work.
ANY WAY of giving the player this item will do the job.

Info of the item that might be useful:
Mod Name: "Mr Crayfish Vehicle Mod"
Item name: Large Engine
registry item name: vehicle:iron_large_engine

modid: vehicle
If we need any other info ask me.

The full code of the procedure: (did not implement the item yet.) We need to replace the "GoldenMagnetItem" for the item specified above.

package roleplayplus.procedures;
import roleplayplus.item.MoneyBillItem;
import roleplayplus.item.GoldMagnetItem;
import roleplayplus.RoleplayPlusModElements;
import roleplayplus.RoleplayPlusMod;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.Entity;

import java.util.Map;

@RoleplayPlusModElements.ModElement.Tag
public class BuyMotorPProcedure extends RoleplayPlusModElements.ModElement {
	public BuyMotorPProcedure(RoleplayPlusModElements instance) {
		super(instance, 76);
	}

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			if (!dependencies.containsKey("entity"))
				RoleplayPlusMod.LOGGER.warn("Failed to load dependency entity for procedure BuyMotorP!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		if (((entity instanceof PlayerEntity)
				? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(MoneyBillItem.block, (int) (1)))
				: false)) {
			if (entity instanceof PlayerEntity) {
				ItemStack _stktoremove = new ItemStack(MoneyBillItem.block, (int) (1));
				((PlayerEntity) entity).inventory.func_234564_a_(p -> _stktoremove.getItem() == p.getItem(), (int) 1,
						((PlayerEntity) entity).container.func_234641_j_());
			}
			if (((entity instanceof PlayerEntity)
					? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(MoneyBillItem.block, (int) (1)))
					: false)) {
				if (entity instanceof PlayerEntity) {
					ItemStack _stktoremove = new ItemStack(MoneyBillItem.block, (int) (1));
					((PlayerEntity) entity).inventory.func_234564_a_(p -> _stktoremove.getItem() == p.getItem(), (int) 1,
							((PlayerEntity) entity).container.func_234641_j_());
				}
				if (((entity instanceof PlayerEntity)
						? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(MoneyBillItem.block, (int) (1)))
						: false)) {
					if (entity instanceof PlayerEntity) {
						ItemStack _stktoremove = new ItemStack(MoneyBillItem.block, (int) (1));
						((PlayerEntity) entity).inventory.func_234564_a_(p -> _stktoremove.getItem() == p.getItem(), (int) 1,
								((PlayerEntity) entity).container.func_234641_j_());
					}
					if (((entity instanceof PlayerEntity)
							? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(MoneyBillItem.block, (int) (1)))
							: false)) {
						if (entity instanceof PlayerEntity) {
							ItemStack _stktoremove = new ItemStack(MoneyBillItem.block, (int) (1));
							((PlayerEntity) entity).inventory.func_234564_a_(p -> _stktoremove.getItem() == p.getItem(), (int) 1,
									((PlayerEntity) entity).container.func_234641_j_());
						}
						if (((entity instanceof PlayerEntity)
								? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(MoneyBillItem.block, (int) (1)))
								: false)) {
							if (entity instanceof PlayerEntity) {
								ItemStack _stktoremove = new ItemStack(MoneyBillItem.block, (int) (1));
								((PlayerEntity) entity).inventory.func_234564_a_(p -> _stktoremove.getItem() == p.getItem(), (int) 1,
										((PlayerEntity) entity).container.func_234641_j_());
							}
							if (((entity instanceof PlayerEntity)
									? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(MoneyBillItem.block, (int) (1)))
									: false)) {
								if (entity instanceof PlayerEntity) {
									ItemStack _stktoremove = new ItemStack(MoneyBillItem.block, (int) (1));
									((PlayerEntity) entity).inventory.func_234564_a_(p -> _stktoremove.getItem() == p.getItem(), (int) 1,
											((PlayerEntity) entity).container.func_234641_j_());
								}
								if (entity instanceof PlayerEntity) {
									ItemStack _setstack = new ItemStack(GoldenMagnetItem.block, (int) (1));
									_setstack.setCount((int) 1);
									ItemHandlerHelper.giveItemToPlayer(((PlayerEntity) entity), _setstack);
								}
							} else {
								if (entity instanceof PlayerEntity) {
									ItemStack _setstack = new ItemStack(MoneyBillItem.block, (int) (1));
									_setstack.setCount((int) 5);
									ItemHandlerHelper.giveItemToPlayer(((PlayerEntity) entity), _setstack);
								}
							}
						} else {
							if (entity instanceof PlayerEntity) {
								ItemStack _setstack = new ItemStack(MoneyBillItem.block, (int) (1));
								_setstack.setCount((int) 4);
								ItemHandlerHelper.giveItemToPlayer(((PlayerEntity) entity), _setstack);
							}
						}
					} else {
						if (entity instanceof PlayerEntity) {
							ItemStack _setstack = new ItemStack(MoneyBillItem.block, (int) (1));
							_setstack.setCount((int) 3);
							ItemHandlerHelper.giveItemToPlayer(((PlayerEntity) entity), _setstack);
						}
					}
				} else {
					if (entity instanceof PlayerEntity) {
						ItemStack _setstack = new ItemStack(MoneyBillItem.block, (int) (1));
						_setstack.setCount((int) 2);
						ItemHandlerHelper.giveItemToPlayer(((PlayerEntity) entity), _setstack);
					}
				}
			} else {
				if (entity instanceof PlayerEntity) {
					ItemStack _setstack = new ItemStack(MoneyBillItem.block, (int) (1));
					_setstack.setCount((int) 1);
					ItemHandlerHelper.giveItemToPlayer(((PlayerEntity) entity), _setstack);
				}
			}
		}
	}
}

For now I have a workaround using the /give command but this may be useful to learn for the future if the target is not a player.

Edited by MantecolWP on Fri, 04/09/2021 - 06:38
Last seen on 22:19, 4. Nov 2023
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I am trying to do the exact…
Tue, 03/07/2023 - 14:47

I am trying to do the exact same thing and i HATE that people don't care and do not want to reply to such topics. They are extremely useful for everybody. there's probably someone out there who knows how this should be done and keeps it in secret.

Last seen on 10:28, 28. Mar 2024
Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Use convert registry name…
Thu, 10/12/2023 - 13:57

Use convert registry name name "mod:block / item" to block / item, and use If - Is the mod with ID "mod" loaded