Jump to content

[1.11] Portal not working


Kokkie

Recommended Posts

Hello, I made a portal and dimension, the dimension works but that portal crashes when going through it, the code of the teleporter class:

public class CheeseTeleporter extends Teleporter {
private final WorldServer worldServerInstance;
/** A private Random() function in Teleporter */
private final Random random;
private final Long2ObjectMap<CheeseTeleporter.PortalPosition> destinationCoordinateCache = new Long2ObjectOpenHashMap(
		4096);

public CheeseTeleporter(WorldServer worldIn) {
	super(worldIn);
	this.worldServerInstance = worldIn;
	this.random = new Random(worldIn.getSeed());
}

public void placeInPortal(Entity entityIn, float rotationYaw) {
	if (this.worldServerInstance.provider.getDimensionType().getId() != 1) {
		if (!this.placeInExistingPortal(entityIn, rotationYaw)) {
			this.makePortal(entityIn);
			this.placeInExistingPortal(entityIn, rotationYaw);
		}
	} else {
		int i = MathHelper.floor_double(entityIn.posX);
		int j = MathHelper.floor_double(entityIn.posY) - 1;
		int k = MathHelper.floor_double(entityIn.posZ);
		int l = 1;
		int i1 = 0;

		for (int j1 = -2; j1 <= 2; ++j1) {
			for (int k1 = -2; k1 <= 2; ++k1) {
				for (int l1 = -1; l1 < 3; ++l1) {
					int i2 = i + k1 * 1 + j1 * 0;
					int j2 = j + l1;
					int k2 = k + k1 * 0 - j1 * 1;
					boolean flag = l1 < 0;
					this.worldServerInstance.setBlockState(new BlockPos(i2, j2, k2),
							flag ? CheeseBlocks.CHEESE_BLOCK.getDefaultState() : Blocks.AIR.getDefaultState());
				}
			}
		}

		entityIn.setLocationAndAngles((double) i, (double) j, (double) k, entityIn.rotationYaw, 0.0F);
		entityIn.motionX = 0.0D;
		entityIn.motionY = 0.0D;
		entityIn.motionZ = 0.0D;
	}
}

public boolean placeInExistingPortal(Entity entityIn, float rotationYaw) {
	int i = 128;
	double d0 = -1.0D;
	int j = MathHelper.floor_double(entityIn.posX);
	int k = MathHelper.floor_double(entityIn.posZ);
	boolean flag = true;
	BlockPos blockpos = BlockPos.ORIGIN;
	long l = ChunkPos.asLong(j, k);

	if (this.destinationCoordinateCache.containsKey(l)) {
		CheeseTeleporter.PortalPosition teleporter$portalposition = (CheeseTeleporter.PortalPosition) this.destinationCoordinateCache
				.get(l);
		d0 = 0.0D;
		blockpos = teleporter$portalposition;
		teleporter$portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime();
		flag = false;
	} else {
		BlockPos blockpos3 = new BlockPos(entityIn);

		for (int i1 = -128; i1 <= 128; ++i1) {
			BlockPos blockpos2;

			for (int j1 = -128; j1 <= 128; ++j1) {
				for (BlockPos blockpos1 = blockpos3.add(i1,
						this.worldServerInstance.getActualHeight() - 1 - blockpos3.getY(), j1); blockpos1
								.getY() >= 0; blockpos1 = blockpos2) {
					blockpos2 = blockpos1.down();

					if (this.worldServerInstance.getBlockState(blockpos1).getBlock() == CheeseBlocks.CHEESE_PORTAL) {
						for (blockpos2 = blockpos1.down(); this.worldServerInstance.getBlockState(blockpos2)
								.getBlock() == CheeseBlocks.CHEESE_PORTAL; blockpos2 = blockpos2.down()) {
							blockpos1 = blockpos2;
						}

						double d1 = blockpos1.distanceSq(blockpos3);

						if (d0 < 0.0D || d1 < d0) {
							d0 = d1;
							blockpos = blockpos1;
						}
					}
				}
			}
		}
	}

	if (d0 >= 0.0D) {
		if (flag) {
			this.destinationCoordinateCache.put(l,
					new CheeseTeleporter.PortalPosition(blockpos, this.worldServerInstance.getTotalWorldTime()));
		}

		double d5 = (double) blockpos.getX() + 0.5D;
		double d7 = (double) blockpos.getZ() + 0.5D;
		BlockPattern.PatternHelper blockpattern$patternhelper = CheeseBlocks.CHEESE_PORTAL
				.createPatternHelper(this.worldServerInstance, blockpos);
		boolean flag1 = blockpattern$patternhelper.getForwards().rotateY()
				.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE;
		double d2 = blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X
				? (double) blockpattern$patternhelper.getFrontTopLeft().getZ()
				: (double) blockpattern$patternhelper.getFrontTopLeft().getX();
		double d6 = (double) (blockpattern$patternhelper.getFrontTopLeft().getY() + 1)
				- entityIn.getLastPortalVec().yCoord * (double) blockpattern$patternhelper.getHeight();

		if (flag1) {
			++d2;
		}

		if (blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X) {
			d7 = d2 + (1.0D - entityIn.getLastPortalVec().xCoord) * (double) blockpattern$patternhelper.getWidth()
					* (double) blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset();
		} else {
			d5 = d2 + (1.0D - entityIn.getLastPortalVec().xCoord) * (double) blockpattern$patternhelper.getWidth()
					* (double) blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset();
		}

		float f = 0.0F;
		float f1 = 0.0F;
		float f2 = 0.0F;
		float f3 = 0.0F;

		if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection()) {
			f = 1.0F;
			f1 = 1.0F;
		} else if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection()
				.getOpposite()) {
			f = -1.0F;
			f1 = -1.0F;
		} else if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection()
				.rotateY()) {
			f2 = 1.0F;
			f3 = -1.0F;
		} else {
			f2 = -1.0F;
			f3 = 1.0F;
		}

		double d3 = entityIn.motionX;
		double d4 = entityIn.motionZ;
		entityIn.motionX = d3 * (double) f + d4 * (double) f3;
		entityIn.motionZ = d3 * (double) f2 + d4 * (double) f1;
		entityIn.rotationYaw = rotationYaw
				- (float) (entityIn.getTeleportDirection().getOpposite().getHorizontalIndex() * 90)
				+ (float) (blockpattern$patternhelper.getForwards().getHorizontalIndex() * 90);

		if (entityIn instanceof EntityPlayerMP) {
			((EntityPlayerMP) entityIn).connection.setPlayerLocation(d5, d6, d7, entityIn.rotationYaw,
					entityIn.rotationPitch);
		} else {
			entityIn.setLocationAndAngles(d5, d6, d7, entityIn.rotationYaw, entityIn.rotationPitch);
		}

		return true;
	} else {
		return false;
	}
}

