Place block offset at negative coordinates

Started by anoldshoe on Thu, 02/14/2019 - 03:38

Topic category: Help with modding (Java Edition)

Last seen on 22:22, 18. Feb 2019
Joined Jan 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Place block offset at negative coordinates
Thu, 02/14/2019 - 03:38

I have been trying to create an item that casts fire around the player. The item works perfectly at Pos X and Pos Z coords, but once i get into a negative coord, the fire is offset by one.

Negative coords Pos coords

package mod.mcreator;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.init.Blocks;

import java.util.HashMap;

public class mcreator_rOFItemInInventoryTick extends fire_starter.ModElement {

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		if (dependencies.get("x") == null) {
			System.err.println("Failed to load dependency x for procedure rOFItemInInventoryTick!");
			return;
		}
		if (dependencies.get("y") == null) {
			System.err.println("Failed to load dependency y for procedure rOFItemInInventoryTick!");
			return;
		}
		if (dependencies.get("z") == null) {
			System.err.println("Failed to load dependency z for procedure rOFItemInInventoryTick!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure rOFItemInInventoryTick!");
			return;
		}
		int x = (int) dependencies.get("x");
		int y = (int) dependencies.get("y");
		int z = (int) dependencies.get("z");
		World world = (World) dependencies.get("world");
		double Xrof = 0;
		double Zrof = 0;
		double Negxrof = 0;
		double Negzrof = 0;
		double count = 0;
		double rand = 0;
		double rando = 0;
		rand = ((double) Math.round((Math.random() * 4)));
		rando = ((double) Math.round((Math.random() * 4)));
		Xrof = ((double) (x + rand));
		Negxrof = ((double) (x - rand));
		Zrof = ((double) (z + rando));
		Negzrof = ((double) (z - rando));
		if (((world.getBlockState(new BlockPos((int) x, (int) y, (int) z))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) x, (int) y, (int) z));
		}
		if (((world.getBlockState(new BlockPos((int) (x + 1), (int) y, (int) z))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) (x + 1), (int) y, (int) z));
		}
		if (((world.getBlockState(new BlockPos((int) (x - 1), (int) y, (int) z))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) (x - 1), (int) y, (int) z));
		}
		if (((world.getBlockState(new BlockPos((int) (x + 1), (int) y, (int) (z + 1)))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) (x + 1), (int) y, (int) (z + 1)));
		}
		if (((world.getBlockState(new BlockPos((int) (x + 1), (int) y, (int) (z - 1)))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) (x + 1), (int) y, (int) (z - 1)));
		}
		if (((world.getBlockState(new BlockPos((int) (x - 1), (int) y, (int) (z - 1)))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) (x - 1), (int) y, (int) (z - 1)));
		}
		if (((world.getBlockState(new BlockPos((int) (x - 1), (int) y, (int) (z + 1)))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) (x - 1), (int) y, (int) (z + 1)));
		}
		if (((world.getBlockState(new BlockPos((int) x, (int) y, (int) (z + 1)))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) x, (int) y, (int) (z + 1)));
		}
		if (((world.getBlockState(new BlockPos((int) x, (int) y, (int) (z - 1)))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())) {
			world.setBlockToAir(new BlockPos((int) x, (int) y, (int) (z - 1)));
		}
		if (((world.isAirBlock(new BlockPos((int) Xrof, (int) y, (int) Zrof))) && (((!(((world.getBlockState(new BlockPos((int) Xrof, (int) (y - 1),
				(int) Zrof))).getBlock() == Blocks.AIR.getDefaultState().getBlock()) && (!((world.getBlockState(new BlockPos((int) Xrof,
				(int) (y - 1), (int) Zrof))).getBlock() == Blocks.WATER.getDefaultState().getBlock())))) && ((!((world.getBlockState(new BlockPos(
				(int) Xrof, (int) (y - 1), (int) Zrof))).getBlock() == Blocks.TALLGRASS.getStateFromMeta(1).getBlock())) && (!((world
				.getBlockState(new BlockPos((int) Xrof, (int) (y - 1), (int) Zrof))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())))) && ((Math
				.abs((Math.abs(Xrof) - Math.abs(x))) >= 2) || (Math.abs((Math.abs(Zrof) - Math.abs(z))) >= 2))))) {
			world.setBlockState(new BlockPos((int) Xrof, (int) y, (int) Zrof), Blocks.FIRE.getDefaultState(), 3);
		}
		if (((world.isAirBlock(new BlockPos((int) Xrof, (int) y, (int) Negzrof))) && (((!(((world.getBlockState(new BlockPos((int) Xrof,
				(int) (y - 1), (int) Negzrof))).getBlock() == Blocks.AIR.getDefaultState().getBlock()) && (!((world.getBlockState(new BlockPos(
				(int) Xrof, (int) (y - 1), (int) Negzrof))).getBlock() == Blocks.WATER.getDefaultState().getBlock())))) && (!(((world
				.getBlockState(new BlockPos((int) Xrof, (int) (y - 1), (int) Negzrof))).getBlock() == Blocks.TALLGRASS.getStateFromMeta(1).getBlock()) && (!((world
				.getBlockState(new BlockPos((int) Xrof, (int) (y - 1), (int) Negzrof))).getBlock() == Blocks.FIRE.getDefaultState().getBlock()))))) && ((Math
				.abs((Math.abs(Xrof) - Math.abs(x))) >= 2) || (Math.abs((Math.abs(Negzrof) - Math.abs(z))) >= 2))))) {
			world.setBlockState(new BlockPos((int) Xrof, (int) y, (int) Negzrof), Blocks.FIRE.getDefaultState(), 3);
		}
		if (((world.isAirBlock(new BlockPos((int) Negxrof, (int) y, (int) Negzrof))) && (((!(((world.getBlockState(new BlockPos((int) Negxrof,
				(int) (y - 1), (int) Negzrof))).getBlock() == Blocks.AIR.getDefaultState().getBlock()) && (!((world.getBlockState(new BlockPos(
				(int) Negxrof, (int) (y - 1), (int) Negzrof))).getBlock() == Blocks.WATER.getDefaultState().getBlock())))) && (!(((world
				.getBlockState(new BlockPos((int) Negxrof, (int) (y - 1), (int) Negzrof))).getBlock() == Blocks.TALLGRASS.getStateFromMeta(1)
				.getBlock()) && (!((world.getBlockState(new BlockPos((int) Negxrof, (int) (y - 1), (int) Negzrof))).getBlock() == Blocks.FIRE
				.getDefaultState().getBlock()))))) && ((Math.abs((Math.abs(Negxrof) - Math.abs(x))) >= 2) || (Math.abs((Math.abs(Negzrof) - Math
				.abs(z))) >= 2))))) {
			world.setBlockState(new BlockPos((int) Negxrof, (int) y, (int) Negzrof), Blocks.FIRE.getDefaultState(), 3);
		}
		if (((world.isAirBlock(new BlockPos((int) Negxrof, (int) y, (int) Zrof))) && (((!(((world.getBlockState(new BlockPos((int) Negxrof,
				(int) (y - 1), (int) Zrof))).getBlock() == Blocks.AIR.getDefaultState().getBlock()) && (!((world.getBlockState(new BlockPos(
				(int) Negxrof, (int) (y - 1), (int) Zrof))).getBlock() == Blocks.WATER.getDefaultState().getBlock())))) && ((!((world
				.getBlockState(new BlockPos((int) Negxrof, (int) (y - 1), (int) Zrof))).getBlock() == Blocks.TALLGRASS.getStateFromMeta(1).getBlock())) && (!((world
				.getBlockState(new BlockPos((int) Negxrof, (int) (y - 1), (int) Zrof))).getBlock() == Blocks.FIRE.getDefaultState().getBlock())))) && ((Math
				.abs((Math.abs(Negxrof) - Math.abs(x))) >= 2) || (Math.abs((Math.abs(Zrof) - Math.abs(z))) >= 2))))) {
			world.setBlockState(new BlockPos((int) Negxrof, (int) y, (int) Zrof), Blocks.FIRE.getDefaultState(), 3);
		}
	}
}

 

Last seen on 22:22, 18. Feb 2019
Joined Jan 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Any help would be nice…
Mon, 02/18/2019 - 22:22

Any help would be nice. still cant figure it out.

In addition to above, in detail, when i am at +X, +Z; the fire is placed around the player 2 or more blocks away up to 5 blocks in a ring(square). when i get to -X +Z, the ring offsets to the x like below

M=Fire, Q= air, P= Player   Facing North

MMMMMMM
MMMMMMM
MMQQQMM
MMPQQMM
MMQQQMM
MMMMMMM
MMMMMMM

when at -X, -Z:

MMMMMMM
MMMMMMM
MMPQQMM
MMQQQMM
MMQQQMM
MMMMMMM
MMMMMMM