From 654ea09152e63ab5ccdcd0a9302eb089916323b8 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:54:21 +0300 Subject: [PATCH 01/26] Added a texture for the scripted block --- .../customnpcs/textures/blocks/npcScripted.png | Bin 0 -> 387 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/assets/customnpcs/textures/blocks/npcScripted.png diff --git a/src/main/resources/assets/customnpcs/textures/blocks/npcScripted.png b/src/main/resources/assets/customnpcs/textures/blocks/npcScripted.png new file mode 100644 index 0000000000000000000000000000000000000000..e58112559b86dfb6069cea705a28a677b6980d56 GIT binary patch literal 387 zcmV-}0et?6P)N2bZe?^J zG%heMHD!e|WdHyH0ZBwbR5(w4lCi47KoCXu&+-%bh?FT_W0%s-LI_w`ScqVwg^jI^ z@Ze$fzQfYiGaMNrE)J8)x@m{oj78e%NnuS3wgkk>S+Nr(@L-xGv-v8bhj}e3*jlFj}(9 zFM{1>EgN!ilx*q6ni$|}xsV+*kYU+U)rZ*+1Po>ztJ|eu9LKKfj45DwIFO?yUfAFD zVmaBw6v&1gJ2(SJVY#}4Z9{%t9Oeb#oC#Axnz{qTJwVMPOBB$BEP-dW^7FwXuWH@| hvazYaL{4b#^CvXbczxO$u|@y@002ovPDHLkV1ic%oYDXQ literal 0 HcmV?d00001 From dbdf559cf699e6f916941015c741a09ac9726e74 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:55:40 +0300 Subject: [PATCH 02/26] Implemented scripted block event interfaces --- .../npcs/scripted/event/BlockEvent.java | 246 ++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 src/main/java/noppes/npcs/scripted/event/BlockEvent.java diff --git a/src/main/java/noppes/npcs/scripted/event/BlockEvent.java b/src/main/java/noppes/npcs/scripted/event/BlockEvent.java new file mode 100644 index 000000000..ce71e1114 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/BlockEvent.java @@ -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; + } + } +} + From 6da6480dd52fe892a987a088394a58d44d78271f Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:56:28 +0300 Subject: [PATCH 03/26] Added an interface for scripted block script handler --- .../controllers/data/IScriptBlockHandler.java | 8 + .../npcs/scripted/BlockScriptedWrapper.java | 198 ++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 src/main/java/noppes/npcs/controllers/data/IScriptBlockHandler.java create mode 100644 src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java diff --git a/src/main/java/noppes/npcs/controllers/data/IScriptBlockHandler.java b/src/main/java/noppes/npcs/controllers/data/IScriptBlockHandler.java new file mode 100644 index 000000000..ffe7e77e2 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/IScriptBlockHandler.java @@ -0,0 +1,8 @@ +package noppes.npcs.controllers.data; + +import noppes.npcs.api.IBlock; + +public interface IScriptBlockHandler extends INpcScriptHandler{ + + public IBlock getBlock(); +} diff --git a/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java b/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java new file mode 100644 index 000000000..4241c793d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java @@ -0,0 +1,198 @@ +package noppes.npcs.scripted; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +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; + +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; + } + + @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); + tile.setItemModel(new ItemStack(Item.getItemFromBlock(block)), block); + } + } + + @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); + } +} + From 123a82831be20e53772b26403a5aa03fae20505f Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:57:12 +0300 Subject: [PATCH 04/26] Changed api branch --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index e3980ce21..0895815b3 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit e3980ce21720e963bb3d3169931885eb0bc60caa +Subproject commit 0895815b34f1278cbe06fe70a4432893e0d2dea4 From f052016de5bbabb1863882a7cb666a18a5907874 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:57:35 +0300 Subject: [PATCH 05/26] Added scripted block and its tile --- .../noppes/npcs/blocks/BlockScripted.java | 214 +++++++ .../npcs/blocks/tiles/TileScripted.java | 526 ++++++++++++++++++ 2 files changed, 740 insertions(+) create mode 100644 src/main/java/noppes/npcs/blocks/BlockScripted.java create mode 100644 src/main/java/noppes/npcs/blocks/tiles/TileScripted.java diff --git a/src/main/java/noppes/npcs/blocks/BlockScripted.java b/src/main/java/noppes/npcs/blocks/BlockScripted.java new file mode 100644 index 000000000..a2d2e6c31 --- /dev/null +++ b/src/main/java/noppes/npcs/blocks/BlockScripted.java @@ -0,0 +1,214 @@ +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; + } + + @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; + } + + @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 isOpaqueCube() { + return false; + } + + @Override + public boolean isNormalCube() { + 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); + + int power = 0; + for (EnumFacing enumfacing : EnumFacing.values()) { + int p = world.isBlockProvidingPowerTo(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; + } + } +} diff --git a/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java b/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java new file mode 100644 index 000000000..b03d03e30 --- /dev/null +++ b/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java @@ -0,0 +1,526 @@ +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.INpcScriptHandler; +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.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +public class TileScripted extends TileEntity implements IScriptBlockHandler { + public List scripts = new ArrayList<>(); + + 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); + } + + 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.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){ + getNBT(compound); + getDisplayNBT(compound); + timers.writeToNBT(compound); + } + + 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.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 list) { + scripts = list; + } + + @Override + public List getScripts() { + return scripts; + } + + @Override + public Map getConsoleText(){ + Map map = new TreeMap<>(); + int tab = 0; + for(ScriptContainer script : getScripts()){ + tab++; + for(Entry 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 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"); + } + } +} From 4980125f3dd37536ef55178b2ba1c12522cfc0be Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:57:52 +0300 Subject: [PATCH 06/26] Registered scripted block and its tile --- src/main/java/noppes/npcs/CustomItems.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/noppes/npcs/CustomItems.java b/src/main/java/noppes/npcs/CustomItems.java index 105d1bbc9..1014df955 100644 --- a/src/main/java/noppes/npcs/CustomItems.java +++ b/src/main/java/noppes/npcs/CustomItems.java @@ -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).setBlockName("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); From a3d59164c236f47d1525f2f558b8be6ba9ed21e0 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:58:14 +0300 Subject: [PATCH 07/26] Added and registered scripted block renderer --- .../java/noppes/npcs/client/ClientProxy.java | 1 + .../blocks/BlockScriptedRenderer.java | 196 ++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index deaa74a22..b5eb05270 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -123,6 +123,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(); diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java new file mode 100644 index 000000000..923f529bb --- /dev/null +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java @@ -0,0 +1,196 @@ +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.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import noppes.npcs.CustomItems; +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 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(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); + Block b = tile.blockModel; + if(b == null || b == Blocks.air){ + GlStateManager.translate(0, 0.5, 0); + renderItem(tile.itemModel); + } + else if(b == CustomItems.scripted){ + GlStateManager.translate(0, 0.5, 0); + renderItem(tile.itemModel); + } + else{ + int meta = tile.itemModel.getItemDamage(); + renderBlock(tile, b); + + if(b.hasTileEntity(meta) && !tile.renderTileErrored){ + try{ + if(tile.renderTile == null){ + TileEntity entity = b.createTileEntity(te.getWorldObj(), meta); + entity.zCoord=tile.zCoord; + entity.yCoord=tile.yCoord; + entity.xCoord=tile.xCoord; + entity.setWorldObj(te.getWorldObj()); + ObfuscationReflectionHelper.setPrivateValue(TileEntity.class, entity, tile.itemModel.getItemDamage(), 5); + ObfuscationReflectionHelper.setPrivateValue(TileEntity.class, entity, b, 6); + tile.renderTile = entity; + if(entity instanceof ITickable){ + tile.renderTileUpdate = (ITickable) entity; + } + } + TileEntitySpecialRenderer renderer = TileEntityRendererDispatcher.instance.getSpecialRenderer(tile.renderTile); + + if(renderer != null){ + renderer.renderTileEntityAt(tile.renderTile, -0.5, 0, -0.5, partialTicks); + + } + else + tile.renderTileErrored = true; + } + catch(Exception e){ + tile.renderTileErrored = true; + } + } + } + } + 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(ItemStack stack){ + IIcon icon = stack.getItem().getIcon(stack, 0); + if(icon != null) { + Color color = new Color(stack.getItem().getColorFromItemStack(stack, 0)); + 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(); + ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); + GL11.glColor3f(1F, 1F, 1F); + } + } + + 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.getInstance().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; + } +} From dff76888dcd2be71bd9eb477a9d53f6d56c1d463 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:59:01 +0300 Subject: [PATCH 08/26] Added event hooks for the scripted block --- src/main/java/noppes/npcs/EventHooks.java | 105 ++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index ea784ccd4..a101614bf 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -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); + } } \ No newline at end of file From 98e04797ca2d4a9a7e25869504dcad36eef0efcb Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:59:38 +0300 Subject: [PATCH 09/26] Added new GUI type for the script block script editing menu --- src/main/java/noppes/npcs/constants/EnumGuiType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/constants/EnumGuiType.java b/src/main/java/noppes/npcs/constants/EnumGuiType.java index 5d320c506..fa40435cb 100644 --- a/src/main/java/noppes/npcs/constants/EnumGuiType.java +++ b/src/main/java/noppes/npcs/constants/EnumGuiType.java @@ -54,5 +54,6 @@ public enum EnumGuiType { CompanionTrader, ManageLinked, CustomGui, - ScriptItem; + ScriptItem, + ScriptBlock; } From 1c1deb7e525fdcc2a75412afe47d18b3fab84912 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 17:32:43 +0300 Subject: [PATCH 10/26] Fixed texture linking --- src/main/java/noppes/npcs/CustomItems.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/CustomItems.java b/src/main/java/noppes/npcs/CustomItems.java index 1014df955..e59feb1d1 100644 --- a/src/main/java/noppes/npcs/CustomItems.java +++ b/src/main/java/noppes/npcs/CustomItems.java @@ -243,7 +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).setBlockName("customnpcs:npcScripted"); + 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"); From e2634cd4ecc2d3bec4e1c1e2808b143410725f80 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 17:33:20 +0300 Subject: [PATCH 11/26] Fixed wrong tile entity cast --- src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java b/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java index 4241c793d..dbb8aae69 100644 --- a/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java +++ b/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java @@ -19,7 +19,7 @@ public class BlockScriptedWrapper extends ScriptBlock implements IBlockScripted{ public BlockScriptedWrapper(World world, Block block, int x, int y, int z) { super(world, block, new BlockPos(x,y,z)); - tile = (TileScripted) super.tile; + tile = (TileScripted) super.tile.getMCTileEntity(); } @Override From 9fb58981c4b212ddf25daec851a23e26ceb264c5 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 18:48:22 +0300 Subject: [PATCH 12/26] Fixed scripted block rendering --- .../noppes/npcs/blocks/BlockScripted.java | 12 ++++- .../blocks/BlockScriptedRenderer.java | 53 +++++++++++++------ 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/main/java/noppes/npcs/blocks/BlockScripted.java b/src/main/java/noppes/npcs/blocks/BlockScripted.java index a2d2e6c31..86bf6be75 100644 --- a/src/main/java/noppes/npcs/blocks/BlockScripted.java +++ b/src/main/java/noppes/npcs/blocks/BlockScripted.java @@ -100,12 +100,20 @@ public class BlockScripted extends BlockContainer { } @Override - public boolean isOpaqueCube() { + public boolean canRenderInPass(int pass) { return false; } @Override - public boolean isNormalCube() { + public int getRenderType() { + return 0; + } + @Override + public boolean isOpaqueCube() { + return false; + } + + public boolean renderAsNormalBlock() { return false; } diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java index 923f529bb..baa98acff 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java @@ -13,11 +13,15 @@ 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; @@ -27,7 +31,7 @@ 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 @@ -40,7 +44,7 @@ public class BlockScriptedRenderer extends BlockRendererInterface{ GlStateManager.translate(x + 0.5, y, z + 0.5); if(overrideModel()){ GlStateManager.translate(0, 0.5, 0); - renderItem(new ItemStack(CustomItems.scripted)); + renderItem(te, new ItemStack(CustomItems.scripted)); } else{ GlStateManager.rotate(tile.rotationY, 0, 1, 0); @@ -50,11 +54,11 @@ public class BlockScriptedRenderer extends BlockRendererInterface{ Block b = tile.blockModel; if(b == null || b == Blocks.air){ GlStateManager.translate(0, 0.5, 0); - renderItem(tile.itemModel); + renderItem(te, tile.itemModel); } else if(b == CustomItems.scripted){ GlStateManager.translate(0, 0.5, 0); - renderItem(tile.itemModel); + renderItem(te, tile.itemModel); } else{ int meta = tile.itemModel.getItemDamage(); @@ -148,17 +152,36 @@ public class BlockScriptedRenderer extends BlockRendererInterface{ GlStateManager.popMatrix(); } - private void renderItem(ItemStack stack){ - IIcon icon = stack.getItem().getIcon(stack, 0); - if(icon != null) { - Color color = new Color(stack.getItem().getColorFromItemStack(stack, 0)); - 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(); - ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); - GL11.glColor3f(1F, 1F, 1F); + 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())); + } + } } } From 7602f7509a4f9300f62d83d3f805377e6948b8e2 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 21:58:51 +0300 Subject: [PATCH 13/26] Fixed scripted block AABB collision --- src/main/java/noppes/npcs/blocks/BlockScripted.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/blocks/BlockScripted.java b/src/main/java/noppes/npcs/blocks/BlockScripted.java index 86bf6be75..32396dc27 100644 --- a/src/main/java/noppes/npcs/blocks/BlockScripted.java +++ b/src/main/java/noppes/npcs/blocks/BlockScripted.java @@ -42,7 +42,7 @@ public class BlockScripted extends BlockContainer { TileScripted tile = (TileScripted) world.getTileEntity(x, y, z); if (tile != null && tile.isPassible) return AABB_EMPTY; - return AABB; + return AABB.getOffsetBoundingBox(x,y,z); } @Override @@ -50,7 +50,7 @@ public class BlockScripted extends BlockContainer { TileScripted tile = (TileScripted) world.getTileEntity(x, y, z); if (tile != null && tile.isPassible) return AABB_EMPTY; - return AABB; + return AABB.getOffsetBoundingBox(x,y,z); } @Override From 72d339ff69611a92b7d94042d4081aacadc32bce Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 22:16:26 +0300 Subject: [PATCH 14/26] Added a script editing GUI for the script block --- .../client/gui/script/GuiScriptBlock.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java new file mode 100644 index 000000000..f1425807a --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java @@ -0,0 +1,37 @@ +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("tossed"); + hookList.add("pickedUp"); + hookList.add("spawn"); + hookList.add("interact"); + hookList.add("attack"); + hookList.add("startItem"); + hookList.add("usingItem"); + hookList.add("stopItem"); + hookList.add("finishItem"); + + this.handler = this.tileScripted = (TileScripted) player.worldObj.getTileEntity(x, y, z); + Client.sendData(EnumPacketServer.ScriptBlockDataGet); + } + + 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())); + } +} \ No newline at end of file From 7562d9a545a3a7365e67532c2fbcc031e42e4cb0 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 22:16:36 +0300 Subject: [PATCH 15/26] Registered a script editing GUI for the script block --- src/main/java/noppes/npcs/client/ClientProxy.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index b5eb05270..ccfb16114 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -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.*; @@ -376,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; } From 32abb0f0eaea3e226c47168b486cdba6030ccdf5 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 22:17:24 +0300 Subject: [PATCH 16/26] Added scripted block data synchronisation --- .../java/noppes/npcs/PacketHandlerServer.java | 25 +++++++++++++++++++ .../npcs/constants/EnumPacketServer.java | 2 ++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index d163b7a7a..d42ee8e39 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -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; @@ -175,6 +177,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) @@ -339,6 +343,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(); diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index fb776be91..dbace0dde 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -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), From 7f4fd1305e78b4a9995bab470ae29e679a2e21aa Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 22:35:19 +0300 Subject: [PATCH 17/26] Added hook names to block events --- .../npcs/scripted/event/BlockEvent.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/event/BlockEvent.java b/src/main/java/noppes/npcs/scripted/event/BlockEvent.java index ce71e1114..4da245610 100644 --- a/src/main/java/noppes/npcs/scripted/event/BlockEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/BlockEvent.java @@ -8,6 +8,7 @@ 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 { @@ -43,6 +44,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public float getDistanceFallen() { return distanceFallen; } + + @Override + public String getHookName() { + return EnumScriptType.FALLEN_UPON.function; + } } /** @@ -90,6 +96,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public int getSide() { return side; } + + @Override + public String getHookName() { + return EnumScriptType.INTERACT.function; + } } /** @@ -112,6 +123,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public int getPower() { return power; } + + @Override + public String getHookName() { + return EnumScriptType.REDSTONE.function; + } } @@ -122,6 +138,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public BreakEvent(IBlock block) { super(block); } + + @Override + public String getHookName() { + return EnumScriptType.BROKEN.function; + } } /** @@ -132,6 +153,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public ExplodedEvent(IBlock block) { super(block); } + + @Override + public String getHookName() { + return EnumScriptType.EXPLODED.function; + } } /** @@ -141,6 +167,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public RainFillEvent(IBlock block) { super(block); } + + @Override + public String getHookName() { + return EnumScriptType.RAIN_FILLED.function; + } } /** @@ -157,6 +188,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public IPos getChangedPos() { return changedPos; } + + @Override + public String getHookName() { + return EnumScriptType.NEIGHBOR_CHANGED.function; + } } /** @@ -166,6 +202,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public InitEvent(IBlock block) { super(block); } + + @Override + public String getHookName() { + return EnumScriptType.INIT.function; + } } /** @@ -175,6 +216,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public UpdateEvent(IBlock block) { super(block); } + + @Override + public String getHookName() { + return EnumScriptType.TICK.function; + } } /** @@ -191,6 +237,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public IPlayer getPlayer() { return player; } + + @Override + public String getHookName() { + return EnumScriptType.CLICKED.function; + } } /** @@ -208,6 +259,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public IPlayer getPlayer() { return player; } + + @Override + public String getHookName() { + return EnumScriptType.HARVESTED.function; + } } /** @@ -224,6 +280,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public IEntity getEntity() { return entity; } + + @Override + public String getHookName() { + return EnumScriptType.COLLIDE.function; + } } /** @@ -241,6 +302,11 @@ public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public int getId() { return id; } + + @Override + public String getHookName() { + return EnumScriptType.TIMER.function; + } } } From d8ba55903308b99b70976d0bc62bdd3076adf003 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 22:39:22 +0300 Subject: [PATCH 18/26] Added hook lost to the scripted block GUI --- .../npcs/client/gui/script/GuiScriptBlock.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java index f1425807a..764129d6c 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java @@ -11,15 +11,17 @@ public class GuiScriptBlock extends GuiScriptInterface { public GuiScriptBlock(int x, int y, int z) { hookList.add("init"); hookList.add("tick"); - hookList.add("tossed"); - hookList.add("pickedUp"); - hookList.add("spawn"); hookList.add("interact"); - hookList.add("attack"); - hookList.add("startItem"); - hookList.add("usingItem"); - hookList.add("stopItem"); - hookList.add("finishItem"); + 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); From 34cc0fecdf33f7a1a50ce615c9269123a0eb7449 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 22:48:48 +0300 Subject: [PATCH 19/26] Fixed script block GUI data synchronisation --- src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java index 764129d6c..5a80b64af 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptBlock.java @@ -24,7 +24,7 @@ public class GuiScriptBlock extends GuiScriptInterface { hookList.add("timer"); this.handler = this.tileScripted = (TileScripted) player.worldObj.getTileEntity(x, y, z); - Client.sendData(EnumPacketServer.ScriptBlockDataGet); + Client.sendData(EnumPacketServer.ScriptBlockDataGet, tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord); } public void setGuiData(NBTTagCompound compound) { From ed3028561b67249303d4ab4214e058395c595ea9 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 23:38:06 +0300 Subject: [PATCH 20/26] Fixed model setting and client synchronisation --- .../java/noppes/npcs/blocks/tiles/TileScripted.java | 3 ++- .../noppes/npcs/scripted/BlockScriptedWrapper.java | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java b/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java index b03d03e30..f214e8284 100644 --- a/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java +++ b/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java @@ -106,7 +106,7 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler { } public void setDisplayNBT(NBTTagCompound compound){ itemModel = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("ScriptBlockModel")); - if(itemModel.stackSize == 0) + if(itemModel==null || itemModel.stackSize == 0) itemModel = new ItemStack(Item.getItemFromBlock(CustomItems.scripted)); if(compound.hasKey("ScriptBlockModelBlock")) blockModel = Block.getBlockFromName(compound.getString("ScriptBlockModelBlock")); @@ -215,6 +215,7 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler { ticksExisted = 0; if(needsClientUpdate){ markDirty(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); worldObj.notifyBlocksOfNeighborChange(xCoord,yCoord,zCoord,getBlockType(),3); needsClientUpdate = false; } diff --git a/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java b/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java index dbb8aae69..1e02ea0de 100644 --- a/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java +++ b/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java @@ -36,7 +36,15 @@ public class BlockScriptedWrapper extends ScriptBlock implements IBlockScripted{ tile.setItemModel(null, null); else{ Block block = Block.getBlockFromName(name); - tile.setItemModel(new ItemStack(Item.getItemFromBlock(block)), block); + 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); + } + } } } From 75f16702fd1c3c8fb1c1b1c932ffc720adafb08a Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 23:38:34 +0300 Subject: [PATCH 21/26] Fixed scripted block rendering --- .../blocks/BlockScriptedRenderer.java | 46 ++----------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java index baa98acff..75f1f825c 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java @@ -51,48 +51,8 @@ public class BlockScriptedRenderer extends BlockRendererInterface{ GlStateManager.rotate(tile.rotationX, 1, 0, 0); GlStateManager.rotate(tile.rotationZ, 0, 0, 1); GlStateManager.scale(tile.scaleX, tile.scaleY, tile.scaleZ); - Block b = tile.blockModel; - if(b == null || b == Blocks.air){ - GlStateManager.translate(0, 0.5, 0); - renderItem(te, tile.itemModel); - } - else if(b == CustomItems.scripted){ - GlStateManager.translate(0, 0.5, 0); - renderItem(te, tile.itemModel); - } - else{ - int meta = tile.itemModel.getItemDamage(); - renderBlock(tile, b); - - if(b.hasTileEntity(meta) && !tile.renderTileErrored){ - try{ - if(tile.renderTile == null){ - TileEntity entity = b.createTileEntity(te.getWorldObj(), meta); - entity.zCoord=tile.zCoord; - entity.yCoord=tile.yCoord; - entity.xCoord=tile.xCoord; - entity.setWorldObj(te.getWorldObj()); - ObfuscationReflectionHelper.setPrivateValue(TileEntity.class, entity, tile.itemModel.getItemDamage(), 5); - ObfuscationReflectionHelper.setPrivateValue(TileEntity.class, entity, b, 6); - tile.renderTile = entity; - if(entity instanceof ITickable){ - tile.renderTileUpdate = (ITickable) entity; - } - } - TileEntitySpecialRenderer renderer = TileEntityRendererDispatcher.instance.getSpecialRenderer(tile.renderTile); - - if(renderer != null){ - renderer.renderTileEntityAt(tile.renderTile, -0.5, 0, -0.5, partialTicks); - - } - else - tile.renderTileErrored = true; - } - catch(Exception e){ - tile.renderTileErrored = true; - } - } - } + GlStateManager.translate(0, 0.5, 0); + renderItem(te, tile.itemModel); } GlStateManager.popMatrix(); @@ -193,7 +153,7 @@ public class BlockScriptedRenderer extends BlockRendererInterface{ GlStateManager.enableBlend(); GlStateManager.disableCull(); GlStateManager.translate(-0.5F, -0, 0.5F); - RenderBlocks.getInstance().renderStandardBlock(b, tile.xCoord, tile.yCoord, tile.zCoord); + 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(); From 38cdc25ceb1a237f3a01b1b7fedc612126df8195 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 23:48:58 +0300 Subject: [PATCH 22/26] Fixed scripted block not saving its data --- src/main/java/noppes/npcs/blocks/tiles/TileScripted.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java b/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java index f214e8284..44596f7e6 100644 --- a/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java +++ b/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java @@ -145,6 +145,7 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler { @Override public void writeToNBT(NBTTagCompound compound){ + super.writeToNBT(compound); getNBT(compound); getDisplayNBT(compound); timers.writeToNBT(compound); From 54f4ed5c16a3f1b0b77d496eaf5d1593c16dc3c9 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 22 Jan 2024 08:05:03 +0300 Subject: [PATCH 23/26] Added timer integration --- src/main/java/noppes/npcs/entity/data/DataTimers.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/noppes/npcs/entity/data/DataTimers.java b/src/main/java/noppes/npcs/entity/data/DataTimers.java index 5dd521dd7..7e63dd61b 100644 --- a/src/main/java/noppes/npcs/entity/data/DataTimers.java +++ b/src/main/java/noppes/npcs/entity/data/DataTimers.java @@ -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); + } } } } From b42ab9425106d518ddf25fbc628626838a902e22 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 22 Jan 2024 19:50:40 +0300 Subject: [PATCH 24/26] Fixed redstone event --- src/main/java/noppes/npcs/blocks/BlockScripted.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/blocks/BlockScripted.java b/src/main/java/noppes/npcs/blocks/BlockScripted.java index 32396dc27..0a08b68a1 100644 --- a/src/main/java/noppes/npcs/blocks/BlockScripted.java +++ b/src/main/java/noppes/npcs/blocks/BlockScripted.java @@ -207,10 +207,15 @@ public class BlockScripted extends BlockContainer { 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.isBlockProvidingPowerTo(x + enumfacing.getFrontOffsetX(), + int p = world.getIndirectPowerLevelTo(x + enumfacing.getFrontOffsetX(), y + enumfacing.getFrontOffsetZ(), z + enumfacing.getFrontOffsetZ(), enumfacing.ordinal()); if (p > power) power = p; From d6875c4ecc53fd6c8eca38db21fb52ede8aaba00 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 22 Jan 2024 20:30:54 +0300 Subject: [PATCH 25/26] Implemented storeddata and tempdata --- .../npcs/blocks/tiles/TileScripted.java | 24 +++- .../npcs/scripted/BlockScriptedWrapper.java | 109 ++++++++++++++++++ 2 files changed, 128 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java b/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java index 44596f7e6..af40b6eca 100644 --- a/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java +++ b/src/main/java/noppes/npcs/blocks/tiles/TileScripted.java @@ -21,21 +21,21 @@ 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.INpcScriptHandler; 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.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.TreeMap; public class TileScripted extends TileEntity implements IScriptBlockHandler { public List scripts = new ArrayList<>(); + public Map tempData = new HashMap<>(); + + private NBTTagCompound customTileData; + public String scriptLanguage = "ECMAScript"; public boolean enabled = false; @@ -89,6 +89,10 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler { setNBT(compound); setDisplayNBT(compound); timers.readFromNBT(compound); + NBTTagCompound extraData = compound.getCompoundTag("ExtraData"); + if(!extraData.hasNoTags()){ + getTileData().setTag("CustomNPCsData", extraData); + } } public void setNBT(NBTTagCompound compound){ @@ -149,6 +153,7 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler { getNBT(compound); getDisplayNBT(compound); timers.writeToNBT(compound); + compound.setTag("ExtraData",getTileData().getTag("CustomNPCsData")); } public NBTTagCompound getNBT(NBTTagCompound compound){ @@ -395,6 +400,15 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler { .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; diff --git a/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java b/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java index 1e02ea0de..33b97e4c1 100644 --- a/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java +++ b/src/main/java/noppes/npcs/scripted/BlockScriptedWrapper.java @@ -3,6 +3,9 @@ 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; @@ -14,6 +17,8 @@ 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; @@ -202,5 +207,109 @@ public class BlockScriptedWrapper extends ScriptBlock implements IBlockScripted{ 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)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()]); + } } From 7e425fd7818bee5cfed1980258d18c5cf249a95d Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 22 Jan 2024 20:32:36 +0300 Subject: [PATCH 26/26] Changed api branch --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index 0895815b3..7200c08d3 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 0895815b34f1278cbe06fe70a4432893e0d2dea4 +Subproject commit 7200c08d3219a5635721f5db1bc3d9721c63b1d5