public boolean makePortal(Entity entityIn) {
	int i = 16;
	double d0 = -1.0D;
	int j = MathHelper.floor_double(entityIn.posX);
	int k = MathHelper.floor_double(entityIn.posY);
	int l = MathHelper.floor_double(entityIn.posZ);
	int i1 = j;
	int j1 = k;
	int k1 = l;
	int l1 = 0;
	int i2 = this.random.nextInt(4);
	BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

	for (int j2 = j - 16; j2 <= j + 16; ++j2) {
		double d1 = (double) j2 + 0.5D - entityIn.posX;

		for (int l2 = l - 16; l2 <= l + 16; ++l2) {
			double d2 = (double) l2 + 0.5D - entityIn.posZ;
			label146:

			for (int j3 = this.worldServerInstance.getActualHeight() - 1; j3 >= 0; --j3) {
				if (this.worldServerInstance.isAirBlock(blockpos$mutableblockpos.setPos(j2, j3, l2))) {
					while (j3 > 0 && this.worldServerInstance
							.isAirBlock(blockpos$mutableblockpos.setPos(j2, j3 - 1, l2))) {
						--j3;
					}

					for (int k3 = i2; k3 < i2 + 4; ++k3) {
						int l3 = k3 % 2;
						int i4 = 1 - l3;

						if (k3 % 4 >= 2) {
							l3 = -l3;
							i4 = -i4;
						}

						for (int j4 = 0; j4 < 3; ++j4) {
							for (int k4 = 0; k4 < 4; ++k4) {
								for (int l4 = -1; l4 < 4; ++l4) {
									int i5 = j2 + (k4 - 1) * l3 + j4 * i4;
									int j5 = j3 + l4;
									int k5 = l2 + (k4 - 1) * i4 - j4 * l3;
									blockpos$mutableblockpos.setPos(i5, j5, k5);

									if (l4 < 0
											&& !this.worldServerInstance.getBlockState(blockpos$mutableblockpos)
													.getMaterial().isSolid()
											|| l4 >= 0 && !this.worldServerInstance
													.isAirBlock(blockpos$mutableblockpos)) {
										continue label146;
									}
								}
							}
						}

						double d5 = (double) j3 + 0.5D - entityIn.posY;
						double d7 = d1 * d1 + d5 * d5 + d2 * d2;

						if (d0 < 0.0D || d7 < d0) {
							d0 = d7;
							i1 = j2;
							j1 = j3;
							k1 = l2;
							l1 = k3 % 4;
						}
					}
				}
			}
		}
	}

	if (d0 < 0.0D) {
		for (int l5 = j - 16; l5 <= j + 16; ++l5) {
			double d3 = (double) l5 + 0.5D - entityIn.posX;

			for (int j6 = l - 16; j6 <= l + 16; ++j6) {
				double d4 = (double) j6 + 0.5D - entityIn.posZ;
				label567:

				for (int i7 = this.worldServerInstance.getActualHeight() - 1; i7 >= 0; --i7) {
					if (this.worldServerInstance.isAirBlock(blockpos$mutableblockpos.setPos(l5, i7, j6))) {
						while (i7 > 0 && this.worldServerInstance
								.isAirBlock(blockpos$mutableblockpos.setPos(l5, i7 - 1, j6))) {
							--i7;
						}

						for (int k7 = i2; k7 < i2 + 2; ++k7) {
							int j8 = k7 % 2;
							int j9 = 1 - j8;

							for (int j10 = 0; j10 < 4; ++j10) {
								for (int j11 = -1; j11 < 4; ++j11) {
									int j12 = l5 + (j10 - 1) * j8;
									int i13 = i7 + j11;
									int j13 = j6 + (j10 - 1) * j9;
									blockpos$mutableblockpos.setPos(j12, i13, j13);

									if (j11 < 0
											&& !this.worldServerInstance.getBlockState(blockpos$mutableblockpos)
													.getMaterial().isSolid()
											|| j11 >= 0 && !this.worldServerInstance
													.isAirBlock(blockpos$mutableblockpos)) {
										continue label567;
									}
								}
							}

							double d6 = (double) i7 + 0.5D - entityIn.posY;
							double d8 = d3 * d3 + d6 * d6 + d4 * d4;

							if (d0 < 0.0D || d8 < d0) {
								d0 = d8;
								i1 = l5;
								j1 = i7;
								k1 = j6;
								l1 = k7 % 2;
							}
						}
					}
				}
			}
		}
	}

	int i6 = i1;
	int k2 = j1;
	int k6 = k1;
	int l6 = l1 % 2;
	int i3 = 1 - l6;

	if (l1 % 4 >= 2) {
		l6 = -l6;
		i3 = -i3;
	}

	if (d0 < 0.0D) {
		j1 = MathHelper.clamp_int(j1, 70, this.worldServerInstance.getActualHeight() - 10);
		k2 = j1;

		for (int j7 = -1; j7 <= 1; ++j7) {
			for (int l7 = 1; l7 < 3; ++l7) {
				for (int k8 = -1; k8 < 3; ++k8) {
					int k9 = i6 + (l7 - 1) * l6 + j7 * i3;
					int k10 = k2 + k8;
					int k11 = k6 + (l7 - 1) * i3 - j7 * l6;
					boolean flag = k8 < 0;
					this.worldServerInstance.setBlockState(new BlockPos(k9, k10, k11),
							flag ? CheeseBlocks.CHEESE_BLOCK.getDefaultState() : Blocks.AIR.getDefaultState());
				}
			}
		}
	}

	IBlockState iblockstate = CheeseBlocks.CHEESE_PORTAL.getDefaultState().withProperty(BlockPortal.AXIS,
			l6 == 0 ? EnumFacing.Axis.Z : EnumFacing.Axis.X);

	for (int i8 = 0; i8 < 4; ++i8) {
		for (int l8 = 0; l8 < 4; ++l8) {
			for (int l9 = -1; l9 < 4; ++l9) {
				int l10 = i6 + (l8 - 1) * l6;
				int l11 = k2 + l9;
				int k12 = k6 + (l8 - 1) * i3;
				boolean flag1 = l8 == 0 || l8 == 3 || l9 == -1 || l9 == 3;
				this.worldServerInstance.setBlockState(new BlockPos(l10, l11, k12),
						flag1 ? CheeseBlocks.CHEESE_BLOCK.getDefaultState() : iblockstate, 2);
			}
		}

		for (int i9 = 0; i9 < 4; ++i9) {
			for (int i10 = -1; i10 < 4; ++i10) {
				int i11 = i6 + (i9 - 1) * l6;
				int i12 = k2 + i10;
				int l12 = k6 + (i9 - 1) * i3;
				BlockPos blockpos = new BlockPos(i11, i12, l12);
				this.worldServerInstance.notifyNeighborsOfStateChange(blockpos,
						this.worldServerInstance.getBlockState(blockpos).getBlock(), false);
			}
		}
	}

	return true;
}

