mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 18:09:44 +00:00
Dev into Experimental
This commit is contained in:
commit
bfb6e968ee
28 files changed
+2181
-99
No files matched your search
@@ -0,0 +1,315 @@
|
||||
package noppes.npcs.scripted;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.ITileEntity;
|
||||
import noppes.npcs.api.ITimers;
|
||||
import noppes.npcs.api.block.IBlockScripted;
|
||||
import noppes.npcs.api.block.ITextPlane;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.blocks.tiles.TileScripted;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockScriptedWrapper extends ScriptBlock implements IBlockScripted{
|
||||
private TileScripted tile;
|
||||
|
||||
public BlockScriptedWrapper(World world, Block block, int x, int y, int z) {
|
||||
super(world, block, new BlockPos(x,y,z));
|
||||
tile = (TileScripted) super.tile.getMCTileEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(IItemStack item){
|
||||
if(item == null)
|
||||
tile.setItemModel(null, null);
|
||||
else
|
||||
tile.setItemModel(item.getMCItemStack(), Block.getBlockFromItem(item.getMCItemStack().getItem()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(String name){
|
||||
if(name == null)
|
||||
tile.setItemModel(null, null);
|
||||
else{
|
||||
Block block = Block.getBlockFromName(name);
|
||||
if(block!=null) {
|
||||
tile.setItemModel(new ItemStack(Item.getItemFromBlock(block)), block);
|
||||
}else{
|
||||
if(Item.itemRegistry.containsKey(name)) {
|
||||
tile.setItemModel(new ItemStack((Item) Item.itemRegistry.getObject(name)), null);
|
||||
}else{
|
||||
tile.setItemModel(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getModel(){
|
||||
return NpcAPI.Instance().getIItemStack(tile.itemModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRedstonePower(int strength){
|
||||
tile.setRedstonePower(strength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRedstonePower(){
|
||||
return tile.powering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIsLadder(boolean bo){
|
||||
tile.isLadder = bo;
|
||||
tile.needsClientUpdate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsLadder(){
|
||||
return tile.isLadder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIsPassible(boolean bo){
|
||||
tile.isPassible = bo;
|
||||
tile.needsClientUpdate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsPassible(){
|
||||
return tile.isPassible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLight(int value){
|
||||
tile.setLightValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLight(){
|
||||
return tile.lightValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScale(float x, float y, float z){
|
||||
tile.setScale(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleX(){
|
||||
return tile.scaleX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleY(){
|
||||
return tile.scaleY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleZ(){
|
||||
return tile.scaleZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(int x, int y, int z){
|
||||
tile.setRotation(x % 360, y % 360, z % 360);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRotationX(){
|
||||
return tile.rotationX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRotationY(){
|
||||
return tile.rotationY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRotationZ(){
|
||||
return tile.rotationZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHardness() {
|
||||
return tile.blockHardness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHardness(float hardness) {
|
||||
tile.blockHardness = hardness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getResistance() {
|
||||
return tile.blockResistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResistance(float resistance) {
|
||||
tile.blockResistance = resistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeCommand(String command){
|
||||
if(!MinecraftServer.getServer().isCommandBlockEnabled())
|
||||
throw new CustomNPCsException("Command blocks need to be enabled to executeCommands");
|
||||
NoppesUtilServer.runCommand(world.getMCWorld(), "ScriptedBlock", command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextPlane getTextPlane() {
|
||||
return tile.text1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextPlane getTextPlane2() {
|
||||
return tile.text2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextPlane getTextPlane3() {
|
||||
return tile.text3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextPlane getTextPlane4() {
|
||||
return tile.text4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextPlane getTextPlane5() {
|
||||
return tile.text5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextPlane getTextPlane6() {
|
||||
return tile.text6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITimers getTimers() {
|
||||
return tile.timers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTileEntity(ITileEntity tile){
|
||||
this.tile = (TileScripted) tile;
|
||||
super.setTileEntity(tile);
|
||||
}
|
||||
|
||||
private NBTTagCompound getNBT(){
|
||||
if(tile == null)
|
||||
return null;
|
||||
NBTTagCompound compound = tile.getTileData().getCompoundTag("CustomNPCsData");
|
||||
if(compound.hasNoTags() && !tile.getTileData().hasKey("CustomNPCsData")){
|
||||
tile.getTileData().setTag("CustomNPCsData", compound);
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredData(String key, Object value) {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return;
|
||||
if(value instanceof Number)
|
||||
compound.setDouble(key, ((Number) value).doubleValue());
|
||||
else if(value instanceof String)
|
||||
compound.setString(key, (String)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getStoredData(String key) {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return null;
|
||||
if(!compound.hasKey(key))
|
||||
return null;
|
||||
NBTBase base = compound.getTag(key);
|
||||
if(base instanceof NBTBase.NBTPrimitive)
|
||||
return ((NBTBase.NBTPrimitive)base).func_150286_g();
|
||||
return ((NBTTagString)base).func_150285_a_();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStoredData(String key) {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return;
|
||||
compound.removeTag(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStoredData(String key) {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return false;
|
||||
return compound.hasKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearStoredData() {
|
||||
if(tile == null)
|
||||
return;
|
||||
tile.getTileData().setTag("CustomNPCsData", new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getStoredDataKeys() {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return new String[0];
|
||||
return ((Set<String>)compound.func_150296_c()).toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTempData(String key) {
|
||||
if(tile == null)
|
||||
return;
|
||||
tile.tempData.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTempData(String key, Object value) {
|
||||
if(tile == null)
|
||||
return;
|
||||
tile.tempData.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTempData(String key) {
|
||||
if(tile == null)
|
||||
return false;
|
||||
return tile.tempData.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTempData(String key) {
|
||||
if(tile == null)
|
||||
return null;
|
||||
return tile.tempData.get(key);
|
||||
}
|
||||
@Override
|
||||
public void clearTempData() {
|
||||
if(tile == null)
|
||||
return;
|
||||
tile.tempData.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTempDataKeys() {
|
||||
return tile.tempData.keySet().toArray(new String[tile.tempData.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
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.constants.EnumScriptType;
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.FALLEN_UPON.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.INTERACT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.REDSTONE.function;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* broken
|
||||
*/
|
||||
public static class BreakEvent extends BlockEvent implements IBlockEvent.BreakEvent{
|
||||
public BreakEvent(IBlock block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.BROKEN.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* exploded
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ExplodedEvent extends BlockEvent implements IBlockEvent.ExplodedEvent{
|
||||
public ExplodedEvent(IBlock block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.EXPLODED.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* rainFilled
|
||||
*/
|
||||
public static class RainFillEvent extends BlockEvent implements IBlockEvent.RainFillEvent{
|
||||
public RainFillEvent(IBlock block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.RAIN_FILLED.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.NEIGHBOR_CHANGED.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
public static class InitEvent extends BlockEvent implements IBlockEvent.InitEvent{
|
||||
public InitEvent(IBlock block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.INIT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* tick
|
||||
*/
|
||||
public static class UpdateEvent extends BlockEvent implements IBlockEvent.UpdateEvent{
|
||||
public UpdateEvent(IBlock block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.TICK.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.CLICKED.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.HARVESTED.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.COLLIDE.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.TIMER.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user