Jump to content

[1.7.10] How to convert the code, which works in 1.8 to 1.7.10


nidico100

Recommended Posts

I get some errors with the code, i tried a lot to fix it, but it doesn't work.

	public void onFallenUpon (World worldIn, BlockPos pos, Entity entityIn, float fallDistance) 
{
	if (entityIn.isSneaking())
	{
		super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
	}
	else 
	{
		entityIn.fall(fallDistance, 0.0F);
	}
}

    public void onLanded(World worldIn, Entity entityIn)
    {
        if (entityIn.isSneaking())
        {
            super.onLanded(worldIn, entityIn);
        }
        else if (entityIn.motionY < 0.0D)
        {
            entityIn.motionY = -entityIn.motionY;
        }
    }

    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, Entity entityIn)
    {
        if (Math.abs(entityIn.motionY) < 0.1D && !entityIn.isSneaking())
        {
            double d0 = 0.4D + Math.abs(entityIn.motionY) * 0.2D;
            entityIn.motionX *= d0;
            entityIn.motionZ *= d0;
        }

        super.onEntityCollidedWithBlock(worldIn, pos, entityIn);
    }

BlockPos (just copied from 1.8, but fixed the errors)

 

package net.bplaced.nidico100.Downgrade;

 

 

import com.google.common.collect.AbstractIterator;

 

import java.util.Iterator;

 

import net.minecraft.entity.Entity;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.MathHelper;

import net.minecraft.util.Vec3;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class BlockPos extends Vec3i