/**
 * called periodically to remove out-of-date portal locations from the cache
 * list. Argument par1 is a WorldServer.getTotalWorldTime() value.
 */
public void removeStalePortalLocations(long worldTime) {
	if (worldTime % 100L == 0L) {
		long i = worldTime - 300L;
		ObjectIterator<CheeseTeleporter.PortalPosition> objectiterator = this.destinationCoordinateCache.values()
				.iterator();

		while (objectiterator.hasNext()) {
			CheeseTeleporter.PortalPosition teleporter$portalposition = (CheeseTeleporter.PortalPosition) objectiterator
					.next();

			if (teleporter$portalposition == null || teleporter$portalposition.lastUpdateTime < i) {
				objectiterator.remove();
			}
		}
	}
}

public class PortalPosition extends BlockPos {
	/** The worldtime at which this PortalPosition was last verified */
	public long lastUpdateTime;

	public PortalPosition(BlockPos pos, long lastUpdate) {
		super(pos.getX(), pos.getY(), pos.getZ());
		this.lastUpdateTime = lastUpdate;
	}
}
}

The portal class

public class CheesePortal extends BlockBreakable {
public static final PropertyEnum<EnumFacing.Axis> AXIS = PropertyEnum.<EnumFacing.Axis>create("axis",
		EnumFacing.Axis.class, new EnumFacing.Axis[] { EnumFacing.Axis.X, EnumFacing.Axis.Z });
protected static final AxisAlignedBB X_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D);
protected static final AxisAlignedBB Z_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D);
protected static final AxisAlignedBB Y_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D);

