Help Making a Block Face the Player When Placed

Started by KevinZiggy on

Topic category: Help with modding (Java Edition)

Last seen on 21:36, 19. Aug 2016
Joined Aug 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Help Making a Block Face the Player When Placed
Tue, 08/16/2016 - 07:45 (edited)

I'm working with MCreator 1.6.6 trying to make a mod compatible with Minecraft 1.8.9 for a project I'm working on. I made a block with Cubik Pro, it's a little Tiki Totem guy, and I then loaded the .json into MCreator to make it into a mod to add it and some other custom blocks. I didn't see any option that would make it place similar to the mob skulls in Vanilla Minecraft, and I know very very little about Java coding and how to edit it. I want for the totem to be able to be placed like a mob head/skull on the ground where it faces the player when placed and can be placed at 16 different angles. I'm going to be making more decorative items like this to be used in a project I'm working on. I'd like to figure out how to get them to place like the skulls. Right now I can only make it face in the direction it was created facing which is south. 

What do I need to add to make the block place facing the player like a mob skull does? I've tried searching for this information for the last few days and haven't found anything that is clear.

Also, I'd like to be able to get rid of the cast shadow effect that it has on the ground around it if possible. I tried turning ambient occlusion off, but that didn't seem to do it.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This is the code that MCreator has generated for my block:

package mod.mcreator;import net.minecraftforge.fml.client.*;
import net.minecraftforge.fml.client.registry.*;
import net.minecraftforge.fml.common.*;
import net.minecraftforge.fml.common.asm.*;
import net.minecraftforge.fml.common.asm.transformers.*;
import net.minecraftforge.fml.common.discovery.*;
import net.minecraftforge.fml.common.discovery.asm.*;
import net.minecraftforge.fml.common.event.*;
import net.minecraftforge.fml.common.functions.*;
import net.minecraftforge.fml.common.network.*;
import net.minecraftforge.fml.common.registry.*;
import net.minecraftforge.fml.common.toposort.*;
import net.minecraftforge.fml.common.versioning.*;
import net.minecraftforge.fml.relauncher.*;
import net.minecraftforge.fml.server.*;
import net.minecraft.block.*;
import net.minecraft.block.material.*;
import net.minecraft.client.*;
import net.minecraft.client.audio.*;
import net.minecraft.client.entity.*;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.achievement.*;
import net.minecraft.client.gui.inventory.*;
import net.minecraft.client.model.*;
import net.minecraft.client.multiplayer.*;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.culling.*;
import net.minecraft.client.renderer.entity.*;
import net.minecraft.client.renderer.tileentity.*;
import net.minecraft.client.settings.*;
import net.minecraft.command.*;
import net.minecraft.crash.*;
import net.minecraft.creativetab.*;
import net.minecraft.dispenser.*;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.boss.*;
import net.minecraft.entity.effect.*;
import net.minecraft.entity.item.*;
import net.minecraft.entity.monster.*;
import net.minecraft.entity.passive.*;
import net.minecraft.entity.player.*;
import net.minecraft.entity.projectile.*;
import net.minecraft.inventory.*;
import net.minecraft.item.*;
import net.minecraft.item.crafting.*;
import net.minecraft.nbt.*;
import net.minecraft.network.*;
import net.minecraft.network.rcon.*;
import net.minecraft.pathfinding.*;
import net.minecraft.potion.*;
import net.minecraft.profiler.*;
import net.minecraft.server.*;
import net.minecraft.server.dedicated.*;
import net.minecraft.server.gui.*;
import net.minecraft.server.integrated.*;
import net.minecraft.server.management.*;
import net.minecraft.stats.*;
import net.minecraft.tileentity.*;
import net.minecraft.util.*;
import net.minecraft.village.*;
import net.minecraft.world.*;
import net.minecraft.world.biome.*;
import net.minecraft.world.chunk.*;
import net.minecraft.world.chunk.storage.*;
import net.minecraft.world.demo.*;
import net.minecraft.world.gen.*;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.layer.*;
import net.minecraft.world.gen.structure.*;
import net.minecraft.world.storage.*;
import net.minecraftforge.classloading.*;
import net.minecraftforge.client.*;
import net.minecraftforge.client.event.*;
import net.minecraftforge.client.event.sound.*;
import net.minecraftforge.common.*;
import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.*;
import net.minecraftforge.event.entity.item.*;
import net.minecraftforge.event.entity.living.*;
import net.minecraftforge.event.entity.minecart.*;
import net.minecraftforge.event.entity.player.*;
import net.minecraftforge.event.terraingen.*;
import net.minecraftforge.event.world.*;
import net.minecraftforge.oredict.*;
import net.minecraft.init.*;
import java.util.*;

import net.minecraftforge.common.util.*;
import net.minecraft.client.renderer.texture.*;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import net.minecraft.client.resources.model.*;
import net.minecraft.block.state.*;
public class mcreator_tikiIdol {

public mcreator_tikiIdol(){}

public static BlockTikiIdol block;

public static Object instance;public int addFuel(ItemStack fuel){return 0;}
public void serverLoad(FMLServerStartingEvent event){}
public void preInit(FMLPreInitializationEvent event){
}
public void registerRenderers(){}
public void load(FMLInitializationEvent event){
if(event.getSide() == Side.CLIENT){
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation("TestEnvironmentMod:TikiIdol", "inventory"));}
}

