Jump to content

[1.7.10] All blocks of same type rotate towards player.


ThePhysician2000

Recommended Posts

I have come across yet another problem: rotating blocks.

EDIT: This bit is fixed, but it throws an error on this line in the TileEntityRender Class:

        int facing = TileEntityThisEndUpSeat.getFacingDirection();

 

 

Block Class:

 

 

package thephysician2000sfurniture.thisendupseat;

 

import cpw.mods.fml.client.registry.RenderingRegistry;

import thephysician2000sfurniture.MainClass;

import thephysician2000sfurniture.refectorytabletwo.TileEntityTableTwo;

import net.minecraft.block.BlockContainer;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.item.ItemStack;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.MathHelper;

import net.minecraft.world.World;

 

public class BlockThisEndUpSeat extends BlockContainer{

 

public BlockThisEndUpSeat(Material p_i45386_1_) {

super(p_i45386_1_);

// TODO Auto-generated constructor stub

}

public static void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)

    {

            int l = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 2.5D) & 3;

            world.setBlockMetadataWithNotify(i, j, k, l, 2);

            System.out.println(l);

    }

 

@Override

public int getRenderType(){

int RT;

RT = RenderingRegistry.getNextAvailableRenderId();

return RT;

}

@Override

public TileEntity createNewTileEntity(World world, int var2) {

return new TileEntityThisEndUpSeat();

}

 

@Override

public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack) {

final int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;

TileEntity tileEntity = world.getTileEntity(i, j, k);

if (tileEntity != null && tileEntity instanceof TileEntityThisEndUpSeat)

{

TileEntityThisEndUpSeat tileEntityTEUS = (TileEntityThisEndUpSeat) tileEntity;

tileEntityTEUS.setFacingDirection((facing + 1));

world.markBlockForUpdate(i, j, k);

    }

}

   

    @Override

    public boolean isOpaqueCube() {

            return false;

    }

   

    public boolean renderAsNormalBlock() {

            return false;

    }

   

    public void registerIcons(IIconRegister icon) {

        this.blockIcon = icon.registerIcon(MainClass.MODID + "textures/items/refectoryTableOne");

    }

 

}

 

 

 

 

TileEntity Class:

 

 

package thephysician2000sfurniture.thisendupseat;

 

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.network.NetworkManager;

import net.minecraft.network.Packet;

import net.minecraft.network.play.server.S35PacketUpdateTileEntity;

import net.minecraft.tileentity.TileEntity;

 

public class TileEntityThisEndUpSeat extends TileEntity{

private static int facingDirection;

 

public static int getFacingDirection()

    {

        return facingDirection;

    }

 

public static void setFacingDirection(int par1)

    {

        facingDirection = par1;

    }

 

@Override

    public Packet getDescriptionPacket()

    {

        NBTTagCompound tag = new NBTTagCompound();

        writeToNBT(tag);

        return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);

    }

 

    @Override

    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)

    {

        readFromNBT(packet.func_148857_g());

    }

 

@Override

    public void readFromNBT(NBTTagCompound nbttagcompound)

    {

        super.readFromNBT(nbttagcompound); 

        facingDirection = nbttagcompound.getInteger("facingDirection");

    }

 

    @Override

    public void writeToNBT(NBTTagCompound nbttagcompound)

    {

        super.writeToNBT(nbttagcompound);

        nbttagcompound.setInteger("facingDirection", facingDirection);

    }

 

}

 

 

 

 

TileEntityRender Class:

 

 

package thephysician2000sfurniture.thisendupseat;

 

import org.lwjgl.opengl.GL11;

 

import thephysician2000sfurniture.MainClass;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.entity.Entity;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.ResourceLocation;

import net.minecraft.world.World;

 

public class TileEntityThisEndUpSeatRender extends TileEntitySpecialRenderer{

 

    private final ThisEndUpSeat model;

    private int textureWidth = 64;

    private int textureHight = 32;

   

    public TileEntityThisEndUpSeatRender() {

            model = new ThisEndUpSeat();

    }

   

    private static void adjustRotatePivotViaMeta(World world, int x, int y, int z) {

            int meta = world.getBlockMetadata(x, y, z);

            GL11.glPushMatrix();

            GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);

            GL11.glPopMatrix();

    }

 

 

    @Override

    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {

        GL11.glPushMatrix();

        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);

        ResourceLocation thisendupseat = new ResourceLocation(MainClass.MODID + ":textures/model/ThisEndUpSeat.png");

        Minecraft.getMinecraft().renderEngine.bindTexture(thisendupseat);

        GL11.glPushMatrix();

        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

        int facing = TileEntityThisEndUpSeat.getFacingDirection();

        GL11.glRotatef(((facing - 1) * 90), 0.0F, 1.0F, 0.0F);

        GL11.glDisable(GL11.GL_CULL_FACE);

        GL11.glEnable(GL11.GL_ALPHA_TEST);

        this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        GL11.glPopMatrix();

        GL11.glPopMatrix();

    }

}

 

 

 

Link to comment
Share on other sites

You are using the static modifier wrong, if you use the static modifier on a variable or method, you are setting that variable or methods value universally. In your case, this means that all instances of your block are going to have the same orientation. So when you place a new block, it will update the orientation of all other instances of that block in the world.

 

To fix this, you need to remove the static modifiers.

 

So for example instead of:

public static void onBlockPlacedBy(...)

 

change it to:

public void onBlockPlacedBy(...)

 

Please research what the static modifiers mean. This is basic java.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Remove static from all the functions that us it..... and learn some basic java.

I DID, and it throws an error on this line:

        int facing = TileEntityThisEndUpSeat.getFacingDirection();

It says needs one of them to be static: the very one that is causing the problem: getFacingDirection.

Link to comment
Share on other sites

int facing = TileEntityThisEndUpSeat.getFacingDirection();

Remove static from all the functions that us it..... and learn some basic java.

The answer is obvious when you do as Chibill said and then look at what you just posted.

Don't be an ass just because you don't know what you're doing and are being told that you don't.

 

(Edit: I even made an attempt to point it out for you.)

Link to comment
Share on other sites

int facing = TileEntityThisEndUpSeat.getFacingDirection();

Remove static from all the functions that us it..... and learn some basic java.

The answer is obvious when you do as Chibill said and then look at what you just posted.

Don't be an ass just because you don't know what you're doing and are being told that you don't.

 

(Edit: I even made an attempt to point it out for you.)

 

1. I am attempting to learn Java through modding. So, yeah, I am a noob.

2. I am not "being an ass" because everyone is telling me I don't know Java, all I said was when I remove all static from functions, it throws an error because it needs a global variable. To put it another way: "How do I stop this error?"

3. You are contradicting yourself. You first say: "you don't know what you're doing" and then you attempt to "point it out" where my error is. Now, if I am a noob, like both of us agree, how am I going to understand where I went wrong by simply italicizing a .class name of all things?

Link to comment
Share on other sites

Learning Java through modding is not necessarily a bad idea, you just have to be cautious and make sure you know what code means. I learned Java through modding, which got me interested in programming, and I now know several other languages. Making a minecraft mod is more rewarding than making the console say "Hello, World."

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

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.