/
BlockNaturaLogs.java
189 lines (164 loc) · 5.43 KB
/
BlockNaturaLogs.java
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package com.progwml6.natura.blocks.natural;
import java.util.List;
import java.util.Random;
import mantle.blocks.util.BlockVariant;
import mantle.blocks.util.IBlockWithVariants;
import mantle.blocks.util.PropertyVariant;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.StatCollector;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.progwml6.natura.Natura;
public class BlockNaturaLogs extends BlockLog implements IBlockWithVariants
{
public static final BlockVariant
EUCALYPTUS = new BlockVariant(0, "eucalyptus_log"),
SAKURA = new BlockVariant(1, "sakura_log"),
GHOSTWOOD = new BlockVariant(2, "ghostwood_log"),
HOPSEED = new BlockVariant(3, "hopseed_log");
public static final PropertyVariant LOG_TYPE = PropertyVariant.create("variant", EUCALYPTUS, SAKURA, GHOSTWOOD, HOPSEED);
public BlockNaturaLogs()
{
super();
this.setHardness(1.5F);
this.setResistance(5F);
this.setStepSound(Block.soundTypeWood);
Blocks.fire.setFireInfo(this, 5, 20);
this.setDefaultState(this.getBlockState().getBaseState().withProperty(LOG_TYPE, EUCALYPTUS).withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
this.setCreativeTab(Natura.INSTANCE.getCreativeTabs().tabMisc);
}
@Override
public String getLocalizedName()
{
return StatCollector.translateToLocal("natura." + this.getUnlocalizedName() + ".name");
}
@Override
public float getBlockHardness(World worldIn, BlockPos pos)
{
return this.blockHardness;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(this);
}
@Override
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face)
{
return this.getMetaFromState(world.getBlockState(pos)) % 4 != 2 ? this.getFlammability(world, pos, face) : 0;
}
@Override
public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face)
{
return this.getMetaFromState(world.getBlockState(pos)) % 4 != 2 ? this.getFireSpreadSpeed(world, pos, face) : 0;
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list)
{
for (BlockVariant variant : LOG_TYPE.getAllowedValues())
{
list.add(new ItemStack(itemIn, 1, variant.getMeta()));
}
}
@Override
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState().withProperty(LOG_TYPE, LOG_TYPE.getVariantFromMeta((meta & 3)));
switch (meta & 12)
{
case 0:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
break;
case 4:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
break;
case 8:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
break;
default:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
}
return iblockstate;
}
/**
* Convert the BlockState into the correct metadata value
*/
@Override
public int getMetaFromState(IBlockState state)
{
byte b0 = 0;
int i = b0 | ((BlockVariant) state.getValue(LOG_TYPE)).getMeta();
switch (SwitchEnumAxis.AXIS_LOOKUP[((BlockLog.EnumAxis) state.getValue(LOG_AXIS)).ordinal()])
{
case 1:
i |= 4;
break;
case 2:
i |= 8;
break;
case 3:
i |= 12;
}
return i;
}
@Override
protected BlockState createBlockState()
{
return new BlockState(this, new IProperty[] { LOG_TYPE, LOG_AXIS });
}
/**
* Get the damage value that this Block should drop
*/
@Override
public int damageDropped(IBlockState state)
{
return ((BlockVariant) state.getValue(LOG_TYPE)).getMeta();
}
@Override
public String getVariantNameFromStack(ItemStack stack)
{
return LOG_TYPE.getVariantFromMeta(stack.getMetadata()).getName();
}
static final class SwitchEnumAxis
{
static final int[] AXIS_LOOKUP = new int[BlockLog.EnumAxis.values().length];
static
{
try
{
AXIS_LOOKUP[BlockLog.EnumAxis.X.ordinal()] = 1;
}
catch (NoSuchFieldError var3)
{
}
try
{
AXIS_LOOKUP[BlockLog.EnumAxis.Z.ordinal()] = 2;
}
catch (NoSuchFieldError var2)
{
}
try
{
AXIS_LOOKUP[BlockLog.EnumAxis.NONE.ordinal()] = 3;
}
catch (NoSuchFieldError var1)
{
}
}
}
}