static{

block = (BlockTikiIdol)(new BlockTikiIdol().setHardness(2.0F)
.setResistance(10.0F)
.setLightLevel(0.0F)
.setUnlocalizedName("TikiIdol")
.setLightOpacity(0)
.setStepSound(Block.soundTypeWood)
.setCreativeTab(CreativeTabs.tabDecorations)
);block.setBlockBounds(0.1F,0.0F,0.1F,0.9F,1.0F,0.9F);
block.setHarvestLevel("axe", 0);
}

public void generateSurface(World world, Random random, int chunkX, int chunkZ){}
public void generateNether(World world, Random random, int chunkX, int chunkZ){}
static class BlockTikiIdol extends Block
{

int a1 = 0,a2 = 0,a3 = 0,a4 = 0,a5 = 0,a6 = 0;

boolean red = false;

 

protected BlockTikiIdol()
{
super(Material.wood);

GameRegistry.registerBlock(this, "TikiIdol");

}

public void onBlockAdded(World world, BlockPos pos, IBlockState state){
int i = pos.getX();int j = pos.getY();int k = pos.getZ();world.scheduleUpdate(new BlockPos(i, j, k), this, this.tickRate(world));

}
public int isProvidingStrongPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side){
return red?15:0;
}
public int isProvidingWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side){
return red?15:0;
}
public boolean isOpaqueCube()
{
return false;
}

@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer()
{
return EnumWorldBlockLayer.SOLID;
}

@Override
public int tickRate(World world)
{
return 10;
}

public int quantityDropped(Random par1Random){
return 1;
}

}
}

Edited by Klemen on Tue, 08/16/2016 - 07:45
Last seen on 04:16, 13. Mar 2024
Joined Oct 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I also would like to know how
Wed, 08/24/2016 - 05:39

I also would like to know how to make blocks face the player when placed.

 

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:I also would like to know how
Wed, 08/24/2016 - 09:51

@#1
 

Try use PropertyDirection.

First you need these imports:
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;

Next you need variable for it:
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

and in constructor define default state:
this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));

Now you need these methods:

[spoiler]

 

@Override
public IBlockState getStateForEntityRender(IBlockState state) {

return getDefaultState().withProperty(FACING, EnumFacing.SOUTH);
}

@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing facing = EnumFacing.getFront(meta);

if(facing.getAxis()==EnumFacing.Axis.Y) {
facing=EnumFacing.NORTH;
}

return getDefaultState().withProperty(FACING, facing);
}

@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing) state.getValue(FACING)).getIndex();
}

@Override
protected BlockState createBlockState() {
return new BlockState(this, new IProperty[]{FACING});
}

@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos,
EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
EntityLivingBase placer) {
return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());

}

[/spoiler]

And in the blockstate .json file asign the variable:

This is from my model file (your values can be maybe different):

{
"variants": {
"facing=up": { "model": "MyMod:Armchair" },
"facing=south": { "model": "MyMod:Armchair" },
"facing=east": { "model": "MyMod:Armchair", "y": 270 },
"facing=west": { "model": "MyMod:Armchair", "y": 90 },
"facing=north": { "model": "MyMod:Armchair", "y": 180 }
}
}

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Nuparu how you do that man? i
Sat, 09/24/2016 - 23:12

Nuparu how you do that man? i tried and i failed.. im using MCreator 1.7 (last version i think)...

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This part is the one i dont
Sat, 09/24/2016 - 23:14

This part is the one i dont understand:

 

and in constructor define default state:
this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));

 

 

where does it go?

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
when i put that on the block
Sat, 09/24/2016 - 23:18

when i put that on the block file it gives this error:

 

error: <identifier> expected
this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok so Nuparu made it work on
Tue, 09/27/2016 - 14:07

Ok so Nuparu made it work on MCreator 161.. all we need to do here is make it work on 170 *cross fingers*

Last seen on 08:40, 25. Mar 2018
Joined Apr 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok, pulling my hair out on
Sat, 04/29/2017 - 13:33

Ok, pulling my hair out on this lol. I've followed the stuff in the video, and I keep getting this:

error: method does not override or implement a method from a supertype

on the declaration of this method override:

@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing,
                            float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
  return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}

Man, I'm going crazy here. Sorry, I am not a Java guru by any stretch of the imagination. I understand what the error means, as I program in OO in other languages, but any ideas if I need to adjust this further for MCreator 1.7.5 / 1.11 Minecraft? Thanks in advance!

Last seen on 08:40, 25. Mar 2018
Joined Apr 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I worked around it and used
Sat, 04/29/2017 - 21:53

I worked around it and used onBlockPlacedBy() instead:

[spoiler]

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
  worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}

[/spoiler]

Last seen on 22:16, 9. Sep 2022
Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
marneman Can you give me a…
Mon, 09/05/2022 - 22:50

marneman Can you give me a step by step on how to do that because I don't understand it at all

Last seen on 13:56, 19. Dec 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You don't need custom code…
Mon, 09/05/2022 - 23:05

You don't need custom code anymore. Look at this image: https://imgur.com/W1gP9fp

Last seen on 22:16, 9. Sep 2022
Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
ImOd102 i figured this out…
Wed, 09/07/2022 - 15:45

ImOd102 i figured this out about 10 minuites ago after i was on this topic for 5 hours on monday and i was gonna come to chat exactly what you did wow