public CheesePortal() {
	super(Material.PORTAL, false);
	this.setDefaultState(this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.X));
	this.setTickRandomly(true);
}

public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
	switch ((EnumFacing.Axis) state.getValue(AXIS)) {
	case X:
		return X_AABB;
	case Y:
	default:
		return Y_AABB;
	case Z:
		return Z_AABB;
	}
}

public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
	super.updateTick(worldIn, pos, state, rand);

	if (worldIn.provider.isSurfaceWorld() && worldIn.getGameRules().getBoolean("doMobSpawning")
			&& rand.nextInt(2000) < worldIn.getDifficulty().getDifficultyId()) {
		int i = pos.getY();
		BlockPos blockpos;

		for (blockpos = pos; !worldIn.getBlockState(blockpos).isFullyOpaque()
				&& blockpos.getY() > 0; blockpos = blockpos.down()) {
			;
		}

		if (i > 0 && !worldIn.getBlockState(blockpos.up()).isNormalCube()) {
			Entity entity = ItemMonsterPlacer.spawnCreature(worldIn,
					EntityList.func_191306_a(EntityPigZombie.class), (double) blockpos.getX() + 0.5D,
					(double) blockpos.getY() + 1.1D, (double) blockpos.getZ() + 0.5D);

			if (entity != null) {
				entity.timeUntilPortal = entity.getPortalCooldown();
			}
		}
	}
}

@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
	return NULL_AABB;
}

public static int getMetaForAxis(EnumFacing.Axis axis) {
	return axis == EnumFacing.Axis.X ? 1 : (axis == EnumFacing.Axis.Z ? 2 : 0);
}

public boolean isFullCube(IBlockState state) {
	return false;
}

public boolean trySpawnPortal(World worldIn, BlockPos pos) {
	CheesePortal.Size blockportal$size = new CheesePortal.Size(worldIn, pos, EnumFacing.Axis.X);

	if (blockportal$size.isValid() && blockportal$size.portalBlockCount == 0) {
		blockportal$size.placePortalBlocks();
		return true;
	} else {
		CheesePortal.Size blockportal$size1 = new CheesePortal.Size(worldIn, pos, EnumFacing.Axis.Z);

		if (blockportal$size1.isValid() && blockportal$size1.portalBlockCount == 0) {
			blockportal$size1.placePortalBlocks();
			return true;
		} else {
			return false;
		}
	}
}

/**
 * Called when a neighboring block was changed and marks that this state
 * should perform any checks during a neighbor change. Cases may include
 * when redstone power is updated, cactus blocks popping off due to a
 * neighboring solid block, etc.
 */
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_) {
	EnumFacing.Axis enumfacing$axis = (EnumFacing.Axis) state.getValue(AXIS);

	if (enumfacing$axis == EnumFacing.Axis.X) {
		CheesePortal.Size blockportal$size = new CheesePortal.Size(worldIn, pos, EnumFacing.Axis.X);

		if (!blockportal$size.isValid()
				|| blockportal$size.portalBlockCount < blockportal$size.width * blockportal$size.height) {
			worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
		}
	} else if (enumfacing$axis == EnumFacing.Axis.Z) {
		CheesePortal.Size blockportal$size1 = new CheesePortal.Size(worldIn, pos, EnumFacing.Axis.Z);

		if (!blockportal$size1.isValid()
				|| blockportal$size1.portalBlockCount < blockportal$size1.width * blockportal$size1.height) {
			worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
		}
	}
}

