• 0

    posted a message on Portal teleporting player inside blocks.

    I made a custom portal for my dimension for my Minecraft mod. Just wondering how I can fix this. This is my code for the teleportation:



    package blazesword2008.randomcraft.world;
    
    import blazesword2008.randomcraft.init.BlockInit;
    import blazesword2008.randomcraft.objects.blocks.BlockEnderthPortal;
    import it.unimi.dsi.fastutil.objects.ObjectIterator;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.block.state.pattern.BlockPattern.PatternHelper;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraft.init.Blocks;
    import net.minecraft.util.EnumFacing.Axis;
    import net.minecraft.util.EnumFacing.AxisDirection;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.math.BlockPos.MutableBlockPos;
    import net.minecraft.util.math.ChunkPos;
    import net.minecraft.util.math.MathHelper;
    import net.minecraft.world.Teleporter;
    import net.minecraft.world.World;
    import net.minecraft.world.WorldServer;
    
    public class DimensionTeleporter extends Teleporter
    {
    	public DimensionTeleporter(WorldServer world) {
    		super(world);
    	}
    	
    	@Override
    	public void placeInPortal(Entity entity, float rotationYaw) {
    		if(this.world.provider.getDimensionType().getId() != 1) {
    			if(!this.placeInExistingPortal(entity, rotationYaw)) {
    				this.makePortal(entity);
    				this.placeInExistingPortal(entity, rotationYaw);
    			}
    		} else {
    			int i = MathHelper.floor(entity.posX),
    				j = MathHelper.floor(entity.posY) - 1,
    				k = MathHelper.floor(entity.posZ),
    				l = 1,
    				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,
    							j2 = j + l1,
    							k2 = k - j1;
    						boolean flag = l1 < 0;
    						this.world.setBlockState(new BlockPos(i2, j2, k2), flag ? BlockInit.RHODOCHROSITE_BLOCK.getDefaultState() : Blocks.AIR.getDefaultState());
    					}
    				}
    			}
    			
    			entity.setLocationAndAngles((double)i, (double)j, (double)k, entity.rotationYaw, 0.0F);
    			entity.motionX = entity.motionY = entity.motionZ = 0.0D;
    		}
    	}
    	
    	@Override
    	public boolean placeInExistingPortal(Entity entity, float rotationYaw) {
    		int i = 128,
    			j = MathHelper.floor(entity.posX),
    			k = MathHelper.floor(entity.posZ);
    		double d0 = -1.0D;
    		boolean flag = true;
    		BlockPos pos = BlockPos.ORIGIN;
    		long l = ChunkPos.asLong(j, k);
    		
    		if(this.destinationCoordinateCache.containsKey(l)) {
    			Teleporter.PortalPosition position = (Teleporter.PortalPosition)this.destinationCoordinateCache.get(l);
    			d0 = 0.0D;
    			pos = position;
    			position.lastUpdateTime = this.world.getTotalWorldTime();
    			flag = false;
    		} else {
    			BlockPos pos3 = new BlockPos(entity);
    			
    			for(int i1 = -128; i1 <= 128; ++i1) {
    				
    				BlockPos pos2;
    				
    				for(int j1 = -128; j1 <= 128; ++j1) {
    					
    					for(BlockPos pos1 = pos3.add(i1, this.world.getActualHeight() - 1 - pos3.getY(), j1); pos1.getY() >= 0; pos1 = pos2) {
    						pos2 = pos1.down();
    						
    						if(this.world.getBlockState(pos1).getBlock() == BlockInit.PORTAL) {
    							for(pos2 = pos1.down(); this.world.getBlockState(pos2).getBlock() == BlockInit.PORTAL; pos2 = pos2.down()) pos1 = pos2;
    							
    							double d1 = pos1.distanceSq(pos3);
    							
    							if(d0 < 0.0D || d1 < d0) {
    								d0 = d1;
    								pos = pos1;
    							}
    						}
    					}
    				}
    			}
    		}
    		
    		if(d0 >= 0.0D) {
    			if(flag) this.destinationCoordinateCache.put(l, new Teleporter.PortalPosition(pos, this.world.getTotalWorldTime()));
    			
    			double d5 = (double) pos.getX() + 0.5D,
    				   d7 = (double) pos.getZ() + 0.5D;
    			PatternHelper helper = BlockInit.PORTAL.createPatternHelper(world, pos);
    			boolean flag1 = helper.getForwards().rotateY().getAxisDirection() == AxisDirection.NEGATIVE;
    			double d2 = helper.getForwards().getAxis() == Axis.X ? (double) helper.getFrontTopLeft().getZ() : (double) helper.getFrontTopLeft().getX(),
    				   d6 = (double) (helper.getFrontTopLeft().getY() + 1) - entity.getLastPortalVec().y * (double) helper.getHeight();
    			
    			if(flag1) ++d2;
    			
    			if(helper.getForwards().getAxis() == Axis.X) d7 = d2 + (1.0D - entity.getLastPortalVec().x) * (double) helper.getWidth() * (double) helper.getForwards().rotateY().getAxisDirection().getOffset();
    			else d5 = d2 + (1.0D - entity.getLastPortalVec().x) * (double) helper.getWidth() * (double) helper.getForwards().rotateY().getAxisDirection().getOffset();
    			
    			float f = 0.0F, f1 = 0.0F, f2 = 0.0F, f3 = 0.0F;
    			
    			if(helper.getForwards().getOpposite() == entity.getTeleportDirection()) f = f1 = 1.0F;
    			else if(helper.getForwards().getOpposite() == entity.getTeleportDirection().getOpposite()) f = f1 = -1.0F;
    			else if(helper.getForwards().getOpposite() == entity.getTeleportDirection().rotateY()) {f2 = 1.0F; f3 = -1.0F;}
    			else {f2 = -1.0F; f3 = 1.0F;}
    			
    			double d3 = entity.motionX,
    				   d4 = entity.motionZ;
    			entity.motionX = d3 *(double)f + d4 * (double)f3;
    			entity.motionX = d3 *(double)f2 + d4 * (double)f1;
    			entity.rotationYaw = rotationYaw - (float)(entity.getTeleportDirection().getOpposite().getHorizontalIndex() * 90) + (float)(helper.getForwards().getHorizontalIndex() * 90);
    			
    			if(entity instanceof EntityPlayerMP) ((EntityPlayerMP) entity).connection.setPlayerLocation(d5, d6, d7, entity.rotationYaw, entity.rotationPitch);
    			else entity.setLocationAndAngles(d5, d6, d7, entity.rotationYaw, entity.rotationPitch);
    			
    			return true;
    		}
    		return false;
    	}
    	
    	@Override
    	public boolean makePortal(Entity entity) {
    		int i = 16;
    		double d0 = -1.0D;
    		int j = MathHelper.floor(entity.posX),
    			k = MathHelper.floor(entity.posY),
    			l = MathHelper.floor(entity.posZ),
    			i1 = j,
    			j1 = k,
    			k1 = l,
    			l1 = 0,
    			i2 = this.random.nextInt(4);
    		MutableBlockPos pos = new MutableBlockPos();
    		
    		for(int j2 = j - 16; j2 <= j + 16; ++j2) {
    			double d1 = (double) j2 +0.5D - entity.posX;
    			
    			for(int l2 = l - 16; l2 <= l + 16; ++l2) {
    				double d2 = (double) l2 + 0.5D - entity.posZ;
    				label293:
    				
    				for(int j3 = this.world.getActualHeight() - 1; j3 >= 0; --j3) {
    					if(this.world.isAirBlock(pos.setPos(j2, j3, l2))) {
    						while(j3 > 0 && this.world.isAirBlock(pos.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 < 3; ++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;
    										pos.setPos(i5, j5, k5);
    										
    										if(l4 < 0 && !this.world.getBlockState(pos).getMaterial().isSolid() || l4 >= 0 && !this.world.isAirBlock(pos)) continue label293;
    									}
    								}
    							}
    							
    							double d5 = (double)j3 + 0.5D - entity.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 - entity.posX;
    
    				for(int j6 = l - 16; j6 <= l + 16; ++j6) {
    					double d4 = (double)j6 + 0.5D - entity.posZ;
    					label231:
    
    						for(int i7 = this.world.getActualHeight() - 1; i7 >= 0; --i7) {
    							if(this.world.isAirBlock(pos.setPos(l5, i7, j6))) {
    								while(i7 > 0 && this.world.isAirBlock(pos.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;
    											pos.setPos(j12, i13, j13);
    
    											if(j11 < 0 && !this.world.getBlockState(pos).getMaterial().isSolid() || j11 >= 0 && !this.world.isAirBlock(pos)) continue label231;
    										}
    									}
    
    									double d6 = (double) i7 + 0.5D - entity.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,
    				k2 = j1,
    				k6 = k1,
    				l6 = l1 % 2,
    				i3 = 1 - l6;
    
    		if(l1 % 4 >= 2) {
    			l6 = -l6;
    			i3 = -i3;
    		}
    
    		if(d0 < 0.0D) {
    			j1 = MathHelper.clamp(j1, 70, this.world.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.world.setBlockState(new BlockPos(k9, k10, k11), flag ? BlockInit.RHODOCHROSITE_BLOCK.getDefaultState() : Blocks.AIR.getDefaultState());
    					}
    				}
    			}
    		}
    
    		IBlockState state = BlockInit.PORTAL.getDefaultState().withProperty(BlockEnderthPortal.AXIS, l6 == 0 ? Axis.Z : 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.world.setBlockState(new BlockPos(l10, l11, k12), flag1 ? BlockInit.RHODOCHROSITE_BLOCK.getDefaultState() : state, 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.world.notifyNeighborsOfStateChange(blockpos, this.world.getBlockState(blockpos).getBlock(), false);
    				}
    			}
    		}
    		return true;
    	}
    	
    	@Override
    	public void removeStalePortalLocations(long worldTime) {
    		if(worldTime % 100L == 0L) {
    			long i = worldTime - 300L;
    			ObjectIterator<Teleporter.PortalPosition> iterator = this.destinationCoordinateCache.values().iterator();
    			
    			while(iterator.hasNext()) {
    				Teleporter.PortalPosition position = (Teleporter.PortalPosition)iterator.next();
    				
    				if(position == null || position.lastUpdateTime < i) iterator.remove();
    			}
    		}
    	}
    	
    	@Override
        public void placeEntity(World world, Entity entity, float yaw)
        {
            if (entity instanceof EntityPlayerMP)
                placeInPortal(entity, yaw);
            else
                placeInExistingPortal(entity, yaw);
        }
    }

    Anyways, thank you! B)

    Posted in: Modification Development
  • 1

    posted a message on Trying to decide which version to make my mod for (Newbie)

    Quite honestly, modding on 1.15.2 is good since it will like you get to know the new updated forge features since 1.15.2 is way more different then modding on 1.12.2. However, if you want to be on a version which most mods are on right now, I'd suggest 1.12.2. I see no reason why you would need a mod for something like 1.7.3. (unless you want your mod to be compatible with older mods, then I would suggest release 1.7.10)


    anyways. that's my recommendations.

    Posted in: Modification Development
  • 0

    posted a message on How can I organize my custom creative tab?

    My creative tab is a mess with items all over the place. Can someone tell me ways I can organize my items and blocks inside my creative tab?


    Thanks! B) :bookflip: by MineWarCrafter

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED, THANKS!] How do I spawn ore in my own custom dimension?

    YOU LEGEND! THANK YOU SO MUCH! :D

    YAYAYAYYAYAYAYAYAY

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED, THANKS!] How do I spawn ore in my own custom dimension?

    Thank you so much for responding. I'll try generating the ore with a size of 4.


    For the if statement, wherein the runGenerator function do you want me to put it?


    Thanks! :D

    Posted in: Modification Development
  • 0

    posted a message on Enchantment help

    you can learn how to make custom enchantments here:

    Posted in: Modification Development
  • 0

    posted a message on I'm new to modding - how do I affect the frequency of a biome and force a structure on it?

    Um, I'm not too sure how to force a certain vanilla structure on your custom biome. I don't think that's possible, but coming from a guy without experience with that sort of thing, I'm not certain. If you want to maybe make your own custom structures and make them spawn inside your biome, I recommend this video:


    :)

    Posted in: Modification Development
  • 0

    posted a message on Newbie modder question

    The .project file must've been deleted or corrupted, might have to start over.

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED, THANKS!] How do I spawn ore in my own custom dimension?

    That didn't work. Tell me what I did wrong. (My dimension id is 2)


    package blazesword2008.randomcraft.world;
    
    import java.util.Random;
    
    import blazesword2008.randomcraft.init.BlockInit;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.block.state.pattern.BlockMatcher;
    import net.minecraft.init.Blocks;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.world.World;
    import net.minecraft.world.chunk.IChunkProvider;
    import net.minecraft.world.gen.IChunkGenerator;
    import net.minecraft.world.gen.feature.WorldGenMinable;
    import net.minecraft.world.gen.feature.WorldGenerator;
    import net.minecraftforge.fml.common.IWorldGenerator;
    
    public class WorldGenCustomOres implements IWorldGenerator
    {
    	private WorldGenerator ore_copper, ruby_ore, endertainium_ore, enderthirate_ore;
    	
    	public WorldGenCustomOres()
    	{
    		ore_copper = new WorldGenMinable(BlockInit.ORE_COPPER.getDefaultState(), 7, BlockMatcher.forBlock(Blocks.STONE));
    		ruby_ore = new WorldGenMinable(BlockInit.RUBY_ORE.getDefaultState(), 6, BlockMatcher.forBlock(Blocks.STONE));
    		endertainium_ore = new WorldGenMinable(BlockInit.ENDERTAINIUM_ORE.getDefaultState(), 3, BlockMatcher.forBlock(Blocks.END_STONE));
    		enderthirate_ore = new WorldGenMinable(BlockInit.ENDERTHIRATE_ORE.getDefaultState(), 2, BlockMatcher.forBlock(Blocks.STONE));
    	}
    	
    	@Override
    	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
    	{
    		switch(world.provider.getDimension())
    		{
    		case 0:
    			
    			runGenerator(ruby_ore, world, random, chunkX, chunkZ, 20, 7, 21);
    			runGenerator(ore_copper, world, random, chunkX, chunkZ, 50, 25, 56);
    			
    			break;
    			
    		case 1:
    			
    			runGenerator(endertainium_ore, world, random, chunkX, chunkZ, 50, 6 , 34);
    			
    			break;
    			
    		case 2:
    			
    			runGenerator(enderthirate_ore, world, random, chunkX, chunkZ, 15, 4, 16);
    			
    			break;
    		}
    	}
    	
    	
    	
    	private void runGenerator(WorldGenerator gen, World world, Random rand, int chunkX, int chunkZ, int chance, int minHeight, int maxHeight)
    	{
    		if(minHeight > maxHeight || minHeight < 0 || maxHeight > 256) throw new IllegalArgumentException("Ore generated out of bounds.");
    		
    		int heightDiff = maxHeight - minHeight +1;
    		for(int i = 0; i < chance; i++)
    		{
    			int x = chunkX * 16 + rand.nextInt(16);
    			int y = minHeight + rand.nextInt(heightDiff);
    			int z = chunkZ * 16 + rand.nextInt(16);
    			
    			gen.generate(world, rand, new BlockPos(x,y,z));
    		}
    	}
    	
    }
    Posted in: Modification Development
  • 0

    posted a message on [SOLVED, THANKS!] How do I spawn ore in my own custom dimension?

    can you give me a code a can use to do this?

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED, THANKS!] How do I spawn ore in my own custom dimension?

    I've recently created my own custom dimension.

    Wondering if someone can help me with ore generation so that ore will spawn in the custom dimension.


    thx :)

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED] How can I create a custom dimension with its own custom portal?

    Hey, I'm working on my mod Randomcraft and I'm wondering how I can make my own custom dimension with its own portal.


    I've tried looking for tutorials on the internet but I can't find any.


    Any help?

    Posted in: Modification Development
  • 0

    posted a message on Can someone help me choose mods for PC minecraft? (:D

    Okay, thanks! I have 4GB of ram on my PC, that's why I use 1.7.10 because its the version that has the most mods and that doesn't lag when I play it.

    Plus, there were over 60 mods on there. And I think it was crashing because of Ic2. I did put them in all at once so there could be some conflict. I did make sure they were for 1.7.10 and I knew I had all the cores for them. Thanks for the help!

    Posted in: Mods Discussion
  • 0

    posted a message on Can someone help me choose mods for PC minecraft? (:D

    I tryed downloading mods that are from the videos and my game crashed. D:

    Posted in: Mods Discussion
  • 0

    posted a message on 1.7.10 Forge Mod Menu

    You can either the custom menu mod for forge or you can use a mod called voxel menu which is a mod that adds in a very nice menu! The Only bad thing with the custom menu mod is that you have to customize it yourself in the JSON file which is in the jar file and the other thing about with voxel menu is that it's only for liteloader. But you can get a thing that has liteloader and forge in it. So you can go look at those two mods and tell me what you think!


    P.S (I'm not sure if voxel menu is a thing or not but I think there is)

    Posted in: Mods Discussion
  • To post a comment, please or register a new account.