/
BlockEnhancedCauldron.java
159 lines (133 loc) · 4.8 KB
/
BlockEnhancedCauldron.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
package knightminer.inspirations.recipes.block;
import java.util.Locale;
import java.util.Random;
import javax.annotation.Nonnull;
import knightminer.inspirations.library.util.TextureBlockUtil;
import knightminer.inspirations.recipes.client.BoilingParticle;
import knightminer.inspirations.recipes.tileentity.TileCauldron;
import net.minecraft.block.BlockCauldron;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import slimeknights.mantle.property.PropertyString;
public class BlockEnhancedCauldron extends BlockCauldron implements ITileEntityProvider {
public static final PropertyEnum<CauldronContents> CONTENTS = PropertyEnum.create("contents", CauldronContents.class);
public static final PropertyBool BOILING = PropertyBool.create("boiling");
public static final PropertyString TEXTURE = TextureBlockUtil.TEXTURE_PROP;
public BlockEnhancedCauldron() {
this.setDefaultState(this.blockState.getBaseState()
.withProperty(LEVEL, 0)
.withProperty(BOILING, false)
.withProperty(CONTENTS, CauldronContents.FLUID));
this.setHardness(2.0F);
this.setUnlocalizedName("cauldron");
this.hasTileEntity = true;
}
/* TE behavior */
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileCauldron();
}
@Override
public void fillWithRain(World world, BlockPos pos) {
TileEntity te = world.getTileEntity(pos);
// do not fill unless the current contents are water
if(te instanceof TileCauldron && !((TileCauldron) te).isWater()) {
return;
}
super.fillWithRain(world, pos);
}
/**
* Called When an Entity Collided with the Block
*/
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
TileEntity te = world.getTileEntity(pos);
// do not estinguish unless the current contents are water
if(te instanceof TileCauldron && !((TileCauldron) te).isWater()) {
return;
}
super.onEntityCollidedWithBlock(world, pos, state, entity);
}
/* Content texture */
@Override
protected ExtendedBlockState createBlockState() {
return new ExtendedBlockState(this, new IProperty[]{LEVEL, CONTENTS, BOILING}, new IUnlistedProperty[]{TEXTURE});
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileCauldron) {
state = state.withProperty(CONTENTS, ((TileCauldron)te).getContentType());
}
// add boiling
state = state.withProperty(BOILING, world.getBlockState(pos.down()).getBlock() == Blocks.FIRE);
return state;
}
@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
if(!state.getActualState(world, pos).getValue(BOILING)) {
return;
}
int level = state.getValue(LEVEL);
if(level == 0) {
return;
}
ParticleManager manager = Minecraft.getMinecraft().effectRenderer;
for(int i = 0; i < 2; i++) {
double x = pos.getX() + 0.1875D + (rand.nextFloat() * 0.625D);
double y = pos.getY() + 0.375D + (level * 0.1875D);
double z = pos.getZ() + 0.1875D + (rand.nextFloat() * 0.625D);
manager.addEffect(new BoilingParticle(world, x, y, z, 0, 0, 0));
}
}
@Nonnull
@Override
public IBlockState getExtendedState(@Nonnull IBlockState state, IBlockAccess world, BlockPos pos) {
IExtendedBlockState extendedState = (IExtendedBlockState) state;
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileCauldron) {
return ((TileCauldron)te).writeExtendedBlockState(extendedState);
}
return super.getExtendedState(state, world, pos);
}
public static enum CauldronContents implements IStringSerializable {
FLUID,
DYE,
POTION;
private int meta;
CauldronContents() {
this.meta = ordinal();
}
@Override
public String getName() {
return name().toLowerCase(Locale.US);
}
public int getMeta() {
return meta;
}
public static CauldronContents fromMeta(int meta) {
if(meta > values().length) {
meta = 0;
}
return values()[meta];
}
}
}