@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,
		EnumFacing side) {
	pos = pos.offset(side);
	EnumFacing.Axis enumfacing$axis = null;

	if (blockState.getBlock() == this) {
		enumfacing$axis = (EnumFacing.Axis) blockState.getValue(AXIS);

		if (enumfacing$axis == null) {
			return false;
		}

		if (enumfacing$axis == EnumFacing.Axis.Z && side != EnumFacing.EAST && side != EnumFacing.WEST) {
			return false;
		}

		if (enumfacing$axis == EnumFacing.Axis.X && side != EnumFacing.SOUTH && side != EnumFacing.NORTH) {
			return false;
		}
	}

	boolean flag = blockAccess.getBlockState(pos.west()).getBlock() == this
			&& blockAccess.getBlockState(pos.west(2)).getBlock() != this;
	boolean flag1 = blockAccess.getBlockState(pos.east()).getBlock() == this
			&& blockAccess.getBlockState(pos.east(2)).getBlock() != this;
	boolean flag2 = blockAccess.getBlockState(pos.north()).getBlock() == this
			&& blockAccess.getBlockState(pos.north(2)).getBlock() != this;
	boolean flag3 = blockAccess.getBlockState(pos.south()).getBlock() == this
			&& blockAccess.getBlockState(pos.south(2)).getBlock() != this;
	boolean flag4 = flag || flag1 || enumfacing$axis == EnumFacing.Axis.X;
	boolean flag5 = flag2 || flag3 || enumfacing$axis == EnumFacing.Axis.Z;
	return flag4 && side == EnumFacing.WEST ? true
			: (flag4 && side == EnumFacing.EAST ? true
					: (flag5 && side == EnumFacing.NORTH ? true : flag5 && side == EnumFacing.SOUTH));
}

/**
 * Returns the quantity of items to drop on block destruction.
 */
public int quantityDropped(Random random) {
	return 0;
}

/**
 * Called When an Entity Collided with the Block
 */
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
	if (!entityIn.isRiding() && !entityIn.isBeingRidden() && entityIn.isNonBoss()) {
		if (entityIn.timeUntilPortal > 0) {
			entityIn.timeUntilPortal = entityIn.getPortalCooldown();
		} else {
			if (!worldIn.isRemote && !pos.equals(getField(Entity.class, entityIn, "lastPortalPos"))) {
				setField(Entity.class, entityIn, "lastPortalPos", pos);
				BlockPattern.PatternHelper blockpattern$patternhelper = CheeseBlocks.CHEESE_PORTAL.createPatternHelper(worldIn, pos);
				double d0 = blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X
						? (double) blockpattern$patternhelper.getFrontTopLeft().getZ()
						: (double) blockpattern$patternhelper.getFrontTopLeft().getX();
				double d1 = blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X ? entityIn.posZ
						: entityIn.posX;
				d1 = Math.abs(MathHelper.pct(
						d1 - (double) (blockpattern$patternhelper.getForwards().rotateY()
								.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? 1 : 0),
						d0, d0 - (double) blockpattern$patternhelper.getWidth()));
				double d2 = MathHelper.pct(entityIn.posY - 1.0D,
						(double) blockpattern$patternhelper.getFrontTopLeft().getY(),
						(double) (blockpattern$patternhelper.getFrontTopLeft().getY()
								- blockpattern$patternhelper.getHeight()));
				setField(Entity.class, entityIn, "lastPortalVex", new Vec3d(d1, d2, 0.0D));
				setField(Entity.class, entityIn, "teleportDirection", blockpattern$patternhelper.getForwards());
			}

			setField(Entity.class, entityIn, "inPortal", true);

		}

		if (entityIn instanceof EntityPlayerMP) {
			EntityPlayerMP player = (EntityPlayerMP) entityIn;
			if (player.timeUntilPortal > 0) {
				player.timeUntilPortal = 10;
			} else if (player.dimension == 0) {
				player.timeUntilPortal = 10;
				MinecraftServer server = player.mcServer;
				server.getPlayerList().transferPlayerToDimension(player, CheeseDimension.DIMENSION_ID,
						new CheeseTeleporter(server.worldServerForDimension(CheeseDimension.DIMENSION_ID)));
			} else if (player.dimension == CheeseDimension.DIMENSION_ID) {
				player.timeUntilPortal = 10;
				MinecraftServer server = player.mcServer;
				server.getPlayerList().transferPlayerToDimension(player, 0,
						new CheeseTeleporter(server.worldServerForDimension(0)));
			}
		}
	}
}

