Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add get|set_projectile_item()
  • Loading branch information
PseudoKnight committed Feb 13, 2021
1 parent e501e6a commit 4d95cea
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 0 deletions.
Expand Up @@ -53,7 +53,9 @@
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCMinecart;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCProjectile;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCSizedFireball;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCTameable;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCItemProjectile;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCVehicle;
import com.laytonsmith.abstraction.bukkit.events.BukkitAbstractEventMixin;
import com.laytonsmith.abstraction.bukkit.events.drivers.BukkitBlockListener;
Expand Down Expand Up @@ -124,7 +126,9 @@
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.SizedFireball;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrowableProjectile;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.minecart.CommandMinecart;
import org.bukkit.inventory.BlastingRecipe;
Expand Down Expand Up @@ -407,12 +411,24 @@ public static MCEntity BukkitGetCorrectEntity(Entity be) {
return new BukkitMCMinecart(be);
}

if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_15_X) && be instanceof SizedFireball) {
// Must come before Fireball
type.setWrapperClass(BukkitMCSizedFireball.class);
return new BukkitMCSizedFireball(be);
}

if(be instanceof Fireball) {
// Must come before Projectile
type.setWrapperClass(BukkitMCFireball.class);
return new BukkitMCFireball(be);
}

if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_15_X) && be instanceof ThrowableProjectile) {
// Must come before Projectile
type.setWrapperClass(BukkitMCItemProjectile.class);
return new BukkitMCItemProjectile(be);
}

if(be instanceof Projectile) {
type.setWrapperClass(BukkitMCProjectile.class);
return new BukkitMCProjectile(be);
Expand Down
@@ -0,0 +1,25 @@
package com.laytonsmith.abstraction.bukkit.entities;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.bukkit.BukkitMCItemStack;
import com.laytonsmith.abstraction.entities.MCItemProjectile;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ThrowableProjectile;
import org.bukkit.inventory.ItemStack;

public class BukkitMCItemProjectile extends BukkitMCProjectile implements MCItemProjectile {

public BukkitMCItemProjectile(Entity be) {
super(be);
}

@Override
public MCItemStack getItem() {
return new BukkitMCItemStack(((ThrowableProjectile) getHandle()).getItem());
}

@Override
public void setItem(MCItemStack item) {
((ThrowableProjectile) getHandle()).setItem((ItemStack) item.getHandle());
}
}
@@ -0,0 +1,25 @@
package com.laytonsmith.abstraction.bukkit.entities;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.bukkit.BukkitMCItemStack;
import com.laytonsmith.abstraction.entities.MCItemProjectile;
import org.bukkit.entity.Entity;
import org.bukkit.entity.SizedFireball;
import org.bukkit.inventory.ItemStack;

public class BukkitMCSizedFireball extends BukkitMCFireball implements MCItemProjectile {

public BukkitMCSizedFireball(Entity be) {
super(be);
}

@Override
public MCItemStack getItem() {
return new BukkitMCItemStack(((SizedFireball) getHandle()).getDisplayItem());
}

@Override
public void setItem(MCItemStack item) {
((SizedFireball) getHandle()).setDisplayItem((ItemStack) item.getHandle());
}
}
@@ -0,0 +1,9 @@
package com.laytonsmith.abstraction.entities;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCMetadatable;

public interface MCItemProjectile extends MCProjectile, MCMetadatable {
MCItemStack getItem();
void setItem(MCItemStack item);
}
Expand Up @@ -3,16 +3,19 @@
import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCCommandMinecart;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCEnderSignal;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCFireball;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCFishHook;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCHopperMinecart;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCItem;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCLightningStrike;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCLlama;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPigZombie;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCSizedFireball;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCStorageMinecart;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCTNT;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCThrownPotion;
import com.laytonsmith.abstraction.enums.MCEntityType;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.core.MSLog;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
Expand Down Expand Up @@ -121,6 +124,13 @@ private void setWrapperClass() {
case ENDER_EYE:
wrapperClass = BukkitMCEnderSignal.class;
break;
case FIREBALL:
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_15_X)) {
wrapperClass = BukkitMCSizedFireball.class;
} else {
wrapperClass = BukkitMCFireball.class;
}
break;
case FISHING_HOOK:
wrapperClass = BukkitMCFishHook.class;
break;
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/EntityManagement.java
Expand Up @@ -50,6 +50,7 @@
import com.laytonsmith.abstraction.entities.MCIronGolem;
import com.laytonsmith.abstraction.entities.MCItem;
import com.laytonsmith.abstraction.entities.MCItemFrame;
import com.laytonsmith.abstraction.entities.MCItemProjectile;
import com.laytonsmith.abstraction.entities.MCLightningStrike;
import com.laytonsmith.abstraction.entities.MCLlama;
import com.laytonsmith.abstraction.entities.MCLlama.MCLlamaColor;
Expand Down Expand Up @@ -3732,6 +3733,69 @@ public MSVersion since() {
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class get_projectile_item extends EntityGetterFunction {

@Override
public String getName() {
return "get_projectile_item";
}

@Override
public String docs() {
return "array {entityUUID} Returns the displayed item for some projectiles."
+ " This can be used on throwable projectiles (snowballs, eggs, exp bottles, enderpearls)"
+ " as well as large and small fireballs.";
}

@Override
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
MCEntity entity = Static.getEntity(args[0], t);
if(entity instanceof MCItemProjectile) {
return ObjectGenerator.GetGenerator().item(((MCItemProjectile) entity).getItem(), t);
} else {
throw new CREBadEntityException("The given entity does not have a display item.", t);
}
}

@Override
public MSVersion since() {
return MSVersion.V3_3_4;
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class set_projectile_item extends EntitySetterFunction {

@Override
public String getName() {
return "set_projectile_item";
}

@Override
public String docs() {
return "void {entityUUID, itemArray} Sets the displayed item for some projectiles."
+ " This can be used on throwable projectiles (snowballs, eggs, exp bottles, enderpearls)"
+ " as well as large and small fireballs.";
}

@Override
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
MCEntity entity = Static.getEntity(args[0], t);
if(entity instanceof MCItemProjectile) {
((MCItemProjectile) entity).setItem(ObjectGenerator.GetGenerator().item(args[1], t));
} else {
throw new CREBadEntityException("The given entity does not have a display item.", t);
}
return CVoid.VOID;
}

@Override
public MSVersion since() {
return MSVersion.V3_3_4;
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class entity_fall_distance extends EntityGetterFunction {

Expand Down

0 comments on commit 4d95cea

Please sign in to comment.