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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • If you're seeking an unparalleled solution to recover lost or stolen cryptocurrency, let me introduce you to GearHead Engineers Solutions. Their exceptional team of cybersecurity experts doesn't just restore your funds; they restore your peace of mind. With a blend of cutting-edge technology and unparalleled expertise, GearHead Engineers swiftly navigates the intricate web of the digital underworld to reclaim what's rightfully yours. In your moment of distress, they become your steadfast allies, guiding you through the intricate process of recovery with transparency, trustworthiness, and unwavering professionalism. Their team of seasoned web developers and cyber specialists possesses the acumen to dissect the most sophisticated schemes, leaving no stone unturned in their quest for justice. They don't just stop at recovering your assets; they go the extra mile to identify and track down the perpetrators, ensuring they face the consequences of their deceitful actions. What sets  GearHead Engineers apart is not just their technical prowess, but their unwavering commitment to their clients. From the moment you reach out to them, you're met with compassion, understanding, and a resolute determination to right the wrongs inflicted upon you. It's not just about reclaiming lost funds; it's about restoring faith in the digital landscape and empowering individuals to reclaim control over their financial futures. If you find yourself ensnared in the clutches of cybercrime, don't despair. Reach out to GearHead Engineers and let them weave their magic. With their expertise by your side, you can turn the tide against adversity and emerge stronger than ever before. In the realm of cybersecurity, GearHead Engineers reigns supreme. Don't just take my word for it—experience their unparalleled excellence for yourself. Your journey to recovery starts here.
    • Ok so this specific code freezes the game on world creation. This is what gets me so confused, i get that it might not be the best thing, but is it really so generation heavy?
    • Wizard web recovery has exhibited unparalleled strength in the realm of recovery. They stand out as the premier team to collaborate with if you encounter withdrawal difficulties from the platform where you’ve invested. Recently, I engaged with them to recover over a million dollars trapped in an investment platform I’d been involved with for months. I furnished their team with every detail of the investment, including accounts, names, and wallet addresses to which I sent the funds. This decision proved to be the best I’ve made, especially after realizing the company had scammed me.   Wizard web recovery ensures exemplary service delivery and ensures the perpetrators face justice. They employ advanced techniques to ensure you regain access to your funds. Understandably, many individuals who have fallen victim to investment scams may still regret engaging in online services again due to the trauma of being scammed. However, I implore you to take action. Seek assistance from Wizard Web Recovery today and witness their remarkable capabilities. I am grateful that I resisted their enticements, and despite the time it took me to discover Wizard web recovery, they ultimately fulfilled my primary objective. Without wizard web recovery intervention, I would have remained despondent and perplexed indefinitely.
    • I've tested the same code on three different envionrments (Desktop win10, desktop Linux and Laptop Linux) and it kinda blows up all the same. Gonna try this code and see if i can tune it
  • Topics

×
×
  • Create New...

Important Information

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