public Object getField(Class clazz, Object obj, String fieldstr) {
	try {
		Field field = clazz.getDeclaredField(fieldstr);
		field.setAccessible(true);
		return field.get(obj);
	} catch(Exception ex) {
		return null;
	}
}

public void setField(Class clazz, Object obj, String fieldstr, Object value) {
	try {
		Field field = clazz.getDeclaredField(fieldstr);
		field.setAccessible(true);
		field.set(obj, value);
	} catch(Exception ex) {
	}
}

public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
	return ItemStack.field_190927_a;
}

/**
 * Convert the given metadata into a BlockState for this Block
 */
public IBlockState getStateFromMeta(int meta) {
	return this.getDefaultState().withProperty(AXIS, (meta & 3) == 2 ? EnumFacing.Axis.Z : EnumFacing.Axis.X);
}

@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer() {
	return BlockRenderLayer.TRANSLUCENT;
}

@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
	if (rand.nextInt(100) == 0) {
		worldIn.playSound((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D,
				SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 0.5F, rand.nextFloat() * 0.4F + 0.8F,
				false);
	}

	for (int i = 0; i < 4; ++i) {
		double d0 = (double) ((float) pos.getX() + rand.nextFloat());
		double d1 = (double) ((float) pos.getY() + rand.nextFloat());
		double d2 = (double) ((float) pos.getZ() + rand.nextFloat());
		double d3 = ((double) rand.nextFloat() - 0.5D) * 0.5D;
		double d4 = ((double) rand.nextFloat() - 0.5D) * 0.5D;
		double d5 = ((double) rand.nextFloat() - 0.5D) * 0.5D;
		int j = rand.nextInt(2) * 2 - 1;

		if (worldIn.getBlockState(pos.west()).getBlock() != this
				&& worldIn.getBlockState(pos.east()).getBlock() != this) {
			d0 = (double) pos.getX() + 0.5D + 0.25D * (double) j;
			d3 = (double) (rand.nextFloat() * 2.0F * (float) j);
		} else {
			d2 = (double) pos.getZ() + 0.5D + 0.25D * (double) j;
			d5 = (double) (rand.nextFloat() * 2.0F * (float) j);
		}

		worldIn.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5, new int[0]);
	}
}

/**
 * Convert the BlockState into the correct metadata value
 */
public int getMetaFromState(IBlockState state) {
	return getMetaForAxis((EnumFacing.Axis) state.getValue(AXIS));
}

/**
 * Returns the blockstate with the given rotation from the passed
 * blockstate. If inapplicable, returns the passed blockstate.
 */
public IBlockState withRotation(IBlockState state, Rotation rot) {
	switch (rot) {
	case COUNTERCLOCKWISE_90:
	case CLOCKWISE_90:

		switch ((EnumFacing.Axis) state.getValue(AXIS)) {
		case X:
			return state.withProperty(AXIS, EnumFacing.Axis.Z);
		case Z:
			return state.withProperty(AXIS, EnumFacing.Axis.X);
		default:
			return state;
		}

	default:
		return state;
	}
}

protected BlockStateContainer createBlockState() {
	return new BlockStateContainer(this, new IProperty[] { AXIS });
}

