Skip to content

Commit

Permalink
Add ENDER_EYE to entity_spec()
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Jul 1, 2018
1 parent bdb29c3 commit a278c72
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.laytonsmith.abstraction.bukkit.entities;

import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
import com.laytonsmith.abstraction.entities.MCEnderSignal;
import org.bukkit.Location;
import org.bukkit.entity.EnderSignal;
import org.bukkit.entity.Entity;

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

@Override
public int getDespawnTicks() {
return es.getDespawnTimer();
}

@Override
public void setDespawnTicks(int ticks) {
try {
es.setDespawnTimer(ticks);
} catch (NoSuchMethodError ex) {
// probably prior to 1.12.2
}
}

@Override
public boolean getDropItem() {
return es.getDropItem();
}

@Override
public void setDropItem(boolean drop) {
try {
es.setDropItem(drop);
} catch (NoSuchMethodError ex) {
// probably prior to 1.12.2
}
}

@Override
public MCLocation getTargetLocation() {
return new BukkitMCLocation(es.getTargetLocation());
}

@Override
public void setTargetLocation(MCLocation loc) {
try {
es.setTargetLocation((Location) loc.getHandle());
} catch (NoSuchMethodError ex) {
// probably prior to 1.12.2
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.laytonsmith.abstraction.entities;

import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.MCLocation;

public interface MCEnderSignal extends MCEntity {

int getDespawnTicks();
void setDespawnTicks(int ticks);
boolean getDropItem();
void setDropItem(boolean drop);
MCLocation getTargetLocation();
void setTargetLocation(MCLocation loc);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.laytonsmith.abstraction.entities.MCCommandMinecart;
import com.laytonsmith.abstraction.entities.MCCreeper;
import com.laytonsmith.abstraction.entities.MCEnderDragon;
import com.laytonsmith.abstraction.entities.MCEnderSignal;
import com.laytonsmith.abstraction.entities.MCEnderman;
import com.laytonsmith.abstraction.entities.MCEvokerFangs;
import com.laytonsmith.abstraction.entities.MCFallingBlock;
Expand Down Expand Up @@ -1849,6 +1850,14 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
}
}
break;
case ENDER_EYE:
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_12_X)) {
MCEnderSignal endereye = (MCEnderSignal) entity;
specArray.set(entity_spec.KEY_ENDEREYE_DESPAWNTICKS, new CInt(endereye.getDespawnTicks(), t), t);
specArray.set(entity_spec.KEY_ENDEREYE_DROP, CBoolean.get(endereye.getDropItem()), t);
specArray.set(entity_spec.KEY_ENDEREYE_TARGET, ObjectGenerator.GetGenerator().location(endereye.getTargetLocation(), false), t);
}
break;
case ENDER_DRAGON:
MCEnderDragon enderdragon = (MCEnderDragon) entity;
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9_X)) {
Expand Down Expand Up @@ -2113,6 +2122,9 @@ public CHVersion since() {
private static final String KEY_DROPPED_ITEM_PICKUPDELAY = "pickupdelay";
private static final String KEY_ENDERCRYSTAL_BASE = "base";
private static final String KEY_ENDERCRYSTAL_BEAMTARGET = "beamtarget";
private static final String KEY_ENDEREYE_DESPAWNTICKS = "despawnticks";
private static final String KEY_ENDEREYE_DROP = "drop";
private static final String KEY_ENDEREYE_TARGET = "target";
private static final String KEY_ENDERDRAGON_PHASE = "phase";
private static final String KEY_ENDERMAN_CARRIED = "carried";
private static final String KEY_EXPERIENCE_ORB_AMOUNT = "amount";
Expand Down Expand Up @@ -2181,7 +2193,7 @@ public String getName() {
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CRECastException.class, CREBadEntityException.class, CREIndexOverflowException.class,
CREIndexOverflowException.class, CRERangeException.class, CREFormatException.class,
CRELengthException.class};
CRELengthException.class, CREInvalidWorldException.class};
}

@Override
Expand Down Expand Up @@ -2482,6 +2494,32 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
}
}
break;
case ENDER_EYE:
MCEnderSignal endereye = (MCEnderSignal) entity;
// Order matters here. Target must be set first or it will reset despawn ticks and drop.
if(specArray.containsKey(entity_spec.KEY_ENDEREYE_TARGET)) {
Construct targetLoc = specArray.get(entity_spec.KEY_ENDEREYE_TARGET, t);
try {
endereye.setTargetLocation(ObjectGenerator.GetGenerator().location(targetLoc, null, t));
} catch (IllegalArgumentException ex) {
throw new CREInvalidWorldException("An EnderEye cannot target a location in another world.", t);
}
}
for(String index : specArray.stringKeySet()) {
switch(index.toLowerCase()) {
case entity_spec.KEY_ENDEREYE_DESPAWNTICKS:
endereye.setDespawnTicks(Static.getInt32(specArray.get(index, t), t));
break;
case entity_spec.KEY_ENDEREYE_DROP:
endereye.setDropItem(Static.getBoolean(specArray.get(index, t), t));
break;
case entity_spec.KEY_ENDEREYE_TARGET:
break;
default:
throwException(index, t);
}
}
break;
case ENDERMAN:
MCEnderman enderman = (MCEnderman) entity;
for(String index : specArray.stringKeySet()) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/functionDocs/entity_spec
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ without knowing the rotations on the other axis or of other body parts beforehan
|
* %KEY_ENDERDRAGON_PHASE%: What AI phase the EnderDragon is in. (can be %ENDERDRAGON_PHASE%)
|-
| ENDER_EYE
|
* %KEY_ENDEREYE_DESPAWNTICKS%: The number of ticks counted until despawn. (will despawn after 80 ticks)
* %KEY_ENDEREYE_DROP%: Whether or not the EnderEye will drop an item on despawn.
* %KEY_ENDEREYE_TARGET%: The target location array that the EnderEye will travel towards.
|-
| ENDERMAN
|
* %KEY_ENDERMAN_CARRIED%: The block that the Enderman is carring.
Expand Down

0 comments on commit a278c72

Please sign in to comment.