{

    public static final BlockPos ORIGIN = new BlockPos(0, 0, 0);

    private static final int NUM_X_BITS = 1 + MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000));

    private static final int NUM_Z_BITS = NUM_X_BITS;

    private static final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS;

    private static final int Y_SHIFT = 0 + NUM_Z_BITS;

    private static final int X_SHIFT = Y_SHIFT + NUM_Y_BITS;

    private static final long X_MASK = (1L << NUM_X_BITS) - 1L;

    private static final long Y_MASK = (1L << NUM_Y_BITS) - 1L;

    private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L;

    private static final String __OBFID = "CL_00002334";

 

    public BlockPos(int x, int y, int z)

    {

        super(x, y, z);

    }

 

    public BlockPos(double x, double y, double z)

    {

        super(x, y, z);

    }

 

    public BlockPos(Entity source)

    {

        this(source.posX, source.posY, source.posZ);

    }

 

    public BlockPos(Vec3 source)

    {

        this(source.xCoord, source.yCoord, source.zCoord);

    }

 

    public BlockPos(Vec3i source)

    {

        this(source.getX(), source.getY(), source.getZ());

    }

 

    public BlockPos add(double x, double y, double z)

    {

        return new BlockPos((double)this.getX() + x, (double)this.getY() + y, (double)this.getZ() + z);

    }

 

    public BlockPos add(int x, int y, int z)

    {

        return new BlockPos(this.getX() + x, this.getY() + y, this.getZ() + z);

    }

 

    public BlockPos add(Vec3i vec)

    {

        return new BlockPos(this.getX() + vec.getX(), this.getY() + vec.getY(), this.getZ() + vec.getZ());

    }

 

    public BlockPos multiply(int factor)

    {

        return new BlockPos(this.getX() * factor, this.getY() * factor, this.getZ() * factor);

    }

 

    public BlockPos up()

    {

        return this.up(1);

    }

 

    @SideOnly(Side.CLIENT)

    public BlockPos subtract(Vec3i vec)

    {

        return new BlockPos(this.getX() - vec.getX(), this.getY() - vec.getY(), this.getZ() - vec.getZ());

    }

 

    public BlockPos up(int n)

    {

        return this.offset(EnumFacing.UP, n);

    }

 

    public BlockPos down()

    {

        return this.down(1);

    }

 

    public BlockPos down(int n)

    {

        return this.offset(EnumFacing.DOWN, n);

    }

 

    public BlockPos north()

    {

        return this.north(1);

    }

 

    public BlockPos north(int n)

    {

        return this.offset(EnumFacing.NORTH, n);

    }

 

    public BlockPos south()

    {

        return this.south(1);

    }

 

    public BlockPos south(int n)

    {

        return this.offset(EnumFacing.SOUTH, n);

    }

 

    public BlockPos west()

    {

        return this.west(1);

    }

 

    public BlockPos west(int n)

    {

        return this.offset(EnumFacing.WEST, n);

    }

 

    public BlockPos east()

    {

        return this.east(1);

    }

 

    public BlockPos east(int n)

    {

        return this.offset(EnumFacing.EAST, n);

    }

 

    public BlockPos offset(EnumFacing facing)

    {

        return this.offset(facing, 1);

    }

 

    public BlockPos offset(EnumFacing facing, int n)

    {

        return new BlockPos(this.getX() + facing.getFrontOffsetX() * n, this.getY() + facing.getFrontOffsetY() * n, this.getZ() + facing.getFrontOffsetZ() * n);

    }

 

    public BlockPos crossProductBP(Vec3i vec)

    {

        return new BlockPos(this.getY() * vec.getZ() - this.getZ() * vec.getY(), this.getZ() * vec.getX() - this.getX() * vec.getZ(), this.getX() * vec.getY() - this.getY() * vec.getX());

    }

 

    public long toLong()

    {

        return ((long)this.getX() & X_MASK) << X_SHIFT | ((long)this.getY() & Y_MASK) << Y_SHIFT | ((long)this.getZ() & Z_MASK) << 0;

    }

 

    public static BlockPos fromLong(long serialized)

    {

        int j = (int)(serialized << 64 - X_SHIFT - NUM_X_BITS >> 64 - NUM_X_BITS);

        int k = (int)(serialized << 64 - Y_SHIFT - NUM_Y_BITS >> 64 - NUM_Y_BITS);

        int l = (int)(serialized << 64 - NUM_Z_BITS >> 64 - NUM_Z_BITS);

        return new BlockPos(j, k, l);

    }

 

    public static Iterable getAllInBox(BlockPos from, BlockPos to)

    {

        final BlockPos blockpos2 = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));

        final BlockPos blockpos3 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));

        return new Iterable()

        {

            private static final String __OBFID = "CL_00002333";

            public Iterator iterator()

            {

                return new AbstractIterator()

                {

                    private BlockPos lastReturned = null;

                    private static final String __OBFID = "CL_00002332";

                    protected BlockPos computeNext0()

                    {

                        if (this.lastReturned == null)

                        {

                            this.lastReturned = blockpos2;

                            return this.lastReturned;

                        }

                        else if (this.lastReturned.equals(blockpos3))

                        {

                            return (BlockPos)this.endOfData();

                        }

                        else

                        {

                            int i = this.lastReturned.getX();

                            int j = this.lastReturned.getY();

                            int k = this.lastReturned.getZ();

 

                            if (i < blockpos3.getX())

                            {

                                ++i;

                            }

                            else if (j < blockpos3.getY())

                            {

                                i = blockpos2.getX();

                                ++j;

                            }

                            else if (k < blockpos3.getZ())

                            {

                                i = blockpos2.getX();

                                j = blockpos2.getY();

                                ++k;

                            }

 

                            this.lastReturned = new BlockPos(i, j, k);

                            return this.lastReturned;

                        }

                    }

                    protected Object computeNext()

                    {

                        return this.computeNext0();

                    }

                };

            }

        };

    }

 

    public static Iterable getAllInBoxMutable(BlockPos from, BlockPos to)

    {

        final BlockPos blockpos2 = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));

        final BlockPos blockpos3 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));

        return new Iterable()

        {

            private static final String __OBFID = "CL_00002331";

            public Iterator iterator()

            {

                return new AbstractIterator()

                {

                    private BlockPos.MutableBlockPos theBlockPos = null;

                    private static final String __OBFID = "CL_00002330";

                    protected BlockPos.MutableBlockPos computeNext0()

                    {

                        if (this.theBlockPos == null)

                        {

                            this.theBlockPos = new BlockPos.MutableBlockPos(blockpos2.getX(), blockpos2.getY(), blockpos2.getZ(), null);

                            return this.theBlockPos;

                        }

                        else if (this.theBlockPos.equals(blockpos3))

                        {

                            return (BlockPos.MutableBlockPos)this.endOfData();

                        }

                        else

                        {

                            int i = this.theBlockPos.getX();

                            int k = this.theBlockPos.getY();

                            int j = this.theBlockPos.getZ();

 

                            if (i < blockpos3.getX())

                            {

                                ++i;

                            }

                            else if (k < blockpos3.getY())

                            {

                                i = blockpos2.getX();

                                ++k;

                            }

                            else if (j < blockpos3.getZ())

                            {

                                i = blockpos2.getX();

                                k = blockpos2.getY();

                                ++j;

                            }

 

                            this.theBlockPos.x = i;

                            this.theBlockPos.y = k;

                            this.theBlockPos.z = j;

                            return this.theBlockPos;

                        }

                    }

                    protected Object computeNext()

                    {

                        return this.computeNext0();

                    }

                };

            }

        };

    }

 

    public Vec3i crossProduct(Vec3i vec)

    {

        return this.crossProductBP(vec);

    }

 

    public static final class MutableBlockPos extends BlockPos

        {

            public int x;

            public int y;

            public int z;

            private static final String __OBFID = "CL_00002329";

 

            private MutableBlockPos(int x_, int y_, int z_)

            {

                super(0, 0, 0);

                this.x = x_;

                this.y = y_;

                this.z = z_;

            }

 

            public int getX()

            {

                return this.x;

            }

 

            public int getY()

            {

                return this.y;

            }

 

            public int getZ()

            {

                return this.z;

            }

 

            public Vec3i crossProduct(Vec3i vec)

            {

                return super.crossProductBP(vec);

            }

 

            MutableBlockPos(int p_i46025_1_, int p_i46025_2_, int p_i46025_3_, Object p_i46025_4_)

            {

                this(p_i46025_1_, p_i46025_2_, p_i46025_3_);

            }

        }

}

 

 