public static BlockPattern.PatternHelper createPatternHelper(World worldIn, BlockPos p_181089_2_) {
	EnumFacing.Axis enumfacing$axis = EnumFacing.Axis.Z;
	CheesePortal.Size blockportal$size = new CheesePortal.Size(worldIn, p_181089_2_, EnumFacing.Axis.X);
	LoadingCache<BlockPos, BlockWorldState> loadingcache = BlockPattern.createLoadingCache(worldIn, true);

	if (!blockportal$size.isValid()) {
		enumfacing$axis = EnumFacing.Axis.X;
		blockportal$size = new CheesePortal.Size(worldIn, p_181089_2_, EnumFacing.Axis.Z);
	}

	if (!blockportal$size.isValid()) {
		return new BlockPattern.PatternHelper(p_181089_2_, EnumFacing.NORTH, EnumFacing.UP, loadingcache, 1, 1, 1);
	} else {
		int[] aint = new int[EnumFacing.AxisDirection.values().length];
		EnumFacing enumfacing = blockportal$size.rightDir.rotateYCCW();
		BlockPos blockpos = blockportal$size.bottomLeft.up(blockportal$size.getHeight() - 1);

		for (EnumFacing.AxisDirection enumfacing$axisdirection : EnumFacing.AxisDirection.values()) {
			BlockPattern.PatternHelper blockpattern$patternhelper = new BlockPattern.PatternHelper(
					enumfacing.getAxisDirection() == enumfacing$axisdirection ? blockpos
							: blockpos.offset(blockportal$size.rightDir, blockportal$size.getWidth() - 1),
					EnumFacing.getFacingFromAxis(enumfacing$axisdirection, enumfacing$axis), EnumFacing.UP,
					loadingcache, blockportal$size.getWidth(), blockportal$size.getHeight(), 1);

			for (int i = 0; i < blockportal$size.getWidth(); ++i) {
				for (int j = 0; j < blockportal$size.getHeight(); ++j) {
					BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(i, j, 1);

					if (blockworldstate.getBlockState() != null
							&& blockworldstate.getBlockState().getMaterial() != Material.AIR) {
						++aint[enumfacing$axisdirection.ordinal()];
					}
				}
			}
		}

		EnumFacing.AxisDirection enumfacing$axisdirection1 = EnumFacing.AxisDirection.POSITIVE;

		for (EnumFacing.AxisDirection enumfacing$axisdirection2 : EnumFacing.AxisDirection.values()) {
			if (aint[enumfacing$axisdirection2.ordinal()] < aint[enumfacing$axisdirection1.ordinal()]) {
				enumfacing$axisdirection1 = enumfacing$axisdirection2;
			}
		}

		return new BlockPattern.PatternHelper(
				enumfacing.getAxisDirection() == enumfacing$axisdirection1 ? blockpos
						: blockpos.offset(blockportal$size.rightDir, blockportal$size.getWidth() - 1),
				EnumFacing.getFacingFromAxis(enumfacing$axisdirection1, enumfacing$axis), EnumFacing.UP,
				loadingcache, blockportal$size.getWidth(), blockportal$size.getHeight(), 1);
	}
}

public static class Size {
	private final World world;
	private final EnumFacing.Axis axis;
	private final EnumFacing rightDir;
	private final EnumFacing leftDir;
	private int portalBlockCount;
	private BlockPos bottomLeft;
	private int height;
	private int width;

	public Size(World worldIn, BlockPos p_i45694_2_, EnumFacing.Axis p_i45694_3_) {
		this.world = worldIn;
		this.axis = p_i45694_3_;

		if (p_i45694_3_ == EnumFacing.Axis.X) {
			this.leftDir = EnumFacing.EAST;
			this.rightDir = EnumFacing.WEST;
		} else {
			this.leftDir = EnumFacing.NORTH;
			this.rightDir = EnumFacing.SOUTH;
		}

		for (BlockPos blockpos = p_i45694_2_; p_i45694_2_.getY() > blockpos.getY() - 21 && p_i45694_2_.getY() > 0
				&& this.isEmptyBlock(
						worldIn.getBlockState(p_i45694_2_.down()).getBlock()); p_i45694_2_ = p_i45694_2_.down()) {
			;
		}

		int i = this.getDistanceUntilEdge(p_i45694_2_, this.leftDir) - 1;

		if (i >= 0) {
			this.bottomLeft = p_i45694_2_.offset(this.leftDir, i);
			this.width = this.getDistanceUntilEdge(this.bottomLeft, this.rightDir);

			if (this.width < 2 || this.width > 21) {
				this.bottomLeft = null;
				this.width = 0;
			}
		}

		if (this.bottomLeft != null) {
			this.height = this.calculatePortalHeight();
		}
	}

	protected int getDistanceUntilEdge(BlockPos p_180120_1_, EnumFacing p_180120_2_) {
		int i;

		for (i = 0; i < 22; ++i) {
			BlockPos blockpos = p_180120_1_.offset(p_180120_2_, i);

			if (!this.isEmptyBlock(this.world.getBlockState(blockpos).getBlock())
					|| this.world.getBlockState(blockpos.down()).getBlock() != CheeseBlocks.CHEESE_BLOCK) {
				break;
			}
		}

		Block block = this.world.getBlockState(p_180120_1_.offset(p_180120_2_, i)).getBlock();
		return block == CheeseBlocks.CHEESE_BLOCK ? i : 0;
	}

	public int getHeight() {
		return this.height;
	}

	public int getWidth() {
		return this.width;
	}

