Merge pull request #112 from Goodbird-git/scripted-blocks

Backported scripted blocks from 1.12.2
This commit is contained in:
Kam authored and GitHub committed 2024-01-22 13:43:03 -05:00
commit 34d3bd775e
16 files changed
+1770 -2

No files matched your search

@@ -189,6 +189,7 @@ public class CustomItems {
public static Block lamp_unlit;
public static Block campfire_unlit;
public static Block candle_unlit;
public static Block scripted;
public static Item crossbowBolt;
@@ -204,6 +205,7 @@ public class CustomItems {
GameRegistry.registerTileEntity(TileMailbox.class, "TileMailbox");
GameRegistry.registerTileEntity(TileWaypoint.class, "TileWaypoint");
GameRegistry.registerTileEntity(TileBanner.class, "TileNPCBanner");
GameRegistry.registerTileEntity(TileScripted.class, "TileNPCScripted");
if(!ConfigMain.DisableExtraBlock){
GameRegistry.registerTileEntity(TileWallBanner.class, "TileNPCWallBanner");
@@ -241,6 +243,7 @@ public class CustomItems {
mailbox = new BlockMailbox().setBlockName("npcMailbox").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setCreativeTab(tabBlocks);
waypoint = new BlockWaypoint().setBlockName("npcLocationBlock").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setBlockTextureName("customnpcs:npcWaypoint").setCreativeTab(tab);
border = new BlockBorder().setBlockName("npcBorder").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tab).setBlockTextureName("customnpcs:npcBorder");
scripted = new BlockScripted().setBlockName("npcScripted").setHardness(5.0F).setResistance(10.0F).setCreativeTab(tab).setBlockTextureName("customnpcs:npcScripted");
soulstoneEmpty = new ItemSoulstoneEmpty().setUnlocalizedName("npcSoulstoneEmpty").setTextureName("customnpcs:npcSoulstoneEmpty").setCreativeTab(tab);
soulstoneFull = new ItemSoulstoneFilled().setUnlocalizedName("npcSoulstoneFilled").setTextureName("customnpcs:npcSoulstoneFilled");
@@ -262,6 +265,7 @@ public class CustomItems {
GameRegistry.registerBlock(mailbox, ItemBlock.class, "npcMailbox");
GameRegistry.registerBlock(waypoint, "npcWaypoint");
GameRegistry.registerBlock(border, "npcBorder");
GameRegistry.registerBlock(scripted, "npcScripted");
Item.getItemFromBlock(mailbox).setHasSubtypes(true);
Item.getItemFromBlock(carpentyBench).setHasSubtypes(true);
+105
View File
@@ -15,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.event.entity.EntityEvent;
@@ -641,4 +642,108 @@ public class EventHooks {
handler.callScript(EnumScriptType.DIALOG_CLOSE, event);
NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptBlockInteract(IScriptBlockHandler handler, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if(handler.isClient())
return false;
BlockEvent.InteractEvent event = new BlockEvent.InteractEvent(handler.getBlock(), player, side, hitX, hitY, hitZ);
handler.callScript(EnumScriptType.INTERACT, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static void onScriptBlockCollide(IScriptBlockHandler handler, Entity entityIn) {
if(handler.isClient())
return;
BlockEvent.CollidedEvent event = new BlockEvent.CollidedEvent(handler.getBlock(), entityIn);
handler.callScript(EnumScriptType.COLLIDE, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onScriptBlockRainFill(IScriptBlockHandler handler) {
if(handler.isClient())
return;
BlockEvent.RainFillEvent event = new BlockEvent.RainFillEvent(handler.getBlock());
handler.callScript(EnumScriptType.RAIN_FILLED, event);
NpcAPI.EVENT_BUS.post(event);
}
public static float onScriptBlockFallenUpon(IScriptBlockHandler handler, Entity entity, float distance) {
if(handler.isClient())
return distance;
BlockEvent.EntityFallenUponEvent event = new BlockEvent.EntityFallenUponEvent(handler.getBlock(), entity, distance);
handler.callScript(EnumScriptType.FALLEN_UPON, event);
if(NpcAPI.EVENT_BUS.post(event))
return 0;
return event.distanceFallen;
}
public static void onScriptBlockClicked(IScriptBlockHandler handler, EntityPlayer player) {
if(handler.isClient())
return;
BlockEvent.ClickedEvent event = new BlockEvent.ClickedEvent(handler.getBlock(), player);
handler.callScript(EnumScriptType.CLICKED, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onScriptBlockBreak(IScriptBlockHandler handler) {
if(handler.isClient())
return;
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(handler.getBlock());
handler.callScript(EnumScriptType.BROKEN, event);
NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptBlockHarvest(IScriptBlockHandler handler, EntityPlayer player) {
if(handler.isClient())
return false;
BlockEvent.HarvestedEvent event = new BlockEvent.HarvestedEvent(handler.getBlock(), player);
handler.callScript(EnumScriptType.HARVESTED, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptBlockExploded(IScriptBlockHandler handler) {
if(handler.isClient())
return false;
BlockEvent.ExplodedEvent event = new BlockEvent.ExplodedEvent(handler.getBlock());
handler.callScript(EnumScriptType.EXPLODED, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static void onScriptBlockNeighborChanged(IScriptBlockHandler handler, int x, int y, int z) {
if(handler.isClient())
return;
BlockEvent.NeighborChangedEvent event = new BlockEvent.NeighborChangedEvent(handler.getBlock(), NpcAPI.Instance().getIPos(x,y,z));
handler.callScript(EnumScriptType.NEIGHBOR_CHANGED, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onScriptBlockRedstonePower(IScriptBlockHandler handler, int prevPower, int power) {
if(handler.isClient())
return;
BlockEvent.RedstoneEvent event = new BlockEvent.RedstoneEvent(handler.getBlock(), prevPower, power);
handler.callScript(EnumScriptType.REDSTONE, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onScriptBlockInit(IScriptBlockHandler handler) {
if(handler.isClient())
return;
BlockEvent.InitEvent event = new BlockEvent.InitEvent(handler.getBlock());
handler.callScript(EnumScriptType.INIT, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onScriptBlockUpdate(IScriptBlockHandler handler) {
if(handler.isClient())
return;
BlockEvent.UpdateEvent event = new BlockEvent.UpdateEvent(handler.getBlock());
handler.callScript(EnumScriptType.TICK, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onScriptBlockTimer(IScriptBlockHandler handler, int id) {
BlockEvent.TimerEvent event = new BlockEvent.TimerEvent(handler.getBlock(), id);
handler.callScript(EnumScriptType.TIMER, event);
NpcAPI.EVENT_BUS.post(event);
}
}
@@ -22,11 +22,13 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.math.BlockPos;
import net.minecraft.village.MerchantRecipeList;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.blocks.tiles.TileScripted;
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.config.ConfigScript;
@@ -214,6 +216,8 @@ public class PacketHandlerServer{
forgeScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave)
itemScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptBlockDataGet || type == EnumPacketServer.ScriptBlockDataSave)
blockScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptGlobalGuiDataGet || type == EnumPacketServer.ScriptGlobalGuiDataSave)
getScriptsEnabled(type, buffer, player);
else if (item.getItem() == CustomItems.scripter)
@@ -407,6 +411,27 @@ public class PacketHandlerServer{
}
}
private void blockScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
if (type == EnumPacketServer.ScriptBlockDataGet) {
TileEntity tile = player.worldObj.getTileEntity(buffer.readInt(), buffer.readInt(), buffer.readInt());
if(!(tile instanceof TileScripted))
return;
NBTTagCompound compound = ((TileScripted) tile).getNBT(new NBTTagCompound());
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
} else if (type == EnumPacketServer.ScriptBlockDataSave) {
if (!player.capabilities.isCreativeMode) {
return;
}
TileEntity tile = player.worldObj.getTileEntity(buffer.readInt(), buffer.readInt(), buffer.readInt());
if(!(tile instanceof TileScripted))
return;
TileScripted script = (TileScripted) tile;
script.setNBT(Server.readNBT(buffer));
script.lastInited = -1;
}
}
private void featherPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if(type == EnumPacketServer.DimensionTeleport){
int dimension = buffer.readInt();
@@ -0,0 +1,227 @@
package noppes.npcs.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.EventHooks;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileScripted;
import noppes.npcs.constants.EnumGuiType;
import java.util.Random;
public class BlockScripted extends BlockContainer {
public static final AxisAlignedBB AABB = AxisAlignedBB.getBoundingBox(0.001f, 0.001f, 0.001f, 0.998f, 0.998f, 0.998f);
public static final AxisAlignedBB AABB_EMPTY = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
public BlockScripted() {
super(Material.rock);
setStepSound(soundTypeStone);
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileScripted();
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
if (tile != null && tile.isPassible)
return AABB_EMPTY;
return AABB.getOffsetBoundingBox(x,y,z);
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
if (tile != null && tile.isPassible)
return AABB_EMPTY;
return AABB.getOffsetBoundingBox(x,y,z);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote)
return true;
ItemStack currentItem = player.inventory.getCurrentItem();
if (currentItem != null && (currentItem.getItem() == CustomItems.wand || currentItem.getItem() == CustomItems.scripter)) {
NoppesUtilServer.sendOpenGui(player, EnumGuiType.ScriptBlock, null, x, y, z);
return true;
}
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
return !EventHooks.onScriptBlockInteract(tile, player, side, hitX, hitY, hitZ);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
if (entity instanceof EntityPlayer && !world.isRemote) {
NoppesUtilServer.sendOpenGui((EntityPlayer) entity, EnumGuiType.ScriptBlock, null, x, y, z);
}
}
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entityIn) {
if (world.isRemote)
return;
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
EventHooks.onScriptBlockCollide(tile, entityIn);
}
@Override
public void fillWithRain(World world, int x, int y, int z) {
if (world.isRemote)
return;
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
EventHooks.onScriptBlockRainFill(tile);
}
@Override
public void onFallenUpon(World world, int x, int y, int z, Entity entity, float fallDistance) {
if (world.isRemote)
return;
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
fallDistance = EventHooks.onScriptBlockFallenUpon(tile, entity, fallDistance);
super.onFallenUpon(world, x, y, z, entity, fallDistance);
}
@Override
public boolean canRenderInPass(int pass) {
return false;
}
@Override
public int getRenderType() {
return 0;
}
@Override
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
@Override
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
if (world.isRemote)
return;
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
EventHooks.onScriptBlockClicked(tile, player);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int metadata) {
if (!world.isRemote) {
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
EventHooks.onScriptBlockBreak(tile);
}
super.breakBlock(world, x, y, z, block, metadata);
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
if (!world.isRemote) {
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
if (EventHooks.onScriptBlockHarvest(tile, player))
return false;
}
return super.removedByPlayer(world, player, x, y, z, willHarvest);
}
@Override
public Item getItemDropped(int i, Random rand, int fortune) {
return null;
}
@Override
public void onBlockExploded(World world, int x, int y, int z, Explosion explosion) {
if (!world.isRemote) {
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
if (EventHooks.onScriptBlockExploded(tile))
return;
}
super.onBlockExploded(world, x, y, z, explosion);
}
@Override
public boolean canProvidePower() {
return true;
}
@Override
public int isProvidingWeakPower(IBlockAccess worldIn, int x, int y, int z, int side) {
return this.isProvidingStrongPower(worldIn, x, y, z, side);
}
@Override
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) {
return ((TileScripted) world.getTileEntity(x, y, z)).activePowering;
}
@Override
public boolean isLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity) {
return ((TileScripted) world.getTileEntity(x, y, z)).isLadder;
}
@Override
public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z) {
return true;
}
@Override
public float getBlockHardness(World world, int x, int y, int z) {
return ((TileScripted) world.getTileEntity(x, y, z)).blockHardness;
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
if (tile == null)
return 0;
return tile.lightValue;
}
@Override
public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) {
return ((TileScripted) world.getTileEntity(x, y, z)).blockResistance;
}
@Override
public void onNeighborChange(IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ) {
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
EventHooks.onScriptBlockNeighborChanged(tile, tileX, tileY, tileZ);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
int power = 0;
for (EnumFacing enumfacing : EnumFacing.values()) {
int p = world.getIndirectPowerLevelTo(x + enumfacing.getFrontOffsetX(),
y + enumfacing.getFrontOffsetZ(), z + enumfacing.getFrontOffsetZ(), enumfacing.ordinal());
if (p > power)
power = p;
}
if (tile.prevPower != power && tile.powering <= 0) {
tile.newPower = power;
}
}
}
@@ -0,0 +1,542 @@
package noppes.npcs.blocks.tiles;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.ITickable;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import noppes.npcs.*;
import noppes.npcs.api.IBlock;
import noppes.npcs.api.block.ITextPlane;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.IScriptBlockHandler;
import noppes.npcs.entity.data.DataTimers;
import noppes.npcs.scripted.BlockScriptedWrapper;
import noppes.npcs.util.ValueUtil;
import java.util.*;
import java.util.Map.Entry;
public class TileScripted extends TileEntity implements IScriptBlockHandler {
public List<ScriptContainer> scripts = new ArrayList<>();
public Map<String,Object> tempData = new HashMap<>();
private NBTTagCompound customTileData;
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
private IBlock blockDummy = null;
public DataTimers timers = new DataTimers(this);
public long lastInited = -1;
private short ticksExisted = 0;
public ItemStack itemModel = new ItemStack(CustomItems.scripted);
public Block blockModel = null;
public boolean needsClientUpdate = false;
public int powering = 0;
public int activePowering = 0;
public int newPower = 0; //used for block redstone event
public int prevPower = 0; //used for block redstone event
public boolean isPassible = false;
public boolean isLadder = false;
public int lightValue = 0;
public float blockHardness = 5;
public float blockResistance = 10;
public int rotationX = 0, rotationY = 0, rotationZ = 0;
public float scaleX = 1, scaleY = 1, scaleZ = 1;
public TileEntity renderTile;
public boolean renderTileErrored = true;
public ITickable renderTileUpdate = null;
public TextPlane text1 = new TextPlane();
public TextPlane text2 = new TextPlane();
public TextPlane text3 = new TextPlane();
public TextPlane text4 = new TextPlane();
public TextPlane text5 = new TextPlane();
public TextPlane text6 = new TextPlane();
public IBlock getBlock(){
if(blockDummy == null)
blockDummy = new BlockScriptedWrapper(worldObj, this.getBlockType(), xCoord,yCoord,zCoord);
return blockDummy;
}
@Override
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
setNBT(compound);
setDisplayNBT(compound);
timers.readFromNBT(compound);
NBTTagCompound extraData = compound.getCompoundTag("ExtraData");
if(!extraData.hasNoTags()){
getTileData().setTag("CustomNPCsData", extraData);
}
}
public void setNBT(NBTTagCompound compound){
scripts = NBTTags.GetScriptOld(compound.getTagList("Scripts", 10), this);
scriptLanguage = compound.getString("ScriptLanguage");
enabled = compound.getBoolean("ScriptEnabled");
activePowering = powering = compound.getInteger("BlockPowering");
prevPower = compound.getInteger("BlockPrevPower");
if(compound.hasKey("BlockHardness")){
blockHardness = compound.getFloat("BlockHardness");
blockResistance = compound.getFloat("BlockResistance");
}
}
public void setDisplayNBT(NBTTagCompound compound){
itemModel = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("ScriptBlockModel"));
if(itemModel==null || itemModel.stackSize == 0)
itemModel = new ItemStack(Item.getItemFromBlock(CustomItems.scripted));
if(compound.hasKey("ScriptBlockModelBlock"))
blockModel = Block.getBlockFromName(compound.getString("ScriptBlockModelBlock"));
renderTileUpdate = null;
renderTile = null;
renderTileErrored = false;
lightValue = compound.getInteger("LightValue");
isLadder = compound.getBoolean("IsLadder");
isPassible = compound.getBoolean("IsPassible");
rotationX = compound.getInteger("RotationX");
rotationY = compound.getInteger("RotationY");
rotationZ = compound.getInteger("RotationZ");
scaleX = compound.getFloat("ScaleX");
scaleY = compound.getFloat("ScaleY");
scaleZ = compound.getFloat("ScaleZ");
if(scaleX <= 0)
scaleX = 1;
if(scaleY <= 0)
scaleY = 1;
if(scaleZ <= 0)
scaleZ = 1;
if(compound.hasKey("Text3")) {
text1.setNBT(compound.getCompoundTag("Text1"));
text2.setNBT(compound.getCompoundTag("Text2"));
text3.setNBT(compound.getCompoundTag("Text3"));
text4.setNBT(compound.getCompoundTag("Text4"));
text5.setNBT(compound.getCompoundTag("Text5"));
text6.setNBT(compound.getCompoundTag("Text6"));
}
}
@Override
public void writeToNBT(NBTTagCompound compound){
super.writeToNBT(compound);
getNBT(compound);
getDisplayNBT(compound);
timers.writeToNBT(compound);
compound.setTag("ExtraData",getTileData().getTag("CustomNPCsData"));
}
public NBTTagCompound getNBT(NBTTagCompound compound){
compound.setTag("Scripts", NBTTags.NBTScript(scripts));
compound.setString("ScriptLanguage", scriptLanguage);
compound.setBoolean("ScriptEnabled", enabled);
compound.setInteger("BlockPowering", powering);
compound.setInteger("BlockPrevPower", prevPower);
compound.setFloat("BlockHardness", blockHardness);
compound.setFloat("BlockResistance", blockResistance);
return compound;
}
public void getDisplayNBT(NBTTagCompound compound){
NBTTagCompound itemcompound = new NBTTagCompound();
itemModel.writeToNBT(itemcompound);
if(blockModel != null){
compound.setString("ScriptBlockModelBlock", Block.blockRegistry.getNameForObject(blockModel));
}
compound.setTag("ScriptBlockModel", itemcompound);
compound.setInteger("LightValue", lightValue);
compound.setBoolean("IsLadder", isLadder);
compound.setBoolean("IsPassible", isPassible);
compound.setInteger("RotationX", rotationX);
compound.setInteger("RotationY", rotationY);
compound.setInteger("RotationZ", rotationZ);
compound.setFloat("ScaleX", scaleX);
compound.setFloat("ScaleY", scaleY);
compound.setFloat("ScaleZ", scaleZ);
compound.setTag("Text1", text1.getNBT());
compound.setTag("Text2", text2.getNBT());
compound.setTag("Text3", text3.getNBT());
compound.setTag("Text4", text4.getNBT());
compound.setTag("Text5", text5.getNBT());
compound.setTag("Text6", text6.getNBT());
}
private boolean isEnabled() {
return enabled && ScriptController.HasStart && !worldObj.isRemote;
}
@Override
public void updateEntity() {
if(renderTileUpdate != null){
try{
renderTileUpdate.tick();
}
catch(Exception e){
renderTileUpdate = null;
}
}
ticksExisted++;
if (prevPower != newPower && powering <= 0){
EventHooks.onScriptBlockRedstonePower(this, prevPower, newPower);
prevPower = newPower;
}
timers.update();
if(ticksExisted >= 10){
EventHooks.onScriptBlockUpdate(this);
ticksExisted = 0;
if(needsClientUpdate){
markDirty();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord,yCoord,zCoord,getBlockType(),3);
needsClientUpdate = false;
}
}
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
handleUpdateTag(pkt.func_148857_g());
}
public void handleUpdateTag(NBTTagCompound tag){
int light = lightValue;
setDisplayNBT(tag);
if(light != lightValue)
checkLight(worldObj,xCoord,yCoord,zCoord);
}
public boolean checkLight(World world, int x, int y, int z)
{
boolean flag = false;
if (!world.provider.hasNoSky)
{
flag |= world.updateLightByType(EnumSkyBlock.Sky, x,y,z);
}
flag = flag | world.updateLightByType(EnumSkyBlock.Block, x,y,z);
return flag;
}
@Override
public Packet getDescriptionPacket() {
return new S35PacketUpdateTileEntity(xCoord,yCoord,zCoord, 0, getUpdateTag());
}
public NBTTagCompound getUpdateTag(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("x", xCoord);
compound.setInteger("y", yCoord);
compound.setInteger("z", zCoord);
getDisplayNBT(compound);
return compound;
}
public void setItemModel(ItemStack item, Block b) {
if(item == null || item.stackSize==0){
item = new ItemStack(CustomItems.scripted);
}
if(NoppesUtilPlayer.compareItems(item, itemModel, false, false) && b != blockModel)
return;
itemModel = item;
blockModel = b;
needsClientUpdate = true;
}
public void setLightValue(int value){
if(value == lightValue)
return;
lightValue = ValueUtil.clamp(value, 0, 15);
needsClientUpdate = true;
}
public void setRedstonePower(int strength){
if(powering == strength)
return;
//using activePowering to prevent the RedstonePower script event from going crazy
prevPower = activePowering = ValueUtil.clamp(strength, 0, 15);
worldObj.notifyBlockChange(xCoord,yCoord,zCoord, getBlockType());
powering = activePowering;
}
public void setScale(float x, float y, float z){
if(scaleX == x && scaleY == y && scaleZ == z)
return;
scaleX = ValueUtil.clamp(x, 0, 10);
scaleY = ValueUtil.clamp(y, 0, 10);
scaleZ = ValueUtil.clamp(z, 0, 10);
needsClientUpdate = true;
}
public void setRotation(int x, int y, int z){
if(rotationX == x && rotationY == y && rotationZ == z)
return;
rotationX = ValueUtil.clamp(x, 0, 359);
rotationY = ValueUtil.clamp(y, 0, 359);
rotationZ = ValueUtil.clamp(z, 0, 359);
needsClientUpdate = true;
}
@Override
public void callScript(EnumScriptType type, Event event) {
if(!isEnabled())
return;
if(ScriptController.Instance.lastLoaded > lastInited){
lastInited = ScriptController.Instance.lastLoaded;
if(type != EnumScriptType.INIT)
EventHooks.onScriptBlockInit(this);
}
for(ScriptContainer script : scripts){
script.run(type, event);
}
}
@Override
public void callScript(String hookName, Event event) {
callScript(EnumScriptType.valueOf(hookName),event);
}
@Override
public boolean isClient() {
return worldObj.isRemote;
}
@Override
public boolean getEnabled() {
return enabled;
}
@Override
public void setEnabled(boolean bo) {
enabled = bo;
}
@Override
public String noticeString() {
return "x: "+xCoord+", y: "+yCoord+", z: "+zCoord;
}
@Override
public String getLanguage() {
return scriptLanguage;
}
@Override
public void setLanguage(String lang) {
scriptLanguage = lang;
}
@Override
public void setScripts(List<ScriptContainer> list) {
scripts = list;
}
@Override
public List<ScriptContainer> getScripts() {
return scripts;
}
@Override
public Map<Long, String> getConsoleText(){
Map<Long, String> map = new TreeMap<>();
int tab = 0;
for(ScriptContainer script : getScripts()){
tab++;
for(Entry<Long, String> entry : script.console.entrySet()){
map.put(entry.getKey(), " tab " + tab + ":\n" + entry.getValue());
}
}
return map;
}
@Override
public void clearConsole() {
for(ScriptContainer script : getScripts()){
script.console.clear();
}
}
@SideOnly(Side.CLIENT)
@Override
public AxisAlignedBB getRenderBoundingBox(){
return AxisAlignedBB.getBoundingBox(0.0, 0.0, 0.0, 1.0, 1.0, 1.0)
.offset(xCoord,yCoord,zCoord);
}
public NBTTagCompound getTileData()
{
if (this.customTileData == null)
{
this.customTileData = new NBTTagCompound();
}
return this.customTileData;
}
public class TextPlane implements ITextPlane {
public boolean textHasChanged = true;
public TextBlock textBlock;
public String text = "";
public int rotationX = 0, rotationY = 0, rotationZ = 0;
public float offsetX = 0, offsetY = 0f, offsetZ = 0.5f;
public float scale = 1;
@Override
public String getText() {
return text;
}
@Override
public void setText(String text) {
if(this.text.equals(text))
return;
this.text = text;
textHasChanged = true;
needsClientUpdate = true;
}
@Override
public int getRotationX() {
return rotationX;
}
@Override
public int getRotationY() {
return rotationY;
}
@Override
public int getRotationZ() {
return rotationZ;
}
@Override
public void setRotationX(int x) {
x = ValueUtil.clamp(x % 360, 0, 359);
if(rotationX == x)
return;
rotationX = x;
needsClientUpdate = true;
}
@Override
public void setRotationY(int y) {
y = ValueUtil.clamp(y % 360, 0, 359);
if(rotationY == y)
return;
rotationY = y;
needsClientUpdate = true;
}
@Override
public void setRotationZ(int z) {
z = ValueUtil.clamp(z % 360, 0, 359);
if(rotationZ == z)
return;
rotationZ = z;
needsClientUpdate = true;
}
@Override
public float getOffsetX() {
return offsetX;
}
@Override
public float getOffsetY() {
return offsetY;
}
@Override
public float getOffsetZ() {
return offsetZ;
}
@Override
public void setOffsetX(float x) {
x = ValueUtil.clamp(x, -1, 1);
if(offsetX == x)
return;
offsetX = x;
needsClientUpdate = true;
}
@Override
public void setOffsetY(float y) {
y = ValueUtil.clamp(y, -1, 1);
if(offsetY == y)
return;
offsetY = y;
needsClientUpdate = true;
}
@Override
public void setOffsetZ(float z) {
z = ValueUtil.clamp(z, -1, 1);
if(offsetZ == z)
return;
System.out.println(rotationZ);
offsetZ = z;
needsClientUpdate = true;
}
@Override
public float getScale() {
return scale;
}
@Override
public void setScale(float scale) {
if(this.scale == scale)
return;
this.scale = scale;
needsClientUpdate = true;
}
public NBTTagCompound getNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setString("Text", text);
compound.setInteger("RotationX", rotationX);
compound.setInteger("RotationY", rotationY);
compound.setInteger("RotationZ", rotationZ);
compound.setFloat("OffsetX", offsetX);
compound.setFloat("OffsetY", offsetY);
compound.setFloat("OffsetZ", offsetZ);
compound.setFloat("Scale", scale);
return compound;
}
public void setNBT(NBTTagCompound compound) {
setText(compound.getString("Text"));
rotationX = compound.getInteger("RotationX");
rotationY = compound.getInteger("RotationY");
rotationZ = compound.getInteger("RotationZ");
offsetX = compound.getFloat("OffsetX");
offsetY = compound.getFloat("OffsetY");
offsetZ = compound.getFloat("OffsetZ");
scale = compound.getFloat("Scale");
}
}
}
@@ -45,6 +45,7 @@ import noppes.npcs.client.gui.player.companion.GuiNpcCompanionTalents;
import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeItem;
import noppes.npcs.client.gui.GuiNpcRemoteEditor;
import noppes.npcs.client.gui.roles.*;
import noppes.npcs.client.gui.script.GuiScriptBlock;
import noppes.npcs.client.gui.script.GuiScriptGlobal;
import noppes.npcs.client.gui.script.GuiScriptItem;
import noppes.npcs.client.model.*;
@@ -123,6 +124,7 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileBeam.class, new BlockBeamRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileBook.class, new BlockBookRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TilePedestal.class, new BlockPedestalRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileScripted.class, new BlockScriptedRenderer());
RenderingRegistry.registerBlockHandler(new BlockBloodRenderer());
}
Minecraft mc = Minecraft.getMinecraft();
@@ -375,6 +377,9 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.CustomGui)
return new GuiCustom((ContainerCustomGui)container);
else if (gui == EnumGuiType.ScriptBlock)
return new GuiScriptBlock(x,y,z);
return null;
}
@@ -0,0 +1,39 @@
package noppes.npcs.client.gui.script;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.blocks.tiles.TileScripted;
import noppes.npcs.client.Client;
import noppes.npcs.constants.EnumPacketServer;
public class GuiScriptBlock extends GuiScriptInterface {
private TileScripted tileScripted;
public GuiScriptBlock(int x, int y, int z) {
hookList.add("init");
hookList.add("tick");
hookList.add("interact");
hookList.add("fallenUpon");
hookList.add("redstone");
hookList.add("broken");
hookList.add("exploded");
hookList.add("rainFilled");
hookList.add("neighborChanged");
hookList.add("clicked");
hookList.add("harvested");
hookList.add("collide");
hookList.add("timer");
this.handler = this.tileScripted = (TileScripted) player.worldObj.getTileEntity(x, y, z);
Client.sendData(EnumPacketServer.ScriptBlockDataGet, tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord);
}
public void setGuiData(NBTTagCompound compound) {
this.tileScripted.setNBT(compound);
super.setGuiData(compound);
}
public void save() {
super.save();
Client.sendData(EnumPacketServer.ScriptBlockDataSave, tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord, this.tileScripted.getNBT(new NBTTagCompound()));
}
}
@@ -0,0 +1,179 @@
package noppes.npcs.client.renderer.blocks;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import net.geckominecraft.client.renderer.GlStateManager;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.ITickable;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.ForgeHooksClient;
import noppes.npcs.CustomItems;
import noppes.npcs.blocks.BlockScripted;
import noppes.npcs.blocks.tiles.TileScripted;
import noppes.npcs.blocks.tiles.TileScripted.TextPlane;
import noppes.npcs.client.TextBlockClient;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.Random;
public class BlockScriptedRenderer extends BlockRendererInterface{
private static final RenderBlocks renderBlocks = new RenderBlocks();
private static final Random random = new Random();
@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks) {
TileScripted tile = (TileScripted) te;
GlStateManager.pushMatrix();
GlStateManager.disableBlend();
RenderHelper.enableStandardItemLighting();
GlStateManager.translate(x + 0.5, y, z + 0.5);
if(overrideModel()){
GlStateManager.translate(0, 0.5, 0);
renderItem(te, new ItemStack(CustomItems.scripted));
}
else{
GlStateManager.rotate(tile.rotationY, 0, 1, 0);
GlStateManager.rotate(tile.rotationX, 1, 0, 0);
GlStateManager.rotate(tile.rotationZ, 0, 0, 1);
GlStateManager.scale(tile.scaleX, tile.scaleY, tile.scaleZ);
GlStateManager.translate(0, 0.5, 0);
renderItem(te, tile.itemModel);
}
GlStateManager.popMatrix();
if(!tile.text1.text.isEmpty()) {
drawText(tile.text1, x, y, z);
}
if(!tile.text2.text.isEmpty()) {
drawText(tile.text2, x, y, z);
}
if(!tile.text3.text.isEmpty()) {
drawText(tile.text3, x, y, z);
}
if(!tile.text4.text.isEmpty()) {
drawText(tile.text4, x, y, z);
}
if(!tile.text5.text.isEmpty()) {
drawText(tile.text5, x, y, z);
}
if(!tile.text6.text.isEmpty()) {
drawText(tile.text6, x, y, z);
}
}
private void drawText(TextPlane text1, double x, double y, double z) {
if(text1.textBlock == null || text1.textHasChanged){
text1.textBlock = new TextBlockClient(text1.text, 336, true, Minecraft.getMinecraft().thePlayer);
text1.textHasChanged = false;
}
GlStateManager.disableBlend();
GlStateManager.enableLighting();
GlStateManager.color(1, 1, 1);
GlStateManager.pushMatrix();
GlStateManager.translate(x + 0.5, y + 0.5, z + 0.5);
GlStateManager.rotate(text1.rotationY, 0, 1, 0);
GlStateManager.rotate(text1.rotationX, 1, 0, 0);
GlStateManager.rotate(text1.rotationZ, 0, 0, 1);
GlStateManager.scale(text1.scale, text1.scale, 1);
GlStateManager.translate(text1.offsetX, text1.offsetY, text1.offsetZ);
float f1 = 0.6666667F;
float f3 = 0.0133F * f1;
GlStateManager.translate(0.0F, 0.5f, 0.01F);
GlStateManager.scale(f3, -f3, f3);
GlStateManager.glNormal3f(0.0F, 0.0F, -1.0F * f3);
GlStateManager.depthMask(false);
FontRenderer fontrenderer = Minecraft.getMinecraft().fontRenderer;
float lineOffset = 0;
if(text1.textBlock.lines.size() < 14)
lineOffset = (14f - text1.textBlock.lines.size()) / 2;
for(int i = 0; i < text1.textBlock.lines.size(); i++){
String text = text1.textBlock.lines.get(i).getFormattedText();
fontrenderer.drawString(text, -fontrenderer.getStringWidth(text) / 2, (int)((lineOffset + i) * (fontrenderer.FONT_HEIGHT - 0.3)), 0);
}
GlStateManager.depthMask(true);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.popMatrix();
}
private void renderItem(TileEntity tile, ItemStack stack){
Minecraft mc = Minecraft.getMinecraft();
if(stack != null) {
mc.renderEngine.bindTexture(stack.getItem() instanceof ItemBlock ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture);
GL11.glScalef(2F, 2F, 2F);
if(!ForgeHooksClient.renderEntityItem(new EntityItem(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, stack), stack, 0F, 0F, tile.getWorldObj().rand, mc.renderEngine, renderBlocks, 1)) {
GL11.glScalef(0.5F, 0.5F, 0.5F);
if(stack.getItem() instanceof ItemBlock && (RenderBlocks.renderItemIn3d(Block.getBlockFromItem(stack.getItem()).getRenderType())
|| Block.getBlockFromItem(stack.getItem()) instanceof BlockScripted)) {
renderBlocks.renderBlockAsItem(Block.getBlockFromItem(stack.getItem()), stack.getItemDamage(), 1F);
} else {
int renderPass = 0;
do {
IIcon icon = stack.getItem().getIcon(stack, renderPass);
if(icon != null) {
Color color = new Color(stack.getItem().getColorFromItemStack(stack, renderPass));
GL11.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
float f = icon.getMinU();
float f1 = icon.getMaxU();
float f2 = icon.getMinV();
float f3 = icon.getMaxV();
GL11.glTranslatef(-0.5F, -0.5F, 0F);
ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F);
GL11.glColor3f(1F, 1F, 1F);
}
renderPass++;
} while(renderPass < stack.getItem().getRenderPasses(stack.getItemDamage()));
}
}
}
}
private void renderBlock(TileScripted tile, Block b){
GlStateManager.pushMatrix();
this.bindTexture(TextureMap.locationBlocksTexture);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
GlStateManager.enableBlend();
GlStateManager.disableCull();
GlStateManager.translate(-0.5F, -0, 0.5F);
renderBlocks.renderStandardBlock(b, tile.xCoord, tile.yCoord, tile.zCoord);
if(b.getTickRandomly() && random.nextInt(12) == 1)
b.randomDisplayTick(tile.getWorldObj(), tile.xCoord,tile.yCoord,tile.zCoord, random);
GlStateManager.popMatrix();
}
private boolean overrideModel(){
ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem();
if(held == null)
return false;
return held.getItem() == CustomItems.wand || held.getItem() == CustomItems.scripter;
}
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
//TODO
}
@Override
public int getRenderId() {
return 0;
}
}
@@ -54,5 +54,6 @@ public enum EnumGuiType {
CompanionTrader,
ManageLinked,
CustomGui,
ScriptItem;
ScriptItem,
ScriptBlock;
}
@@ -49,6 +49,8 @@ public enum EnumPacketServer {
ScriptItemDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
ScriptItemDataGet(false),
ScriptBlockDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
ScriptBlockDataGet(false),
LinkedGetAll, LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED),
ScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), ScriptDataGet(true),
@@ -0,0 +1,8 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.IBlock;
public interface IScriptBlockHandler extends INpcScriptHandler{
public IBlock getBlock();
}
@@ -9,6 +9,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.EventHooks;
import noppes.npcs.api.ITimers;
import noppes.npcs.blocks.tiles.TileScripted;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.CustomNPCsException;
@@ -186,6 +187,9 @@ public class DataTimers implements ITimers {
else if(ob instanceof PlayerData) {
EventHooks.onPlayerTimer((PlayerData)ob, this.id);
}
else if(ob instanceof TileScripted) {
EventHooks.onScriptBlockTimer((TileScripted)ob, this.id);
}
}
}
}
@@ -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;
}
}
}