Vec3i (just copied from 1.8, but fixed the errors)

 

package net.bplaced.nidico100.Downgrade;

 

import net.minecraft.util.MathHelper;

import com.google.common.base.Objects;

 

public class Vec3i implements Comparable

{

    public static final Vec3i NULL_VECTOR = new Vec3i(0, 0, 0);

    private final int x;

    private final int y;

    private final int z;

    private static final String __OBFID = "CL_00002315";

 

    public Vec3i(int xIn, int yIn, int zIn)

    {

        this.x = xIn;

        this.y = yIn;

        this.z = zIn;

    }

 

    public Vec3i(double xIn, double yIn, double zIn)

    {

        this(MathHelper.floor_double(xIn), MathHelper.floor_double(yIn), MathHelper.floor_double(zIn));

    }

 

    public boolean equals(Object p_equals_1_)

    {

        if (this == p_equals_1_)

        {

            return true;

        }

        else if (!(p_equals_1_ instanceof Vec3i))

        {

            return false;

        }

        else

        {

            Vec3i vec3i = (Vec3i)p_equals_1_;

            return this.getX() != vec3i.getX() ? false : (this.getY() != vec3i.getY() ? false : this.getZ() == vec3i.getZ());

        }

    }

 

    public int hashCode()

    {

        return (this.getY() + this.getZ() * 31) * 31 + this.getX();

    }

 

    public int compareTo(Vec3i vec)

    {

        return this.getY() == vec.getY() ? (this.getZ() == vec.getZ() ? this.getX() - vec.getX() : this.getZ() - vec.getZ()) : this.getY() - vec.getY();

    }

 

    public int getX()

    {

        return this.x;

    }

 

    public int getY()

    {

        return this.y;

    }

 

    public int getZ()

    {

        return this.z;

    }

 

    public Vec3i crossProduct(Vec3i vec)

    {

        return new Vec3i(this.getY() * vec.getZ() - this.getZ() * vec.getY(), this.getZ() * vec.getX() - this.getX() * vec.getZ(), this.getX() * vec.getY() - this.getY() * vec.getX());

    }

 

    public double distanceSq(double toX, double toY, double toZ)

    {

        double d3 = (double)this.getX() - toX;

        double d4 = (double)this.getY() - toY;

        double d5 = (double)this.getZ() - toZ;

        return d3 * d3 + d4 * d4 + d5 * d5;

    }

 

    public double distanceSqToCenter(double xIn, double yIn, double zIn)

    {

        double d3 = (double)this.getX() + 0.5D - xIn;

        double d4 = (double)this.getY() + 0.5D - yIn;

        double d5 = (double)this.getZ() + 0.5D - zIn;

        return d3 * d3 + d4 * d4 + d5 * d5;

    }

 

    public double distanceSq(Vec3i to)

    {

        return this.distanceSq((double)to.getX(), (double)to.getY(), (double)to.getZ());

    }

 

    public String toString()

    {

        return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString();

    }

 

    public int compareTo(Object p_compareTo_1_)

    {

        return this.compareTo((Vec3i)p_compareTo_1_);

    }

}

 

 

Link to comment
Share on other sites

Why are you backporting stuff? :o

 

Don't copy vanilla classes. BlockPos is 3 ints in pre 1.8. You need to make sure you override the correct method in 1.7 still, I suggest you use @Override.

I want the slimeblock in my 1.7.10 modpack with its physics

my problem is that

    protected void fall(float p_70069_1_)
    {
        if (this.riddenByEntity != null)
        {
            this.riddenByEntity.fall(p_70069_1_);
        }
    }

is not public in 1.7.10

Link to comment
Share on other sites

