-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMultiTexturedBlock.java
More file actions
62 lines (51 loc) · 2.33 KB
/
MultiTexturedBlock.java
File metadata and controls
62 lines (51 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package mcjty.modtut.blocks;
import mcjty.modtut.CreativeTab;
import mcjty.modtut.ModTut;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class MultiTexturedBlock extends Block {
public static final PropertyDirection FACING = PropertyDirection.create("facing");
public MultiTexturedBlock() {
super(Material.ROCK);
setUnlocalizedName(ModTut.MODID + ".multitexturedblock");
setRegistryName("multitexturedblock");
setCreativeTab(CreativeTab.tabMODTAB);
setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
}
@SideOnly(Side.CLIENT)
public void initModel() {
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
world.setBlockState(pos, state.withProperty(FACING, getFacingFromEntity(pos, placer)), 2);
}
public static EnumFacing getFacingFromEntity(BlockPos clickedBlock, EntityLivingBase entity) {
return EnumFacing.getFacingFromVector((float) (entity.posX - clickedBlock.getX()), (float) (entity.posY - clickedBlock.getY()), (float) (entity.posZ - clickedBlock.getZ()));
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7));
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(FACING).getIndex();
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, FACING);
}
}