Skip to content

Commit 3109d11

Browse files
committed
Add ominous item spawner to entity_spec()
1 parent 19f7af5 commit 3109d11

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.laytonsmith.abstraction.bukkit.entities;
2+
3+
import com.laytonsmith.abstraction.MCItemStack;
4+
import com.laytonsmith.abstraction.bukkit.BukkitMCItemStack;
5+
import com.laytonsmith.abstraction.entities.MCOminousItemSpawner;
6+
import org.bukkit.entity.Entity;
7+
import org.bukkit.entity.OminousItemSpawner;
8+
import org.bukkit.inventory.ItemStack;
9+
10+
public class BukkitMCOminousItemSpawner extends BukkitMCEntity implements MCOminousItemSpawner {
11+
12+
OminousItemSpawner spawner;
13+
14+
public BukkitMCOminousItemSpawner(Entity e) {
15+
super(e);
16+
this.spawner = (OminousItemSpawner) e;
17+
}
18+
19+
@Override
20+
public MCItemStack getItem() {
21+
if(this.spawner.getItem() == null) {
22+
return null;
23+
}
24+
return new BukkitMCItemStack(this.spawner.getItem());
25+
}
26+
27+
@Override
28+
public void setItem(MCItemStack item) {
29+
if(item == null) {
30+
this.spawner.setItem(null);
31+
} else {
32+
this.spawner.setItem((ItemStack) item.getHandle());
33+
}
34+
}
35+
36+
@Override
37+
public long getDelay() {
38+
return this.spawner.getSpawnItemAfterTicks();
39+
}
40+
41+
@Override
42+
public void setDelay(long delay) {
43+
this.spawner.setSpawnItemAfterTicks(delay);
44+
}
45+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.laytonsmith.abstraction.entities;
2+
3+
import com.laytonsmith.abstraction.MCEntity;
4+
import com.laytonsmith.abstraction.MCItemStack;
5+
6+
public interface MCOminousItemSpawner extends MCEntity {
7+
8+
MCItemStack getItem();
9+
10+
void setItem(MCItemStack item);
11+
12+
long getDelay();
13+
14+
void setDelay(long delay);
15+
}

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.laytonsmith.abstraction.entities.MCLlama.MCLlamaColor;
6969
import com.laytonsmith.abstraction.entities.MCMinecart;
7070
import com.laytonsmith.abstraction.entities.MCMushroomCow;
71+
import com.laytonsmith.abstraction.entities.MCOminousItemSpawner;
7172
import com.laytonsmith.abstraction.entities.MCPainting;
7273
import com.laytonsmith.abstraction.entities.MCPanda;
7374
import com.laytonsmith.abstraction.entities.MCParrot;
@@ -2168,6 +2169,11 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
21682169
MCMushroomCow cow = (MCMushroomCow) entity;
21692170
specArray.set(entity_spec.KEY_MUSHROOM_COW_TYPE, cow.getVariant().name(), t);
21702171
break;
2172+
case OMINOUS_ITEM_SPAWNER:
2173+
MCOminousItemSpawner spawner = (MCOminousItemSpawner) entity;
2174+
specArray.set(entity_spec.KEY_OMINOUS_SPAWNER_ITEM, ObjectGenerator.GetGenerator().item(spawner.getItem(), t), t);
2175+
specArray.set(entity_spec.KEY_OMINOUS_SPAWNER_DELAY, new CInt(spawner.getDelay(), t), t);
2176+
break;
21712177
case PAINTING:
21722178
MCPainting painting = (MCPainting) entity;
21732179
specArray.set(entity_spec.KEY_PAINTING_ART, new CString(painting.getArt().name(), t), t);
@@ -2462,6 +2468,8 @@ public MSVersion since() {
24622468
private static final String KEY_MINECART_COMMAND_COMMAND = "command";
24632469
private static final String KEY_MINECART_COMMAND_CUSTOMNAME = "customname";
24642470
private static final String KEY_MUSHROOM_COW_TYPE = "type";
2471+
private static final String KEY_OMINOUS_SPAWNER_ITEM = "item";
2472+
private static final String KEY_OMINOUS_SPAWNER_DELAY = "delay";
24652473
private static final String KEY_PAINTING_ART = "type";
24662474
private static final String KEY_PANDA_MAINGENE = "maingene";
24672475
private static final String KEY_PANDA_HIDDENGENE = "hiddengene";
@@ -3460,6 +3468,21 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
34603468
}
34613469
}
34623470
break;
3471+
case OMINOUS_ITEM_SPAWNER:
3472+
MCOminousItemSpawner spawner = (MCOminousItemSpawner) entity;
3473+
for(String index : specArray.stringKeySet()) {
3474+
switch(index.toLowerCase()) {
3475+
case entity_spec.KEY_OMINOUS_SPAWNER_ITEM:
3476+
spawner.setItem(ObjectGenerator.GetGenerator().item(specArray.get(index, t), t));
3477+
break;
3478+
case entity_spec.KEY_OMINOUS_SPAWNER_DELAY:
3479+
spawner.setDelay(ArgumentValidation.getInt(specArray.get(index, t), t));
3480+
break;
3481+
default:
3482+
throwException(index, t);
3483+
}
3484+
}
3485+
break;
34633486
case PAINTING:
34643487
MCPainting painting = (MCPainting) entity;
34653488
for(String index : specArray.stringKeySet()) {

src/main/resources/functionDocs/entity_spec

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ without knowing the rotations on the other axis or of other body parts beforehan
215215
|
216216
* %KEY_MUSHROOM_COW_TYPE%: The type of mushroom cow. (can be %MUSHROOM_COW_TYPE%).
217217
|-
218+
| OMINOUS_ITEM_SPAWNER
219+
|
220+
* %KEY_OMINOUS_SPAWNER_ITEM%: The item that will be shown and then spawned after a delay (can be null). If the item is a projectile type, it will be shot as one downwards.
221+
* %KEY_OMINOUS_SPAWNER_DELAY%: The number of ticks before the item will be spawned. (will play "about_to_spawn_item" sound at 37 ticks)
222+
|-
218223
| PAINTING
219224
|
220225
* %KEY_PAINTING_ART%: The art on the painting (can be %ART%).

0 commit comments

Comments
 (0)