Seriously dude?  :)

 

World::

[1.8]

    public boolean isAirBlock(BlockPos pos)

[1.7.10]

    public boolean isAirBlock(int x, int y, int z)

 

-TGG

yeah okay i was right, but there is another bug

entityIn.fall(fallDistance, 0.0F);

There stands fall(float) is not defined for fall(float, float), but when i delete one of the floats, there stands the method is not visible i looked on the method

    protected void fall(float p_70069_1_)
    {
        if (this.riddenByEntity != null)
        {
            this.riddenByEntity.fall(p_70069_1_);
        }
    }

how to make public?

Link to comment
Share on other sites

Also, aren't all of the 1.8 blocks available in 1.7 using Gany's Surface?

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

Also, aren't all of the 1.8 blocks available in 1.7 using Gany's Surface?

No :/ i need slime block and Armorstand with the physics of 1.8 :/

 

Good luck doing the physics with vanilla code that doesn't exist.

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

i didn't find anything good about using reflection in 1.7.10

how to do?

 

Reflection is an entire Java package dealing with class files. It's half way between "code that runs" and "code that modifies running code" (ASM).

 

Here's a chunk I use:

 

try {
    		Class clz = BiomeGenBase.class;
    		WildlifeEventHandler.rains = clz.getDeclaredField("enableRain");//field_76765_S
    		WildlifeEventHandler.rains.setAccessible(true);
    		WildlifeEventHandler.snows = clz.getDeclaredField("enableSnow");//field_76766_R
    		WildlifeEventHandler.snows.setAccessible(true);
    	}
    	catch(NoSuchFieldException e ) {
    	}

 

Basically, I request a private field from a class, set its accessibility to public, so that later I can modify the value (if I don't, the program will crash with an exception).  Eg:

 

WildlifeEventHandler.snows.set(BiomeGenBase.plains, true);

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

i didn't find anything good about using reflection in 1.7.10

how to do?

 

Reflection is an entire Java package dealing with class files. It's half way between "code that runs" and "code that modifies running code" (ASM).

 

Here's a chunk I use:

 

try {
    		Class clz = BiomeGenBase.class;
    		WildlifeEventHandler.rains = clz.getDeclaredField("enableRain");//field_76765_S
    		WildlifeEventHandler.rains.setAccessible(true);
    		WildlifeEventHandler.snows = clz.getDeclaredField("enableSnow");//field_76766_R
    		WildlifeEventHandler.snows.setAccessible(true);
    	}
    	catch(NoSuchFieldException e ) {
    	}

 

Basically, I request a private field from a class, set its accessibility to public, so that later I can modify the value (if I don't, the program will crash with an exception).  Eg:

 

WildlifeEventHandler.snows.set(BiomeGenBase.plains, true);

i tried:

	public static void main(String args[]) {
try {
	Method method = Entity.class.getDeclaredMethod("fall");
	method.setAccessible(true);
	}
		catch (Exception e) 
		{
		e.printStackTrace();
		}
}

but still there stands the method is not visible

Link to comment
Share on other sites

Just because you typed it out doesn't mean the IDE magically changes the uncompiled code.

 

WildlifeEventHandler.snows.set(BiomeGenBase.plains, true);

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

i didn't find anything good about using reflection in 1.7.10

how to do?

 

Reflection is an entire Java package dealing with class files. It's half way between "code that runs" and "code that modifies running code" (ASM).

 

Here's a chunk I use:

 

try {
    		Class clz = BiomeGenBase.class;
    		WildlifeEventHandler.rains = clz.getDeclaredField("enableRain");//field_76765_S
    		WildlifeEventHandler.rains.setAccessible(true);
    		WildlifeEventHandler.snows = clz.getDeclaredField("enableSnow");//field_76766_R
    		WildlifeEventHandler.snows.setAccessible(true);
    	}
    	catch(NoSuchFieldException e ) {
    	}

 

Basically, I request a private field from a class, set its accessibility to public, so that later I can modify the value (if I don't, the program will crash with an exception).  Eg:

 

WildlifeEventHandler.snows.set(BiomeGenBase.plains, true);

i tried:

	public static void main(String args[]) {
try {
	Method method = Entity.class.getDeclaredMethod("fall");
	method.setAccessible(true);
	}
		catch (Exception e) 
		{
		e.printStackTrace();
		}
}

but still there stands the method is not visible

 

forget the reflection i just changed

entityIn.fall(fallDistance, 0.0F);

to

entityIn.fallDistance = 0.0F;

i was so easy but i was blind :D

now i will try to add onLanded method

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



×
×
  • Create New...

Important Information

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