Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello! I created custom block and trying to rotate it, but its position is good only for one direction (2), for others (0,1,3) its position is strange.

 

RenderTable.java

package com.bros.tastymod.rendering.entities.tiles.tileentities;

import com.bros.tastymod.model.ModelMeat;
import com.bros.tastymod.rendering.entities.tiles.TileEntityTable;
import jdk.nashorn.internal.runtime.regexp.joni.constants.EncloseType;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

public class RenderTable extends TileEntitySpecialRenderer {

    private ModelMeat model;
    private ResourceLocation texture = new ResourceLocation("tastymod:textures/blocks/Meat.png");

    public RenderTable() {
        model = new ModelMeat();
    }

    @Override
    public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float scale) {

        GL11.glPushMatrix();
        GL11.glTranslated(x - 0.3, y + 0.5, z + 0.3);
        GL11.glRotated(0, 0, 0, 1);
        TileEntityTable myTile = (TileEntityTable) tile;
        int dir = myTile.direction;

        GL11.glRotatef(dir * (-180F), 0.0F, 1.0F, 0.0F);


        this.bindTexture(texture);
        this.model.render((Entity) null, 0, -0.1f, 0, 0, 0, 0.0625f);
        GL11.glPopMatrix();
    }
}

 

BlockTable.java

package com.bros.tastymod.blocks;

import com.bros.tastymod.rendering.entities.tiles.TileEntityTable;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
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 BlockTable extends BlockContainer {
    public BlockTable() {
        super(Material.iron);
        setBlockName("table");
    }

    @Override
    public int getRenderType(){
        return -1;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }
    public boolean isNormalCube(){
        return false;
    }

    @Override
    public TileEntity createNewTileEntity(World world, int id) {
        return new TileEntityTable();
    }

    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
       if (entity==null){
           return;
       }



       TileEntityTable tile = (TileEntityTable) world.getTileEntity(x,y,z);
        tile.direction = MathHelper.floor_double((double) (entity.rotationYaw*4.0F/360)+0.5D) &3;

        if(tile.direction==1){
            world.setBlockMetadataWithNotify(x,y,z,5,2);
        }
        
    }
}

 

TileEntityTable.java

package com.bros.tastymod.rendering.entities.tiles;

import net.minecraft.tileentity.TileEntity;

public class TileEntityTable extends TileEntity {

    public int direction;
    
}

 

 

Screenshot_4.png

Screenshot_5.png

Screenshot_6.png

Screenshot_7.png

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.