/
JFallingBlock.java
123 lines (105 loc) · 3.51 KB
/
JFallingBlock.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
package fr.Jodge.jodgeLibrary.common.block;
import fr.Jodge.jodgeLibrary.common.JCommonCreate;
import fr.Jodge.jodgeLibrary.common.Main;
import fr.Jodge.jodgeLibrary.common.entity.JEntityFallingBlock;
import fr.Jodge.jodgeLibrary.common.function.JFunction;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.BlockStaticLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author Jodge
*
*/
public class JFallingBlock extends BlockFalling implements JCommonCreate
{
public String oreDictionaryName;
public boolean canDownInLiquid = true;
public JFallingBlock(Material material, String name, String modid)
{
this(material, name, modid, "");
}
public JFallingBlock(Material material, String name, String modid, String oreDictionnaryName)
{
this(material, name, modid, modid, name, oreDictionnaryName);
}
public JFallingBlock(Material material, String name, String modid, String textureModid, String textureName)
{
this(material, name, modid, textureModid, textureName, "");
}
public JFallingBlock(Material material, String name, String modid, String textureModid, String textureName, String oreDictionnaryName)
{
super(material);
JFunction.commonInit(name, modid, this, textureModid, textureName, oreDictionnaryName);
}
public JFallingBlock CanDownOnWater(boolean canDownOnWater)
{
canDownInLiquid = canDownOnWater;
return this;
}
public boolean canFallIntoBlock(World worldIn, BlockPos pos)
{
if (worldIn.isAirBlock(pos)) return true;
Block block = worldIn.getBlockState(pos).getBlock();
Material material = block.getMaterial();
return block == Blocks.fire || material == Material.air || material == Material.water || material == Material.lava;
}
public static boolean canFall(World worldIn, BlockPos pos, JFallingBlock originalBlock)
{
return originalBlock.canFallIntoBlock(worldIn, pos);
}
public void checkFallable(World worldIn, BlockPos pos)
{
if (canFallIntoBlock(worldIn, pos.down()) && pos.getY() >= 0)
{
byte b0 = 32;
if (!fallInstantly && worldIn.isAreaLoaded(pos.add(-b0, -b0, -b0), pos.add(b0, b0, b0)))
{
if (!worldIn.isRemote)
{
EntityFallingBlock entityfallingblock = new JEntityFallingBlock(worldIn, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, worldIn.getBlockState(pos), 1.0F, false, true).CanDownOnWater(canDownInLiquid);
onStartFalling(entityfallingblock);
worldIn.spawnEntityInWorld(entityfallingblock);
}
}
else
{
worldIn.setBlockToAir(pos);
BlockPos blockpos1 = pos.down();
Block blockWhereFall;
while (true)
{
blockpos1 = blockpos1.down();
blockWhereFall = worldIn.getBlockState(blockpos1).getBlock();
if ( !(canFallIntoBlock(worldIn, blockpos1) && blockpos1.getY() > 0))
{
break;
}
}
if (blockpos1.getY() > 0)
{
worldIn.setBlockState(blockpos1.up(), getDefaultState());
}
}
}
}
public String getOreDic()
{
return getOreDictionaryName();
}
public String getOreDictionaryName()
{
return oreDictionaryName;
}
public void setOreDictionaryName(String oreDictionaryName)
{
this.oreDictionaryName = oreDictionaryName;
}
}