Implemented scripted block event interfaces

This commit is contained in:
Goodbird committed 2024-01-21 10:55:40 +03:00
1 parent 654ea09152
commit dbdf559cf6
1 file changed
+246
@@ -0,0 +1,246 @@
package noppes.npcs.scripted.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.api.IBlock;
import noppes.npcs.api.IPos;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.event.IBlockEvent;
import noppes.npcs.scripted.NpcAPI;
public class BlockEvent extends CustomNPCsEvent implements IBlockEvent {
public IBlock block;
public BlockEvent(IBlock block){
this.block = block;
}
@Override
public IBlock getBlock() {
return null;
}
/**
* fallenUpon
*/
@Cancelable
public static class EntityFallenUponEvent extends BlockEvent implements IBlockEvent.EntityFallenUponEvent{
public final IEntity entity;
public float distanceFallen;
public EntityFallenUponEvent(IBlock block, Entity entity, float distance){
super(block);
this.distanceFallen = distance;
this.entity = NpcAPI.Instance().getIEntity(entity);
}
@Override
public IEntity getEntity() {
return entity;
}
@Override
public float getDistanceFallen() {
return distanceFallen;
}
}
/**
* interact
*/
@Cancelable
public static class InteractEvent extends BlockEvent implements IBlockEvent.InteractEvent{
public final IPlayer player;
public final float hitX, hitY, hitZ;
public final int side;
public InteractEvent(IBlock block, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
super(block);
this.player = (IPlayer) NpcAPI.Instance().getIEntity(player);
this.hitX = hitX;
this.hitY = hitY;
this.hitZ = hitZ;
this.side = side;
}
@Override
public IPlayer getPlayer() {
return player;
}
@Override
public float getHitX() {
return hitX;
}
@Override
public float getHitY() {
return hitY;
}
@Override
public float getHitZ() {
return hitZ;
}
@Override
public int getSide() {
return side;
}
}
/**
* redstone
*/
public static class RedstoneEvent extends BlockEvent implements IBlockEvent.RedstoneEvent{
public final int prevPower, power;
public RedstoneEvent(IBlock block, int prevPower, int power) {
super(block);
this.power = power;
this.prevPower = prevPower;
}
@Override
public int getPrevPower() {
return prevPower;
}
@Override
public int getPower() {
return power;
}
}
/**
* broken
*/
public static class BreakEvent extends BlockEvent implements IBlockEvent.BreakEvent{
public BreakEvent(IBlock block) {
super(block);
}
}
/**
* exploded
*/
@Cancelable
public static class ExplodedEvent extends BlockEvent implements IBlockEvent.ExplodedEvent{
public ExplodedEvent(IBlock block) {
super(block);
}
}
/**
* rainFilled
*/
public static class RainFillEvent extends BlockEvent implements IBlockEvent.RainFillEvent{
public RainFillEvent(IBlock block) {
super(block);
}
}
/**
* neighborChanged
*/
public static class NeighborChangedEvent extends BlockEvent implements IBlockEvent.NeighborChangedEvent{
public final IPos changedPos;
public NeighborChangedEvent(IBlock block, IPos changedPos) {
super(block);
this.changedPos = changedPos;
}
@Override
public IPos getChangedPos() {
return changedPos;
}
}
/**
* init
*/
public static class InitEvent extends BlockEvent implements IBlockEvent.InitEvent{
public InitEvent(IBlock block) {
super(block);
}
}
/**
* tick
*/
public static class UpdateEvent extends BlockEvent implements IBlockEvent.UpdateEvent{
public UpdateEvent(IBlock block) {
super(block);
}
}
/**
* clicked
*/
public static class ClickedEvent extends BlockEvent implements IBlockEvent.ClickedEvent{
public final IPlayer player;
public ClickedEvent(IBlock block, EntityPlayer player) {
super(block);
this.player = (IPlayer) NpcAPI.Instance().getIEntity(player);
}
@Override
public IPlayer getPlayer() {
return player;
}
}
/**
* harvested
*/
@Cancelable
public static class HarvestedEvent extends BlockEvent implements IBlockEvent.HarvestedEvent{
public final IPlayer player;
public HarvestedEvent(IBlock block, EntityPlayer player) {
super(block);
this.player = (IPlayer) NpcAPI.Instance().getIEntity(player);
}
@Override
public IPlayer getPlayer() {
return player;
}
}
/**
* collide
*/
public static class CollidedEvent extends BlockEvent implements IBlockEvent.CollidedEvent{
public final IEntity entity;
public CollidedEvent(IBlock block, Entity entity) {
super(block);
this.entity = NpcAPI.Instance().getIEntity(entity);
}
@Override
public IEntity getEntity() {
return entity;
}
}
/**
* timer
*/
public static class TimerEvent extends BlockEvent implements IBlockEvent.TimerEvent{
public final int id;
public TimerEvent(IBlock block, int id) {
super(block);
this.id = id;
}
@Override
public int getId() {
return id;
}
}
}