	protected int calculatePortalHeight() {
		label24:

		for (this.height = 0; this.height < 21; ++this.height) {
			for (int i = 0; i < this.width; ++i) {
				BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i).up(this.height);
				Block block = this.world.getBlockState(blockpos).getBlock();

				if (!this.isEmptyBlock(block)) {
					break label24;
				}

				if (block == CheeseBlocks.CHEESE_PORTAL) {
					++this.portalBlockCount;
				}

				if (i == 0) {
					block = this.world.getBlockState(blockpos.offset(this.leftDir)).getBlock();

					if (block != CheeseBlocks.CHEESE_BLOCK) {
						break label24;
					}
				} else if (i == this.width - 1) {
					block = this.world.getBlockState(blockpos.offset(this.rightDir)).getBlock();

					if (block != CheeseBlocks.CHEESE_BLOCK) {
						break label24;
					}
				}
			}
		}

		for (int j = 0; j < this.width; ++j) {
			if (this.world.getBlockState(this.bottomLeft.offset(this.rightDir, j).up(this.height))
					.getBlock() != CheeseBlocks.CHEESE_BLOCK) {
				this.height = 0;
				break;
			}
		}

		if (this.height <= 21 && this.height >= 3) {
			return this.height;
		} else {
			this.bottomLeft = null;
			this.width = 0;
			this.height = 0;
			return 0;
		}
	}

	protected boolean isEmptyBlock(Block blockIn) {
		return blockIn.getMaterial(blockIn.getDefaultState()) == Material.AIR || blockIn == CheeseBlocks.CHEESE_FIRE
				|| blockIn == CheeseBlocks.CHEESE_PORTAL;
	}

	public boolean isValid() {
		return this.bottomLeft != null && this.width >= 2 && this.width <= 21 && this.height >= 3
				&& this.height <= 21;
	}

	public void placePortalBlocks() {
		for (int i = 0; i < this.width; ++i) {
			BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i);

			for (int j = 0; j < this.height; ++j) {
				this.world.setBlockState(blockpos.up(j),
						CheeseBlocks.CHEESE_PORTAL.getDefaultState().withProperty(CheesePortal.AXIS, this.axis), 2);
			}
		}
	}
}
}

The crash

[16:00:16] [server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: net.minecraft.util.ReportedException: Colliding entity with block
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_77]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_77]
at net.minecraft.util.Util.runTask(Util.java:27) [util.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
Caused by: net.minecraft.util.ReportedException: Colliding entity with block
at net.minecraft.entity.Entity.moveEntity(Entity.java:999) ~[Entity.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:501) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.CPacketPlayer.processPacket(CPacketPlayer.java:36) ~[CPacketPlayer.class:?]
at net.minecraft.network.play.client.CPacketPlayer$PositionRotation.processPacket(CPacketPlayer.java:125) ~[CPacketPlayer$PositionRotation.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_77]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_77]
at net.minecraft.util.Util.runTask(Util.java:26) ~[util.class:?]
... 5 more
Caused by: java.lang.NullPointerException
at com.Kokkie.cheesemod.world.dimension.CheeseTeleporter.placeInExistingPortal(CheeseTeleporter.java:131) ~[CheeseTeleporter.class:?]
at com.Kokkie.cheesemod.world.dimension.CheeseTeleporter.placeInPortal(CheeseTeleporter.java:38) ~[CheeseTeleporter.class:?]
at net.minecraft.server.management.PlayerList.transferEntityToWorld(PlayerList.java:732) ~[PlayerList.class:?]
at net.minecraft.server.management.PlayerList.transferPlayerToDimension(PlayerList.java:639) ~[PlayerList.class:?]
at com.Kokkie.cheesemod.blocks.CheesePortal.onEntityCollidedWithBlock(CheesePortal.java:239) ~[CheesePortal.class:?]
at net.minecraft.entity.Entity.doBlockCollisions(Entity.java:1074) ~[Entity.class:?]
at net.minecraft.entity.Entity.moveEntity(Entity.java:992) ~[Entity.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:501) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.CPacketPlayer.processPacket(CPacketPlayer.java:36) ~[CPacketPlayer.class:?]
at net.minecraft.network.play.client.CPacketPlayer$PositionRotation.processPacket(CPacketPlayer.java:125) ~[CPacketPlayer$PositionRotation.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_77]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_77]
at net.minecraft.util.Util.runTask(Util.java:26) ~[util.class:?]
... 5 more

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Link to comment
Share on other sites

Can anyone please help?

First off dont bump so often, and second off what is line 131 of CheeseTeleporter.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Caused by: java.lang.NullPointerException
at com.Kokkie.cheesemod.world.dimension.CheeseTeleporter.placeInExistingPortal(CheeseTeleporter.java:131) ~[CheeseTeleporter.class:?]

Well, there's something

null

on that line which is causing your issue. Use your debugger to figure out what.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

if(null) { do one thing } else { do another}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.