-
Notifications
You must be signed in to change notification settings - Fork 81
/
BlockNetherLeaves2.java
196 lines (165 loc) · 5.3 KB
/
BlockNetherLeaves2.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
190
191
192
193
194
195
196
package com.progwml6.natura.nether.block.leaves;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import javax.annotation.Nonnull;
import com.google.common.collect.Lists;
import com.progwml6.natura.common.block.base.BlockLeavesBase;
import com.progwml6.natura.library.NaturaRegistry;
import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.shared.NaturaCommons;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import slimeknights.mantle.block.EnumBlock;
public class BlockNetherLeaves2 extends BlockLeavesBase
{
public static PropertyEnum<BlockNetherLeaves2.LeavesType> TYPE = PropertyEnum.create("type", BlockNetherLeaves2.LeavesType.class);
public BlockNetherLeaves2()
{
this.setCreativeTab(NaturaRegistry.tabWorld);
Blocks.FIRE.setFireInfo(this, 0, 0);
this.setDefaultState(this.blockState.getBaseState().withProperty(CHECK_DECAY, false).withProperty(DECAYABLE, true));
}
@Override
public void updateTick(World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state, Random rand)
{
super.updateTick(worldIn, pos, state, rand);
}
@SideOnly(Side.CLIENT)
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list)
{
for (LeavesType type : LeavesType.values())
{
list.add(new ItemStack(this, 1, this.getMetaFromState(this.getDefaultState().withProperty(TYPE, type))));
}
}
// sapling item
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
if (state.getValue(TYPE) == LeavesType.DARKWOOD_FRUIT)
{
return NaturaCommons.edibles;
}
else
{
return Item.getItemFromBlock(NaturaNether.netherSapling);
}
}
// sapling meta
@Override
public int damageDropped(IBlockState state)
{
if (state.getValue(TYPE) == LeavesType.DARKWOOD_FRUIT)
{
return 10;
}
else
{
return 2;
}
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{
return new ItemStack(Item.getItemFromBlock(this), 1, (state.getValue(TYPE)).ordinal() & 3);
}
// item dropped on silktouching
@Override
protected ItemStack getSilkTouchDrop(@Nonnull IBlockState state)
{
return new ItemStack(Item.getItemFromBlock(this), 1, (state.getValue(TYPE)).ordinal() & 3);
}
@Nonnull
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, TYPE, CHECK_DECAY, DECAYABLE);
}
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta)
{
int type = meta % 4;
if (type < 0 || type >= LeavesType.values().length)
{
type = 0;
}
LeavesType logtype = LeavesType.values()[type];
return this.getDefaultState()
.withProperty(TYPE, logtype)
.withProperty(DECAYABLE, (meta & 4) == 0)
.withProperty(CHECK_DECAY, (meta & 8) > 0);
}
@Override
public int getMetaFromState(IBlockState state)
{
int meta = (state.getValue(TYPE)).ordinal() & 3; // only first 2 bits
if (!state.getValue(DECAYABLE))
{
meta |= 4;
}
if (state.getValue(CHECK_DECAY))
{
meta |= 8;
}
return meta;
}
@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune)
{
IBlockState state = world.getBlockState(pos);
return Lists.newArrayList(this.getSilkTouchDrop(state));
}
@Override
public boolean isLeaves(IBlockState state, IBlockAccess world, BlockPos pos)
{
return true;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(IBlockState state, int fortune, Random random)
{
if (state.getValue(TYPE) == LeavesType.DARKWOOD_FRUIT)
{
return 1;
}
return this.quantityDroppedWithBonus(fortune, random);
}
public enum LeavesType implements IStringSerializable, EnumBlock.IEnumMeta
{
DARKWOOD, DARKWOOD_FLOWERING, DARKWOOD_FRUIT;
public final int meta;
LeavesType()
{
this.meta = this.ordinal();
}
@Override
public String getName()
{
return this.toString().toLowerCase(Locale.US);
}
@Override
public int getMeta()
{
return this.meta;
}
}
}