Problem with getting block location GUI is bound to. (Modjam Mod)

Started by Chris_C_2023 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Problem with getting block location GUI is bound to. (Modjam Mod)
Sat, 05/11/2024 - 16:22 (edited)

I'm making a mod for the mod jam, and I want a machine that you can put an item in then get a liquid, but whenever I try anything related to needing the block's location, I can't get it to work. I made something that would summon the block you are looking at, to test if it got the block, but when I try anything related to the fluids, nothing works.

The current code is below, and it is done through a GUI tick event. (I'm not sure what I should include, so I just did everything, and I remembered to enable fluid storage)


package net.mcreator.astralrealms.procedures;

/* imports omitted */

public class AEXOpenActiveProcedure {
	public static void execute(LevelAccessor world, Entity entity, HashMap guistate) {
		if (entity == null || guistate == null)
			return;
		boolean found = false;
		double previousRecipe = 0;
		double sx = 0;
		double sy = 0;
		double sz = 0;
		if (new Object() {
			public int getAmount(int sltid) {
				if (entity instanceof Player _player && _player.containerMenu instanceof Supplier _current && _current.get() instanceof Map _slots) {
					ItemStack stack = ((Slot) _slots.get(sltid)).getItem();
					if (stack != null)
						return stack.getCount();
				}
				return 0;
			}
		}.getAmount(0) > 0) {
			if ((world.getBlockState(
					new BlockPos(entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
							entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
							entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ())))
					.getBlock() == AstralRealmsModBlocks.ASTRAL_ESSENCE_EXTRACTOR.get()) {
				if (new Object() {
					public int getFluidTankLevel(LevelAccessor level, BlockPos pos, int tank) {
						if (level instanceof ILevelExtension _ext) {
							IFluidHandler _fluidHandler = _ext.getCapability(Capabilities.FluidHandler.BLOCK, pos, null);
							if (_fluidHandler != null)
								return _fluidHandler.getFluidInTank(tank).getAmount();
						}
						return 0;
					}
				}.getFluidTankLevel(world,
						new BlockPos(entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
								entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
								entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ()),
						1) == 0) {
					if (entity instanceof Player _player && _player.containerMenu instanceof Supplier _current && _current.get() instanceof Map _slots) {
						((Slot) _slots.get(0)).remove(1);
						_player.containerMenu.broadcastChanges();
					}
					if (world instanceof ILevelExtension _ext) {
						IFluidHandler _fluidHandler = _ext.getCapability(Capabilities.FluidHandler.BLOCK, new BlockPos(
								entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
								entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
								entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ()), null);
						if (_fluidHandler != null)
							_fluidHandler.fill(new FluidStack(AstralRealmsModFluids.ASTRAL_ESSENCE_FLUID.get(), 1000), IFluidHandler.FluidAction.EXECUTE);
					}
					if (guistate.get("text:curent_fluid") instanceof EditBox _tf)
						_tf.setValue(("" + (new Object() {
							public int getFluidTankLevel(LevelAccessor level, BlockPos pos, int tank) {
								if (level instanceof ILevelExtension _ext) {
									IFluidHandler _fluidHandler = _ext.getCapability(Capabilities.FluidHandler.BLOCK, pos, null);
									if (_fluidHandler != null)
										return _fluidHandler.getFluidInTank(tank).getAmount();
								}
								return 0;
							}
						}.getFluidTankLevel(world, new BlockPos(
								entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
								entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
								entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ()), 1))));
					AstralRealmsMod.queueServerWork(100, () -> {
						if (guistate.get("text:curent_fluid") instanceof EditBox _tf)
							_tf.setValue("test");
						assert Boolean.TRUE; //#dbg:AEXOpenActive:sucess
					});
				}
			}
		}
	}
}
Edited by Chris_C_2023 on Sat, 05/11/2024 - 16:22