Jump to content

[1.9] Teleporter not working.


KingOfMiners

Recommended Posts

I made a dimension and updated it to 1.9 in trying to create a different type of portal so with that comes the Teleporter, but when I try to travel to the dimension it doesn't spawn the portal and It spawns you in the ground. This is my teleporter class:

package com.moreoresmod.main.dimensions.Otherlyworld;

import com.google.common.collect.Lists;
import com.moreoresmod.main.init.MoreOresModBlocks;

import java.util.Iterator;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockPortal;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockPattern;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.LongHashMap;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.Teleporter;
import net.minecraft.world.WorldServer;

public class TeleporterOtherlyworld extends Teleporter{
    private final WorldServer worldServerInstance;
    /** A private Random() function in Teleporter */
    private final Random random;
    private final LongHashMap<TeleporterOtherlyworld.PortalPosition> destinationCoordinateCache = new LongHashMap();
    private final List<Long> destinationCoordinateKeys = Lists.<Long>newArrayList();

    public TeleporterOtherlyworld(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);
            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.setBlockState(new BlockPos(i, j, k), MoreOresModBlocks.paridox_portal.getDefaultState());
                    }

                }

            }

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

    public boolean placeInExistingPortal(Entity entityIn, float rotationYaw)
    {
    	short short1 = 128;
        double d3 = -1D;
        int i = 0;
        int j = 0;
        int k = 0;
        int l = MathHelper.floor_double(entityIn.posX);
        int i1 = MathHelper.floor_double(entityIn.posZ);
        long j1 = ChunkCoordIntPair.chunkXZ2Int(l, i1);
        boolean flag = true;
        if(destinationCoordinateCache.containsItem(j1))
        {
            PortalPosition portalposition = (PortalPosition)destinationCoordinateCache.getValueByKey(j1);
            d3 = 0.0D;
            i = portalposition.getX();
            j = portalposition.getY();
            k = portalposition.getZ();
            portalposition.lastUpdateTime = worldServerInstance.getTotalWorldTime();
            flag = false;
        } else
        {
            for(int l3 = l - short1; l3 <= l + short1; l3++)
            {
                double d4 = ((double)l3 + 0.5D) - entityIn.posX;
                for(int l1 = i1 - short1; l1 <= i1 + short1; l1++)
                {
                    double d5 = ((double)l1 + 0.5D) - entityIn.posZ;
                    for(int i2 = worldServerInstance.getActualHeight() - 1; i2 >= 0; i2--)
                    {
                        if(this.worldServerInstance.getBlockState(new BlockPos(l3, i2, l1)) != MoreOresModBlocks.paridox_portal)
                            continue;
                        for(; this.worldServerInstance.getBlockState(new BlockPos(l3, i2 - 1, l1)) == MoreOresModBlocks.paridox_portal; i2--);
                        double d7 = ((double)i2 + 0.5D) - entityIn.posY;
                        double d8 = d4 * d4 + d7 * d7 + d5 * d5;
                        if(d3 < 0.0D || d8 < d3)
                        {
                            d3 = d8;
                            i = l3;
                            j = i2;
                            k = l1;
                          
                        }
                    }

                }

            }
            System.out.println(d3);
        }
        if(d3 >= 0.0D)
        {
            if(flag)
            {
                destinationCoordinateCache.add(j1, new PortalPosition(new BlockPos(i, j, k), worldServerInstance.getTotalWorldTime()));
                destinationCoordinateKeys.add(Long.valueOf(j1));
            }
            double d11 = (double)i + 0.5D;
            double d6 = (double)j + 0.5D;
            double d7 = (double)k + 0.5D;
            int i4 = -1;
            if(this.worldServerInstance.getBlockState(new BlockPos(i - 1, j, k)) == MoreOresModBlocks.paridox_portal)
                i4 = 2;
            if(this.worldServerInstance.getBlockState(new BlockPos(i, j, k)) == MoreOresModBlocks.paridox_portal)
                i4 = 0;
            if(this.worldServerInstance.getBlockState(new BlockPos(i, j, k - 1)) == MoreOresModBlocks.paridox_portal)
                i4 = 3;
            if(this.worldServerInstance.getBlockState(new BlockPos(i, j, k + 1)) == MoreOresModBlocks.paridox_portal)
                i4 = 1;
            //int j2 = entityIn.func_82148_at();
            entityIn.motionX = entityIn.motionY = entityIn.motionZ = 0.0D;
            entityIn.setLocationAndAngles(d11, d6, d7, entityIn.rotationYaw, entityIn.rotationPitch);
            return true;
        } else
        {
            return false;
            
        }   
    }

    public boolean makePortal(Entity entityIn)
    {
    	byte b0 = 16;
        double d0 = -1D;
        int i = MathHelper.floor_double(entityIn.posX);
        int j = 25;
        int k = MathHelper.floor_double(entityIn.posZ);
        int l = i;
        int i1 = j;
        int j1 = k;
        int k1 = 0;
        int l1 = random.nextInt(4);
        int k2;
        for(int i2 = i - b0; i2 <= i + b0; i2++)
        {
            double d1 = ((double)i2 + 0.5D) - entityIn.posX;
            for(k2 = k - b0; k2 <= k + b0; k2++)
            {
                double d2 = ((double)k2 + 0.5D) - entityIn.posZ;
                for(int i3 = worldServerInstance.getActualHeight() - 1; i3 >= 0; i3--)
                {
                    if(!worldServerInstance.isAirBlock(new BlockPos(i2, i3, k2)))
                        continue;
                    for(; i3 > 0 && worldServerInstance.isAirBlock(new BlockPos(i2, i3 - 1, k2)); i3--);
                    label0:
                    	
                    for(int j3 = l1; j3 < l1 + 4; j3++)
                    {
                        int k3 = j3 % 2;
                        int l3 = 1 - k3;
                        if(j3 % 4 >= 2)
                        {
                            k3 = -k3;
                            l3 = -l3;
                        }
                        for(int i4 = 0; i4 < 3; i4++)
                        {
                            for(int j4 = 0; j4 < 4; j4++)
                            {
                                for(int k4 = -1; k4 < 4; k4++)
                                {
                                    int l4 = i2 + (j4 - 1) * k3 + i4 * l3;
                                    int i5 = i3 + k4;
                                    int j5 = (k2 + (j4 - 1) * l3) - i4 * k3;
                                    if(k4 < 0 && !this.worldServerInstance.getBlockState(new BlockPos(l4, i5, j5)).getMaterial().isSolid() || k4 >= 0 && !worldServerInstance.isAirBlock(new BlockPos(l4, i5, j5)))
                                        break label0;
                                }

                            }

                        }

                        double d4 = ((double)i3 + 0.5D) - entityIn.posY;
                        double d3 = d1 * d1 + d4 * d4 + d2 * d2;
                        if(d0 < 0.0D || d3 < d0)
                        {
                            d0 = d3;
                            l = i2;
                            i1 = i3;
                            j1 = k2;
                            k1 = j3 % 4;
                        }
                    }

                }

            }

        }

        if(d0 < 0.0D)
        {
            for(int i2 = i - b0; i2 <= i + b0; i2++)
            {
                double d1 = ((double)i2 + 0.5D) - entityIn.posX;
                for(k2 = k - b0; k2 <= k + b0; k2++)
                {
                    double d2 = ((double)k2 + 0.5D) - entityIn.posZ;
                    for(int i3 = worldServerInstance.getActualHeight() - 1; i3 >= 0; i3--)
                    {
                        if(!worldServerInstance.isAirBlock(new BlockPos(i2, i3, k2)))
                            continue;
                        for(; i3 > 0 && worldServerInstance.isAirBlock(new BlockPos(i2, i3 - 1, k2)); i3--);
                        label1:
                        for(int j3 = l1; j3 < l1 + 2; j3++)
                        {
                            int k3 = j3 % 2;
                            int l3 = 1 - k3;
                            for(int i4 = 0; i4 < 4; i4++)
                            {
                                for(int j4 = -1; j4 < 4; j4++)
                                {
                                    int k4 = i2 + (i4 - 1) * k3;
                                    int l4 = i3 + j4;
                                    int i5 = k2 + (i4 - 1) * l3;
                                    if(j4 < 0 && this.worldServerInstance.getBlockState(new BlockPos(k4, l4, i5)).getMaterial().isSolid() || j4 >= 0 && !worldServerInstance.isAirBlock(new BlockPos(k4, l4, i5)))
                                        break label1;
                                }

                            }

                            double d4 = ((double)i3 + 0.5D) - entityIn.posY;
                            double d3 = d1 * d1 + d4 * d4 + d2 * d2;
                            if(d0 < 0.0D || d3 < d0)
                            {
                                d0 = d3;
                                l = i2;
                                i1 = i3;
                                j1 = k2;
                                k1 = j3 % 2;
                            }
                        }

                    }

                }

            }

        }
        int k5 = l;
        int j2 = i1;
        k2 = j1;
        int l5 = k1 % 2;
        int l2 = 1 - l5;
        if(k1 % 4 >= 2)
        {
            l5 = -l5;
            l2 = -l2;
        }
        if(d0 < 0.0D)
        {
            if(i1 < 70)
                i1 = 70;
            if(i1 > worldServerInstance.getActualHeight() - 10)
                i1 = worldServerInstance.getActualHeight() - 10;
            j2 = i1;
            for(int i3 = -1; i3 <= 1; i3++)
            {
                for(int j3 = 1; j3 < 3; j3++)
                {
                    for(int k3 = -1; k3 < 3; k3++)
                    {
                        int l3 = k5 + (j3 - 1) * l5 + i3 * l2;
                        int i4 = j2 + k3;
                        int j4 = (k2 + (j3 - 1) * l2) - i3 * l5;
                        boolean flag = k3 < 0;
                        this.worldServerInstance.setBlockState(new BlockPos(i, j, k), MoreOresModBlocks.paridox_portal.getDefaultState());
                    }

                }

            }

            for(int i3 = 0; i3 < 4; i3++)
            {
                for(int j3 = 0; j3 < 4; j3++)
                {
                    for(int k3 = -1; k3 < 4; k3++)
                    {
                        int l3 = k5 + (j3 - 1) * l5;
                        int i4 = j2 + k3;
                        int j4 = k2 + (j3 - 1) * l2;
                        boolean flag = j3 == 0 || j3 == 3 || k3 == -1 || k3 == 3;
                        this.worldServerInstance.setBlockState(new BlockPos(i, j, k), MoreOresModBlocks.paridox_portal.getDefaultState());
                    }

                }

            }

        }
        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)
         {
             Iterator iterator = destinationCoordinateKeys.iterator();
             long j = worldTime - 600L;
             do
             {
                 if(!iterator.hasNext())
                     break;
                 Long olong = (Long)iterator.next();
                 PortalPosition portalposition = (PortalPosition)destinationCoordinateCache.getValueByKey(olong.longValue());
                 if(portalposition == null || portalposition.lastUpdateTime < j)
                 {
                     iterator.remove();
                     destinationCoordinateCache.remove(olong.longValue());
                 }
             } while(true);
         }
    }

    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;
        }
    }
}

