Implemented several more events for players, including a click event, key event, fall event, and the basic entity living hurt, killed, and kills events, among others.

This commit is contained in:
luisc committed 2021-10-12 02:57:32 -05:00
1 parent 6c8c7671b8
commit 6752f8baec
38 files changed
+763 -249

No files matched your search

@@ -0,0 +1,11 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import net.minecraft.entity.passive.EntityAnimal;
public interface IAnimal<T extends EntityAnimal> extends IEntityLiving<T> {
}
@@ -0,0 +1,41 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
public interface IBlock {
int getX();
int getY();
int getZ();
IPos getPos();
String getName();
void remove();
boolean isAir();
IBlock setBlock(String var1);
IBlock setBlock(IBlock var1);
boolean isContainer();
IContainer getContainer();
IWorld getWorld();
TileEntity getMCTileEntity();
Block getMCBlock();
String getDisplayName();
}
@@ -18,7 +18,7 @@ import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.roles.*;
import noppes.npcs.util.ValueUtil;
public interface ICustomNpc<T extends EntityCreature> {
public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
/**
* @return Returns the current npcs size 1-30
*/
@@ -322,5 +322,5 @@ public interface IEntity<T extends Entity> {
* Expert users only
* @return Returns minecrafts entity
*/
public Entity getMCEntity();
public T getMCEntity();
}
@@ -0,0 +1,18 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import net.minecraft.entity.EntityLiving;
public interface IEntityLiving<T extends EntityLiving> extends IEntityLivingBase<T> {
boolean isNavigating();
void clearNavigation();
void navigateTo(double var1, double var3, double var5, double var7);
T getMCEntity();
}
@@ -7,7 +7,7 @@ import net.minecraft.potion.PotionEffect;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.constants.EntityType;
public interface IEntityLivingBase {
public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T> {
/**
* @return The entity's current health
*/
@@ -51,7 +51,7 @@ public interface IEntityLivingBase {
* Expert use only
* @return Returns the minecraft entity object
*/
public EntityLivingBase getMinecraftEntity();
public T getMCEntity();
/**
* Makes the entity swing its hand
@@ -0,0 +1,11 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import net.minecraft.entity.monster.EntityMob;
public interface IMonster<T extends EntityMob> extends IEntityLiving<T> {
}
@@ -0,0 +1,11 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import net.minecraft.entity.passive.EntityTameable;
public interface IPixelmon<T extends EntityTameable> extends IAnimal<T> {
}
@@ -18,7 +18,7 @@ import noppes.npcs.controllers.*;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.util.ValueUtil;
public interface IPlayer {
public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T> {
/**
* @return Returns the displayed name of the player
*/
@@ -0,0 +1,58 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import net.minecraft.util.math.BlockPos;
public interface IPos {
int getX();
int getY();
int getZ();
IPos up();
IPos up(int var1);
IPos down();
IPos down(int var1);
IPos north();
IPos north(int var1);
IPos east();
IPos east(int var1);
IPos south();
IPos south(int var1);
IPos west();
IPos west(int var1);
IPos add(int var1, int var2, int var3);
IPos add(IPos var1);
IPos subtract(int var1, int var2, int var3);
IPos subtract(IPos var1);
double[] normalize();
BlockPos getMCBlockPos();
IPos offset(int var1);
IPos offset(int var1, int var2);
double distanceTo(IPos var1);
}
@@ -31,6 +31,8 @@ public abstract class NpcAPI {
public abstract IEntity getIEntity(Entity var1);
public abstract IBlock getIBlock(World var1, BlockPos var2);
public abstract IContainer getIContainer(IInventory var1);
public abstract IContainer getIContainer(Container var1);
@@ -3,9 +3,9 @@ package noppes.npcs.scripted;
import net.minecraft.entity.passive.EntityAnimal;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptAnimal extends ScriptLiving{
public class ScriptAnimal<T extends EntityAnimal> extends ScriptLiving<T> implements IAnimal {
public ScriptAnimal(EntityAnimal entity) {
public ScriptAnimal(T entity) {
super(entity);
}
@@ -0,0 +1,112 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import noppes.npcs.util.LRUHashMap;
public class ScriptBlock implements IBlock {
private static final Map<String, ScriptBlock> blockCache = new LRUHashMap(400);
protected final IWorld world;
protected final Block block;
protected final BlockPos pos;
protected final ScriptBlockPos bPos;
protected TileEntity tile;
public ScriptBlock(World world, Block block, BlockPos pos) {
this.world = NpcAPI.Instance().getIWorld((WorldServer)world);
this.block = block;
this.pos = pos;
this.bPos = new ScriptBlockPos(pos);
}
public IPos getPos() {
return this.bPos;
}
public int getX() {
return this.pos.getX();
}
public int getY() {
return this.pos.getY();
}
public int getZ() {
return this.pos.getZ();
}
public void remove() {
this.world.getMCWorld().setBlockToAir(getX(), getY(), getZ());
}
public boolean isAir() {
return this.block.isAir(this.world.getMCWorld(), getX(), getY(), getZ());
}
public ScriptBlock setBlock(String name) {
Block block = (Block)Block.blockRegistry.getObject(new ResourceLocation(name));
if(block == null) {
return this;
} else {
this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block);
return new ScriptBlock(this.world.getMCWorld(), block, this.pos);
}
}
public ScriptBlock setBlock(IBlock block) {
this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block.getMCBlock());
return new ScriptBlock(this.world.getMCWorld(), block.getMCBlock(), this.pos);
}
public boolean isContainer() {
return this.tile != null && this.tile instanceof IInventory?((IInventory)this.tile).getSizeInventory() > 0:false;
}
public IContainer getContainer() {
if(!this.isContainer()) {
throw new CustomNPCsException("This block is not a container", new Object[0]);
} else {
return NpcAPI.Instance().getIContainer((IInventory)this.tile);
}
}
public String getName() {
return Block.blockRegistry.getNameForObject(this.block) + "";
}
public String getDisplayName() {
return this.tile == null?this.getName():this.tile.blockType.getItemIconName();
}
public IWorld getWorld() {
return this.world;
}
public Block getMCBlock() {
return this.block;
}
public static void clearCache() {
blockCache.clear();
}
public boolean hasTileEntity() {
return this.tile != null;
}
public TileEntity getMCTileEntity() {
return this.tile;
}
}
@@ -0,0 +1,117 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
public class ScriptBlockPos implements IPos {
private BlockPos blockPos;
public ScriptBlockPos(BlockPos pos) {
this.blockPos = pos;
}
public int getX() {
return this.blockPos.getX();
}
public int getY() {
return this.blockPos.getY();
}
public int getZ() {
return this.blockPos.getZ();
}
public IPos up() {
return new ScriptBlockPos(this.blockPos.up());
}
public IPos up(int n) {
return new ScriptBlockPos(this.blockPos.up(n));
}
public IPos down() {
return new ScriptBlockPos(this.blockPos.down());
}
public IPos down(int n) {
return new ScriptBlockPos(this.blockPos.down(n));
}
public IPos north() {
return new ScriptBlockPos(this.blockPos.north());
}
public IPos north(int n) {
return new ScriptBlockPos(this.blockPos.north(n));
}
public IPos east() {
return new ScriptBlockPos(this.blockPos.east());
}
public IPos east(int n) {
return new ScriptBlockPos(this.blockPos.east(n));
}
public IPos south() {
return new ScriptBlockPos(this.blockPos.south());
}
public IPos south(int n) {
return new ScriptBlockPos(this.blockPos.south(n));
}
public IPos west() {
return new ScriptBlockPos(this.blockPos.west());
}
public IPos west(int n) {
return new ScriptBlockPos(this.blockPos.west(n));
}
public IPos add(int x, int y, int z) {
return new ScriptBlockPos(this.blockPos.add(x, y, z));
}
public IPos add(IPos pos) {
return new ScriptBlockPos(this.blockPos.add(pos.getMCBlockPos()));
}
public IPos subtract(int x, int y, int z) {
return new ScriptBlockPos(this.blockPos.add(-x, -y, -z));
}
public IPos subtract(IPos pos) {
return new ScriptBlockPos(this.blockPos.add(-pos.getX(), -pos.getY(), -pos.getZ()));
}
public IPos offset(int direction) {
return new ScriptBlockPos(this.blockPos.offset(EnumFacing.values()[direction]));
}
public IPos offset(int direction, int n) {
return new ScriptBlockPos(this.blockPos.offset(EnumFacing.values()[direction], n));
}
public BlockPos getMCBlockPos() {
return this.blockPos;
}
public double[] normalize() {
double d = Math.sqrt((double)(this.blockPos.getX() * this.blockPos.getX() + this.blockPos.getY() * this.blockPos.getY() + this.blockPos.getZ() * this.blockPos.getZ()));
return new double[]{(double)this.getX() / d, (double)this.getY() / d, (double)this.getZ() / d};
}
public double distanceTo(IPos pos) {
double d0 = (double)(this.getX() - pos.getX());
double d1 = (double)(this.getY() - pos.getY());
double d2 = (double)(this.getZ() - pos.getZ());
return Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
}
}
@@ -27,11 +27,11 @@ import noppes.npcs.controllers.ScriptController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEntity implements IEntity{
protected Entity entity;
public class ScriptEntity<T extends Entity> implements IEntity{
protected T entity;
private Map<String,Object> tempData = new HashMap<String,Object>();
public ScriptEntity(Entity entity){
public ScriptEntity(T entity){
this.entity = entity;
}
@@ -483,7 +483,7 @@ public class ScriptEntity implements IEntity{
* Expert users only
* @return Returns minecrafts entity
*/
public Entity getMCEntity(){
public T getMCEntity(){
return entity;
}
}
@@ -8,10 +8,10 @@ import net.minecraft.item.ItemStack;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptLiving extends ScriptLivingBase{
public class ScriptLiving<T extends EntityLiving> extends ScriptLivingBase<T> implements IEntityLiving {
private EntityLiving entity;
public ScriptLiving(EntityLiving entity) {
private T entity;
public ScriptLiving(T entity) {
super(entity);
this.entity = entity;
}
@@ -21,10 +21,10 @@ import net.minecraft.util.MathHelper;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase{
protected EntityLivingBase entity;
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase{
protected T entity;
public ScriptLivingBase(EntityLivingBase entity){
public ScriptLivingBase(T entity){
super(entity);
this.entity = entity;
}
@@ -95,7 +95,7 @@ public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase{
* Expert use only
* @return Returns the minecraft entity object
*/
public EntityLivingBase getMinecraftEntity(){
public T getMCEntity(){
return entity;
}
@@ -4,9 +4,9 @@ import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.EntityMob;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptMonster extends ScriptLiving{
public class ScriptMonster<T extends EntityMob> extends ScriptLiving<T> implements IMonster {
public ScriptMonster(EntityMob entity) {
public ScriptMonster(T entity) {
super(entity);
}
@@ -31,10 +31,10 @@ import noppes.npcs.scripted.roles.ScriptRoleTrader;
import noppes.npcs.scripted.roles.ScriptRoleTransporter;
import noppes.npcs.util.ValueUtil;
public class ScriptNpc extends ScriptLiving implements ICustomNpc{
public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> implements ICustomNpc {
protected EntityCustomNpc npc;
public ScriptNpc(EntityNPCInterface npc){
public ScriptNpc(T npc){
super(npc);
this.npc = (EntityCustomNpc)npc;
}
@@ -6,16 +6,16 @@ import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.PixelmonHelper;
import noppes.npcs.util.ValueUtil;
public class ScriptPixelmon extends ScriptAnimal{
private EntityTameable pixelmon;
public class ScriptPixelmon<T extends EntityTameable> extends ScriptAnimal<T> implements IPixelmon {
private T pixelmon;
private NBTTagCompound compound = null;
public ScriptPixelmon(EntityTameable pixelmon){
public ScriptPixelmon(T pixelmon){
super(pixelmon);
this.pixelmon = pixelmon;
compound = new NBTTagCompound();
pixelmon.writeEntityToNBT(compound);
}
public ScriptPixelmon(EntityTameable pixelmon, NBTTagCompound compound){
public ScriptPixelmon(T pixelmon, NBTTagCompound compound){
this(pixelmon);
this.compound = compound;
}
@@ -25,9 +25,9 @@ import noppes.npcs.controllers.QuestData;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.util.ValueUtil;
public class ScriptPlayer extends ScriptLivingBase implements IPlayer{
protected EntityPlayerMP player;
public ScriptPlayer(EntityPlayerMP player){
public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T> implements IPlayer {
protected T player;
public ScriptPlayer(T player){
super(player);
this.player = player;
}
@@ -9,14 +9,10 @@ import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import noppes.npcs.scripted.IContainer;
import noppes.npcs.scripted.IDamageSource;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.IEntity;
import noppes.npcs.scripted.IEntityLivingBase;
import noppes.npcs.scripted.IPlayer;
import noppes.npcs.scripted.IItemStack;
import noppes.npcs.scripted.*;
public class PlayerEvent extends CustomNPCsEvent {
public final IPlayer player;
@@ -52,6 +48,26 @@ public class PlayerEvent extends CustomNPCsEvent {
}
}
public static class MouseClickedEvent extends PlayerEvent {
public final int button;
public final int mouseWheel;
public MouseClickedEvent(IPlayer player, int button, int mouseWheel){
super(player);
this.button = button;
this.mouseWheel = mouseWheel;
}
}
public static class PickupXPEvent extends PlayerEvent {
public final int amount;
public PickupXPEvent(IPlayer player, EntityXPOrb orb) {
super(player);
this.amount = orb.xpValue;
}
}
public static class LevelUpEvent extends PlayerEvent {
public final int change;
@@ -97,12 +113,21 @@ public class PlayerEvent extends CustomNPCsEvent {
}
}
public static class FallEvent extends PlayerEvent {
public final float distance;
public FallEvent(IPlayer player, float distance){
super(player);
this.distance = distance;
}
}
public static class KilledEntityEvent extends PlayerEvent {
public final IEntityLivingBase entity;
public KilledEntityEvent(IPlayer player, EntityLivingBase entity) {
super(player);
this.entity = (IEntityLivingBase)NpcAPI.Instance().getIEntity(entity);
this.entity = new ScriptLivingBase<>(entity);//NpcAPI.Instance().getIEntity(entity);
}
}
@@ -122,8 +147,13 @@ public class PlayerEvent extends CustomNPCsEvent {
@Cancelable
public static class RangedLaunchedEvent extends PlayerEvent {
public RangedLaunchedEvent(IPlayer player) {
public final IItemStack bow;
public int charge;
public RangedLaunchedEvent(IPlayer player, ItemStack bow, int charge) {
super(player);
this.bow = NpcAPI.Instance().getIItemStack(bow);
this.charge = charge;
}
}
@@ -171,11 +201,11 @@ public class PlayerEvent extends CustomNPCsEvent {
@Cancelable
public static class TossEvent extends PlayerEvent {
public final IItemStack item;
public final IItemStack[] items;
public TossEvent(IPlayer player, IItemStack item) {
public TossEvent(IPlayer player, IItemStack[] items) {
super(player);
this.item = item;
this.items = items;
}
}
@@ -214,4 +244,61 @@ public class PlayerEvent extends CustomNPCsEvent {
super(player);
}
}
public static class StartUsingItem extends PlayerEvent {
public final IItemStack item;
public final int duration;
public StartUsingItem(IPlayer player, ItemStack item, int duration){
super(player);
this.item = NpcAPI.Instance().getIItemStack(item);
this.duration = duration;
}
}
public static class UsingItem extends PlayerEvent {
public final IItemStack item;
public final int duration;
public UsingItem(IPlayer player, ItemStack item, int duration){
super(player);
this.item = NpcAPI.Instance().getIItemStack(item);
this.duration = duration;
}
}
public static class StopUsingItem extends PlayerEvent {
public final IItemStack item;
public final int duration;
public StopUsingItem(IPlayer player, ItemStack item, int duration){
super(player);
this.item = NpcAPI.Instance().getIItemStack(item);
this.duration = duration;
}
}
public static class FinishUsingItem extends PlayerEvent {
public final IItemStack item;
public final int duration;
public FinishUsingItem(IPlayer player, ItemStack item, int duration){
super(player);
this.item = NpcAPI.Instance().getIItemStack(item);
this.duration = duration;
}
}
@Cancelable
public static class BreakEvent extends PlayerEvent {
public final IBlock block;
public int exp;
public BreakEvent(IPlayer player, IBlock block, int exp) {
super(player);
this.block = block;
this.exp = exp;
}
}
}
@@ -1,7 +1,6 @@
package noppes.npcs.scripted.roles;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.JobGuard;
import noppes.npcs.roles.JobHealer;
import noppes.npcs.scripted.ScriptLivingBase;
import noppes.npcs.scripted.constants.JobType;
@@ -14,7 +13,7 @@ public class ScriptJobHealer extends ScriptJobInterface{
}
public void heal(ScriptLivingBase entity, float amount){
job.heal(entity.getMinecraftEntity(), amount);
job.heal(entity.getMCEntity(), amount);
}
@Override
@@ -19,11 +19,11 @@ public class ScriptRoleFollower extends ScriptRoleInterface{
* @param player Player who is set as the owner. If null given everything resets
*/
public void setOwner(ScriptPlayer player){
if(player == null || player.getMinecraftEntity() == null){
if(player == null || player.getMCEntity() == null){
role.setOwner(null);
return;
}
EntityPlayer mcplayer = (EntityPlayer) player.getMinecraftEntity();
EntityPlayer mcplayer = (EntityPlayer) player.getMCEntity();
role.setOwner(mcplayer);
}
@@ -59,6 +59,10 @@ public class WrapperNpcAPI extends NpcAPI {
}
}
public IBlock getIBlock(World world, BlockPos pos) {
return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos);
}
public ICustomNpc createNPC(World world) {
if (world.isRemote) {
return null;