This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
SpawnTypeRock.java
118 lines (101 loc) · 4.33 KB
/
SpawnTypeRock.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
package lycanite.lycanitesmobs.api.spawning;
import java.util.List;
import lycanite.lycanitesmobs.ExtendedWorld;
import lycanite.lycanitesmobs.LycanitesMobs;
import lycanite.lycanitesmobs.api.config.ConfigBase;
import lycanite.lycanitesmobs.api.entity.EntityCreatureBase;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
public class SpawnTypeRock extends SpawnTypeBlockBreak {
public int blockBreakRadius = 1;
// ==================================================
// Constructor
// ==================================================
public SpawnTypeRock(String typeName) {
super(typeName);
}
// ==================================================
// Load from Config
// ==================================================
@Override
public void loadFromConfig() {
super.loadFromConfig();
ConfigBase config = ConfigBase.getConfig(LycanitesMobs.group, "spawning");
this.blockBreakRadius = config.getInt("Spawner Features", "Rock Spawn Block Break Radius", this.blockBreakRadius, "The block breaking radius aroud a mob spawned from the Rock Spawner.");
}
// ==================================================
// Block Harvest
// ==================================================
@Override
public boolean validBlockHarvest(Block block, World world, int x, int y, int z, Entity entity) {
if(!super.validBlockHarvest(block, world, x, y, z, entity))
return false;
String blockName = block.getUnlocalizedName();
String[] blockNameParts = blockName.split("\\.");
boolean isOre = false;
for(String blockNamePart : blockNameParts) {
int blockNamePartLength = blockNamePart.length();
if(blockNamePartLength >= 3) {
if(blockNamePart.substring(0, 3).equalsIgnoreCase("ore") || blockNamePart.substring(blockNamePartLength - 3, blockNamePartLength).equalsIgnoreCase("ore")) {
isOre = true;
break;
}
}
}
return isOre || block == Blocks.monster_egg;
}
// ==================================================
// Rare Block
// ==================================================
@Override
public boolean isRareBlock(Block block) {
if(block == Blocks.diamond_ore)
return true;
if(block == Blocks.emerald_ore)
return true;
return false;
}
// ==================================================
// Check Spawn Chance
// ==================================================
@Override
public boolean canSpawn(long tick, World world, int x, int y, int z, boolean rare) {
double roll = world.rand.nextDouble();
if(rare)
roll /= 4;
ExtendedWorld worldExt = ExtendedWorld.getForWorld(world);
if(worldExt != null) {
if("boulderdash".equalsIgnoreCase(worldExt.getWorldEventType()))
roll /= 4;
}
if(roll >= this.chance)
return false;
return true;
}
// ==================================================
// Order Coordinates
// ==================================================
@Override
public List<int[]> orderCoords(List<int[]> coords, int x, int y, int z) {
return this.orderCoordsCloseToFar(coords, x, y, z);
}
// ==================================================
// Spawn Entity
// ==================================================
/**
* Spawn an entity in the provided world. The mob should have already been positioned.
* @param world The world to spawn in.
* @param entityLiving The entity to spawn.
*/
@Override
public void spawnEntity(World world, EntityLiving entityLiving) {
super.spawnEntity(world, entityLiving);
if(entityLiving instanceof EntityCreatureBase && this.blockBreakRadius > -1) {
((EntityCreatureBase)entityLiving).destroyArea((int)entityLiving.posX, (int)entityLiving.posY, (int)entityLiving.posZ, 4, true, this.blockBreakRadius);
}
}
}