Jump to content

Recommended Posts

Posted

Yeah its me again, sorry if im getting a bit annoying but i didnt find anything useful on this. When i eneter m dimension the portal structure generates normally, except in world where FROM i eneterd it, no where TO i eetered, like i enter moon dimension but portal spawns at overworld.

My code:

TeleporterMoon:

package skyinf;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.util.Direction;
import net.minecraft.util.LongHashMap;
import net.minecraft.util.MathHelper;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.PortalPosition;
import net.minecraft.world.Teleporter;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;

public class TeleporterMoon extends Teleporter {
public Random rand = new Random();
World world;
Ship1 shipGen = new Ship1();
private final WorldServer worldServerInstance;

/** A private Random() function in Teleporter */
private final Random random;

/** Stores successful portal placement locations for rapid lookup. */
private final LongHashMap destinationCoordinateCache = new LongHashMap();

/**
 * A list of valid keys for the destinationCoordainteCache. These are based
 * on the X & Z of the players initial location.
 */
private final List destinationCoordinateKeys = new ArrayList();

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

/**
 * Place an entity in a nearby portal, creating one if necessary.
 */
@Override
public void placeInPortal(Entity par1Entity, double par2, double par4, double par6, float par8) {
	world = par1Entity.worldObj;
	if (this.worldServerInstance.provider.dimensionId != 1) {
		if (!this.placeInExistingPortal(par1Entity, par2, par4, par6, par8)) {
			this.makePortal(par1Entity);
			this.placeInExistingPortal(par1Entity, par2, par4, par6, par8);
		}
	} else {
		int i = MathHelper.floor_double(par1Entity.posX);
		int j = MathHelper.floor_double(par1Entity.posY) - 1;
		int k = MathHelper.floor_double(par1Entity.posZ);
		byte b0 = 1;
		byte b1 = 0;

		for (int l = -2; l <= 2; ++l) {
			for (int i1 = -2; i1 <= 2; ++i1) {
				for (int j1 = -1; j1 < 3; ++j1) {
					int k1 = i + i1 * b0 + l * b1;
					int l1 = j + j1;
					int i2 = k + i1 * b1 - l * b0;
					boolean flag = j1 < 0;
					this.worldServerInstance.setBlock(k1, l1, i2, flag ? Block.obsidian.blockID : 0);
				}
			}
		}

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

/**
 * Place an entity in a nearby portal which already exists.
 */
@Override
public boolean placeInExistingPortal(Entity par1Entity, double par2, double par4, double par6, float par8) {
	short short1 = 128;
	double d3 = -1.0D;
	int i = 0;
	int j = 0;
	int k = 0;
	int l = MathHelper.floor_double(par1Entity.posX);
	int i1 = MathHelper.floor_double(par1Entity.posZ);
	long j1 = ChunkCoordIntPair.chunkXZ2Int(l, i1);
	boolean flag = true;
	double d4;
	int k1;

	if (this.destinationCoordinateCache.containsItem(j1)) {
		PortalPosition portalposition = (PortalPosition) this.destinationCoordinateCache.getValueByKey(j1);
		d3 = 0.0D;
		i = portalposition.posX;
		j = portalposition.posY;
		k = portalposition.posZ;
		portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime();
		flag = false;
	} else {
		for (k1 = l - short1; k1 <= l + short1; ++k1) {
			double d5 = (double) k1 + 0.5D - par1Entity.posX;

			for (int l1 = i1 - short1; l1 <= i1 + short1; ++l1) {
				double d6 = (double) l1 + 0.5D - par1Entity.posZ;

				for (int i2 = this.worldServerInstance.getActualHeight() - 1; i2 >= 0; --i2) {
					if (this.worldServerInstance.getBlockId(k1, i2, l1) == Block.portal.blockID) {
						while (this.worldServerInstance.getBlockId(k1, i2 - 1, l1) == Block.portal.blockID) {
							--i2;
						}

						d4 = (double) i2 + 0.5D - par1Entity.posY;
						double d7 = d5 * d5 + d4 * d4 + d6 * d6;

						if (d3 < 0.0D || d7 < d3) {
							d3 = d7;
							i = k1;
							j = i2;
							k = l1;
						}
					}
				}
			}
		}
	}

	if (d3 >= 0.0D) {
		if (flag) {
			this.destinationCoordinateCache.add(j1, new PortalPosition(this, i, j, k, this.worldServerInstance.getTotalWorldTime()));
			this.destinationCoordinateKeys.add(Long.valueOf(j1));
		}

		double d8 = (double) i + 0.5D;
		double d9 = (double) j + 0.5D;
		d4 = (double) k + 0.5D;
		int j2 = -1;


		int k2 = par1Entity.getTeleportDirection();

		if (j2 > -1) {
			int l2 = Direction.rotateLeft[j2];
			int i3 = Direction.offsetX[j2];
			int j3 = Direction.offsetZ[j2];
			int k3 = Direction.offsetX[l2];
			int l3 = Direction.offsetZ[l2];
			boolean flag1 = !this.worldServerInstance.isAirBlock(i + i3 + k3, j, k + j3 + l3) || !this.worldServerInstance.isAirBlock(i + i3 + k3, j + 1, k + j3 + l3);
			boolean flag2 = !this.worldServerInstance.isAirBlock(i + i3, j, k + j3) || !this.worldServerInstance.isAirBlock(i + i3, j + 1, k + j3);

			if (flag1 && flag2) {
				j2 = Direction.rotateOpposite[j2];
				l2 = Direction.rotateOpposite[l2];
				i3 = Direction.offsetX[j2];
				j3 = Direction.offsetZ[j2];
				k3 = Direction.offsetX[l2];
				l3 = Direction.offsetZ[l2];
				k1 = i - k3;
				d8 -= (double) k3;
				int i4 = k - l3;
				d4 -= (double) l3;
				flag1 = !this.worldServerInstance.isAirBlock(k1 + i3 + k3, j, i4 + j3 + l3) || !this.worldServerInstance.isAirBlock(k1 + i3 + k3, j + 1, i4 + j3 + l3);
				flag2 = !this.worldServerInstance.isAirBlock(k1 + i3, j, i4 + j3) || !this.worldServerInstance.isAirBlock(k1 + i3, j + 1, i4 + j3);
			}

			float f1 = 0.5F;
			float f2 = 0.5F;

			if (!flag1 && flag2) {
				f1 = 1.0F;
			} else if (flag1 && !flag2) {
				f1 = 0.0F;
			} else if (flag1 && flag2) {
				f2 = 0.0F;
			}

			d8 += (double) ((float) k3 * f1 + f2 * (float) i3);
			d4 += (double) ((float) l3 * f1 + f2 * (float) j3);
			float f3 = 0.0F;
			float f4 = 0.0F;
			float f5 = 0.0F;
			float f6 = 0.0F;

			if (j2 == k2) {
				f3 = 1.0F;
				f4 = 1.0F;
			} else if (j2 == Direction.rotateOpposite[k2]) {
				f3 = -1.0F;
				f4 = -1.0F;
			} else if (j2 == Direction.rotateRight[k2]) {
				f5 = 1.0F;
				f6 = -1.0F;
			} else {
				f5 = -1.0F;
				f6 = 1.0F;
			}

			double d10 = par1Entity.motionX;
			double d11 = par1Entity.motionZ;
			par1Entity.motionX = d10 * (double) f3 + d11 * (double) f6;
			par1Entity.motionZ = d10 * (double) f5 + d11 * (double) f4;
			par1Entity.rotationYaw = par8 - (float) (k2 * 90) + (float) (j2 * 90);
		} else {
			par1Entity.motionX = par1Entity.motionY = par1Entity.motionZ = 0.0D;
		}

		par1Entity.setLocationAndAngles(d8, d9, d4, par1Entity.rotationYaw, par1Entity.rotationPitch);
		return true;
	} else {
		return false;
	}
}

@Override
public boolean makePortal(Entity par1Entity) {
	World world1 = par1Entity.worldObj;
	int i = MathHelper.floor_double(par1Entity.posX) - 3;
	int j = MathHelper.floor_double(par1Entity.posY) - 1;
	int k = MathHelper.floor_double(par1Entity.posZ) - 7;
	System.out.println("" + i +" "+ j +" "+ k);
	shipGen.generate(world1, rand, i, j, k);
	System.out.println("Generated!");
	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 par1) {
	if (par1 % 100L == 0L) {
		Iterator iterator = this.destinationCoordinateKeys.iterator();
		long j = par1 - 600L;

		while (iterator.hasNext()) {
			Long olong = (Long) iterator.next();
			PortalPosition portalposition = (PortalPosition) this.destinationCoordinateCache.getValueByKey(olong.longValue());

			if (portalposition == null || portalposition.lastUpdateTime < j) {
				iterator.remove();
				this.destinationCoordinateCache.remove(olong.longValue());
			}
		}
	}
}
}

BlockComputer:

package skyinf;

import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.EntitySnowman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class BlockComputer extends BlockDirectional {
@SideOnly(Side.CLIENT)
private Icon field_94475_c;

Ship1 shipgen = new Ship1();
Random rand = new Random();
public World world;

public int k1;
public int j1;
public int i1;

public void setShipGenCoords(int i, int j, int k) {

}

protected BlockComputer(int id, Material material) {
	super(id, material);
}

@SideOnly(Side.CLIENT)
/**
 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
 */
public Icon getIcon(int par1, int par2) {
	return par2 == 2 && par1 == 2 ? this.field_94475_c : (par2 == 3 && par1 == 5 ? this.field_94475_c : (par2 == 0 && par1 == 3 ? this.field_94475_c : (par2 == 1 && par1 == 4 ? this.field_94475_c : this.blockIcon)));
}

/**
 * Called when the block is placed in the world.
 */
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack) {
	int l = MathHelper.floor_double((double) (par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
	par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
}

@SideOnly(Side.CLIENT)
/**
 * When this method is called, your block should register all the icons it needs with the given IconRegister. This
 * is the only chance you get to register icons.
 */
public void registerIcons(IconRegister par1IconRegister) {
	this.field_94475_c = par1IconRegister.registerIcon(ModBase.modId + ":" + "siComputerFront");
	this.blockIcon = par1IconRegister.registerIcon(ModBase.modId + ":" + "siComputerSide");
}

boolean isActiveLiftoff = false;
boolean confirmation = false;
EntityPlayerMP[] passengerList = new EntityPlayerMP[10];
boolean countedDown = false;

@Override
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
	world = par1World;
	if (par5EntityPlayer instanceof EntityPlayerMP) {
		EntityPlayerMP thePlayer = (EntityPlayerMP) par5EntityPlayer;
		if (confirmation) {
			confirmation = false;
			isActiveLiftoff = true;
		}

		if (!isActiveLiftoff) {
			thePlayer.sendChatToPlayer("Confirm Lift-Off by right clicking again");
			confirmation = true;
		}

		if (isActiveLiftoff) {
			int x1 = x - 3;
			int y1 = 7 - 2;
			int z1 = z - 8;
			// shipgen.remove(par1World, rand, x1, y1, z1);

			if (par5EntityPlayer.dimension == ModBase.dimension) {

				thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, 0, new TeleporterMoon(thePlayer.mcServer.worldServerForDimension(0)));
			} else {
				thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, ModBase.dimension, new TeleporterMoon(thePlayer.mcServer.worldServerForDimension(20)));
			}
			int i = MathHelper.floor_double(thePlayer.posX);
			int j = MathHelper.floor_double(thePlayer.posY);
			int k = MathHelper.floor_double(thePlayer.posZ);
			k1 = k - 7;
			j1 = j - 1;
			i1 = i - 3;

			isActiveLiftoff = false;
			countedDown = false;

		}
	}
	return true;

}

public void generateShip() {
	shipgen.generate(world, rand, i1, j1, k1);
}

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Same issue - I have no idea
    • I am trying to develop a modpack for me and my friends to use on our server. Does anyone know how to develop a modpack for a server or could they help take a look at my modpack to potentially help at all?
    • un server de armas realista.  
  • Topics

×
×
  • Create New...

Important Information

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