Link to comment
Share on other sites

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

    • Hello, I was trying to play a MOD in my preferred language, but I see that only some items are translated, and I go to debug and I get this information (the only thing that is translated is the bestiary):   [14sep.2024 17:14:36.415] [Render thread/WARN] [net.minecraft.client.resources.language.ClientLanguage/]: Skipped language file: mowziesmobs:lang/es_es.json (com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected name at line 394 column 2 path $.config.mowziesmobs.ice_crystal_attack_multiplier) [14sep.2024 17:14:36.421] [Render thread/WARN] [net.minecraft.client.resources.language.ClientLanguage/]: Skipped language file: iceandfire:lang/es_es.json (com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1349 column 4 path $.iceandfire.sound.subtitle.dragonflute)   Is that the reason why everything is not translated? , and is there any way to fix it? Thanks
    • I got my model to render from the models renderToBuffer method. But still not quite what I want. I want to render the model from my renderer's render method. I feel that having access to the renderer and its methods will open some doors for me later down the line. //EntityRendererProvider.Context pContext = ; I want this //ToaPlayerRenderer render = new ToaPlayerRenderer(pContext, false); // if I can get the above line to work, having the methods from the renderer class would be incredibly helpful down the line RenderType rendertype = model.renderType(p.getSkinTextureLocation()); // this should be something like render.getTextureLocation() VertexConsumer vertexconsumer = buffer.getBuffer(rendertype); model.renderToBuffer(stack, vertexconsumer, paLights, 1, 1, 1, 1, 1); // I don't want the render to happen here since it doesn't use the renderer //model.render(p, 1f, pTicks, stack, buffer, paLights); I want to render the model using this It is certainly getting closer though. Probably. I am still worried that even if pContext is initialized this new instance of the renderer class will still hit me with the classic and all too familiar "can't use static method in non-static context"
    • Hello, I am learning how to create Multipart Entities and I tried creating a PartEntity based on the EnderDragonPart code. However, when I tested summoning the entity in the game, the PartEntity appeared at position x 0, y 0, z 0 within the game. I tried to make it follow the main entity, and after testing again, the part entity followed the main entity but seemed to teleport back to x 0, y 0, z 0 every tick (I'm just guessing). I don't know how to fix this can someone help me? My github https://github.com/SteveKK666/Forge-NewWorld-1.20.1/tree/master/src/main/java/net/kk/newworldmod/entity/custom Illustration  https://drive.google.com/file/d/157SPvyQCE8GcsRXyQQkD4Dyhalz6LjBn/view?usp=drive_link Sorry for my English; I’m not very good at it. 
    • its still crashing with the same message
  • Topics

×
×
  • Create New...

Important Information

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