Skip to content

Commit a278c72

Browse files
committed
Add ENDER_EYE to entity_spec()
1 parent bdb29c3 commit a278c72

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEnderSignal.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.laytonsmith.abstraction.bukkit.entities;
22

3+
import com.laytonsmith.abstraction.MCLocation;
4+
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
35
import com.laytonsmith.abstraction.entities.MCEnderSignal;
6+
import org.bukkit.Location;
47
import org.bukkit.entity.EnderSignal;
58
import org.bukkit.entity.Entity;
69

@@ -13,4 +16,45 @@ public BukkitMCEnderSignal(Entity e) {
1316
this.es = (EnderSignal) e;
1417
}
1518

19+
@Override
20+
public int getDespawnTicks() {
21+
return es.getDespawnTimer();
22+
}
23+
24+
@Override
25+
public void setDespawnTicks(int ticks) {
26+
try {
27+
es.setDespawnTimer(ticks);
28+
} catch (NoSuchMethodError ex) {
29+
// probably prior to 1.12.2
30+
}
31+
}
32+
33+
@Override
34+
public boolean getDropItem() {
35+
return es.getDropItem();
36+
}
37+
38+
@Override
39+
public void setDropItem(boolean drop) {
40+
try {
41+
es.setDropItem(drop);
42+
} catch (NoSuchMethodError ex) {
43+
// probably prior to 1.12.2
44+
}
45+
}
46+
47+
@Override
48+
public MCLocation getTargetLocation() {
49+
return new BukkitMCLocation(es.getTargetLocation());
50+
}
51+
52+
@Override
53+
public void setTargetLocation(MCLocation loc) {
54+
try {
55+
es.setTargetLocation((Location) loc.getHandle());
56+
} catch (NoSuchMethodError ex) {
57+
// probably prior to 1.12.2
58+
}
59+
}
1660
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package com.laytonsmith.abstraction.entities;
22

33
import com.laytonsmith.abstraction.MCEntity;
4+
import com.laytonsmith.abstraction.MCLocation;
45

56
public interface MCEnderSignal extends MCEntity {
6-
7+
int getDespawnTicks();
8+
void setDespawnTicks(int ticks);
9+
boolean getDropItem();
10+
void setDropItem(boolean drop);
11+
MCLocation getTargetLocation();
12+
void setTargetLocation(MCLocation loc);
713
}

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.laytonsmith.abstraction.entities.MCCommandMinecart;
4141
import com.laytonsmith.abstraction.entities.MCCreeper;
4242
import com.laytonsmith.abstraction.entities.MCEnderDragon;
43+
import com.laytonsmith.abstraction.entities.MCEnderSignal;
4344
import com.laytonsmith.abstraction.entities.MCEnderman;
4445
import com.laytonsmith.abstraction.entities.MCEvokerFangs;
4546
import com.laytonsmith.abstraction.entities.MCFallingBlock;
@@ -1849,6 +1850,14 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
18491850
}
18501851
}
18511852
break;
1853+
case ENDER_EYE:
1854+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_12_X)) {
1855+
MCEnderSignal endereye = (MCEnderSignal) entity;
1856+
specArray.set(entity_spec.KEY_ENDEREYE_DESPAWNTICKS, new CInt(endereye.getDespawnTicks(), t), t);
1857+
specArray.set(entity_spec.KEY_ENDEREYE_DROP, CBoolean.get(endereye.getDropItem()), t);
1858+
specArray.set(entity_spec.KEY_ENDEREYE_TARGET, ObjectGenerator.GetGenerator().location(endereye.getTargetLocation(), false), t);
1859+
}
1860+
break;
18521861
case ENDER_DRAGON:
18531862
MCEnderDragon enderdragon = (MCEnderDragon) entity;
18541863
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9_X)) {
@@ -2113,6 +2122,9 @@ public CHVersion since() {
21132122
private static final String KEY_DROPPED_ITEM_PICKUPDELAY = "pickupdelay";
21142123
private static final String KEY_ENDERCRYSTAL_BASE = "base";
21152124
private static final String KEY_ENDERCRYSTAL_BEAMTARGET = "beamtarget";
2125+
private static final String KEY_ENDEREYE_DESPAWNTICKS = "despawnticks";
2126+
private static final String KEY_ENDEREYE_DROP = "drop";
2127+
private static final String KEY_ENDEREYE_TARGET = "target";
21162128
private static final String KEY_ENDERDRAGON_PHASE = "phase";
21172129
private static final String KEY_ENDERMAN_CARRIED = "carried";
21182130
private static final String KEY_EXPERIENCE_ORB_AMOUNT = "amount";
@@ -2181,7 +2193,7 @@ public String getName() {
21812193
public Class<? extends CREThrowable>[] thrown() {
21822194
return new Class[]{CRECastException.class, CREBadEntityException.class, CREIndexOverflowException.class,
21832195
CREIndexOverflowException.class, CRERangeException.class, CREFormatException.class,
2184-
CRELengthException.class};
2196+
CRELengthException.class, CREInvalidWorldException.class};
21852197
}
21862198

21872199
@Override
@@ -2482,6 +2494,32 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
24822494
}
24832495
}
24842496
break;
2497+
case ENDER_EYE:
2498+
MCEnderSignal endereye = (MCEnderSignal) entity;
2499+
// Order matters here. Target must be set first or it will reset despawn ticks and drop.
2500+
if(specArray.containsKey(entity_spec.KEY_ENDEREYE_TARGET)) {
2501+
Construct targetLoc = specArray.get(entity_spec.KEY_ENDEREYE_TARGET, t);
2502+
try {
2503+
endereye.setTargetLocation(ObjectGenerator.GetGenerator().location(targetLoc, null, t));
2504+
} catch (IllegalArgumentException ex) {
2505+
throw new CREInvalidWorldException("An EnderEye cannot target a location in another world.", t);
2506+
}
2507+
}
2508+
for(String index : specArray.stringKeySet()) {
2509+
switch(index.toLowerCase()) {
2510+
case entity_spec.KEY_ENDEREYE_DESPAWNTICKS:
2511+
endereye.setDespawnTicks(Static.getInt32(specArray.get(index, t), t));
2512+
break;
2513+
case entity_spec.KEY_ENDEREYE_DROP:
2514+
endereye.setDropItem(Static.getBoolean(specArray.get(index, t), t));
2515+
break;
2516+
case entity_spec.KEY_ENDEREYE_TARGET:
2517+
break;
2518+
default:
2519+
throwException(index, t);
2520+
}
2521+
}
2522+
break;
24852523
case ENDERMAN:
24862524
MCEnderman enderman = (MCEnderman) entity;
24872525
for(String index : specArray.stringKeySet()) {

src/main/resources/functionDocs/entity_spec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ without knowing the rotations on the other axis or of other body parts beforehan
7070
|
7171
* %KEY_ENDERDRAGON_PHASE%: What AI phase the EnderDragon is in. (can be %ENDERDRAGON_PHASE%)
7272
|-
73+
| ENDER_EYE
74+
|
75+
* %KEY_ENDEREYE_DESPAWNTICKS%: The number of ticks counted until despawn. (will despawn after 80 ticks)
76+
* %KEY_ENDEREYE_DROP%: Whether or not the EnderEye will drop an item on despawn.
77+
* %KEY_ENDEREYE_TARGET%: The target location array that the EnderEye will travel towards.
78+
|-
7379
| ENDERMAN
7480
|
7581
* %KEY_ENDERMAN_CARRIED%: The block that the Enderman is carring.

0 commit comments

Comments
 (0)