From f2f8b63ae5cf43fe8ed8fed9d1283e9a26261506 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Wed, 3 Jan 2024 11:08:58 +0300 Subject: [PATCH 01/40] Fixed bug with stuck projectiles --- src/main/java/noppes/npcs/entity/EntityProjectile.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/noppes/npcs/entity/EntityProjectile.java b/src/main/java/noppes/npcs/entity/EntityProjectile.java index f97c908bd..ebe761a1c 100644 --- a/src/main/java/noppes/npcs/entity/EntityProjectile.java +++ b/src/main/java/noppes/npcs/entity/EntityProjectile.java @@ -220,6 +220,9 @@ public class EntityProjectile extends EntityThrowable { public void onUpdate() { super.onEntityUpdate(); + if (ticksExisted == 400) { + this.setDead(); + } if(++ticksExisted % 10 == 0){ EventHooks.onProjectileTick(this); } From a412ce6008a6ce46878589101481f201e8d5a03e Mon Sep 17 00:00:00 2001 From: Goodbird Date: Wed, 3 Jan 2024 11:33:46 +0300 Subject: [PATCH 02/40] Fixed NPE spam to log --- src/main/java/noppes/npcs/client/model/part/ModelLegs.java | 2 ++ src/main/java/noppes/npcs/client/model/part/ModelTail.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java index 0d87b4512..db997f28e 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java @@ -229,6 +229,8 @@ public class ModelLegs extends ModelScaleRenderer{ } public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity entity) { + if(this.entity==null) return; + ModelPartData part = this.entity.modelData.legParts; rotationPointZ = 0; rotationPointY = 0; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelTail.java b/src/main/java/noppes/npcs/client/model/part/ModelTail.java index f8ddd87c6..b80fe6318 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelTail.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelTail.java @@ -82,6 +82,8 @@ public class ModelTail extends ModelScaleRenderer { public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity entity) { + if(this.entity==null) return; + rotateAngleY = MathHelper.cos(par1 * 0.6662F) * 0.3f * par2; rotateAngleX = MathHelper.sin(par3 * 0.067F) * 0.05F; From 57739e5de37e2537de908526cef5afac99ede35c Mon Sep 17 00:00:00 2001 From: Goodbird Date: Wed, 3 Jan 2024 11:52:14 +0300 Subject: [PATCH 03/40] Fixed book and big sign not saving their contents From 1e8d2fa1a0967369e66b4747ac5f7dcf719a6d7e Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 18 Jan 2024 14:47:15 -0500 Subject: [PATCH 04/40] Kill Projectile after a Minute --- src/main/java/noppes/npcs/entity/EntityProjectile.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/entity/EntityProjectile.java b/src/main/java/noppes/npcs/entity/EntityProjectile.java index ebe761a1c..2a4a93f2b 100644 --- a/src/main/java/noppes/npcs/entity/EntityProjectile.java +++ b/src/main/java/noppes/npcs/entity/EntityProjectile.java @@ -220,7 +220,7 @@ public class EntityProjectile extends EntityThrowable { public void onUpdate() { super.onEntityUpdate(); - if (ticksExisted == 400) { + if (ticksExisted >= 1200) { this.setDead(); } if(++ticksExisted % 10 == 0){ @@ -265,7 +265,7 @@ public class EntityProjectile extends EntityThrowable { { ++this.ticksInGround; - if (this.ticksInGround == 1200) + if (this.ticksInGround >= 1200) { this.setDead(); } @@ -284,7 +284,7 @@ public class EntityProjectile extends EntityThrowable { { ++this.ticksInAir; - if (this.ticksInAir == 1200) + if (this.ticksInAir >= 1200) { this.setDead(); } From c26369c4801edc356c55cfe3a838ecbfbf9c1aaa Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 18 Jan 2024 16:15:33 -0500 Subject: [PATCH 05/40] Update API to have IScreenSize --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index fd31facd1..e3980ce21 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit fd31facd1260abe590cffe48fe3fd41c18f03f02 +Subproject commit e3980ce21720e963bb3d3169931885eb0bc60caa From bc4ab685fc62cb2631a59856cbc81b69c20e9f6a Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 18 Jan 2024 16:18:03 -0500 Subject: [PATCH 06/40] Fix Book and BigSign --- .../java/noppes/npcs/PacketHandlerPlayer.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index 36f247540..40924001f 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -271,38 +271,42 @@ public class PacketHandlerPlayer{ } } } - else if(type == EnumPlayerPacket.SignSave){ + else if(type == EnumPlayerPacket.SignSave) { int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt(); - TileEntity tile = player.worldObj.getTileEntity(x, y, z); - if(tile == null || !(tile instanceof TileBigSign)) - return; - TileBigSign sign = (TileBigSign) tile; - if(sign.canEdit){ - sign.setText(Server.readString(buffer)); - sign.canEdit = false; - player.worldObj.markBlockForUpdate(x, y, z); + if (player.worldObj.blockExists(x, y, z)) { + TileEntity tile = player.worldObj.getTileEntity(x, y, z); + if(!(tile instanceof TileBigSign)) + return; + TileBigSign sign = (TileBigSign) tile; + if (sign.canEdit) { + sign.setText(Server.readString(buffer)); + sign.canEdit = false; + player.worldObj.markBlockForUpdate(x, y, z); + } } } - else if(type == EnumPlayerPacket.SaveBook){ + else if(type == EnumPlayerPacket.SaveBook) { int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt(); - TileEntity tileentity = player.worldObj.getTileEntity(x, y, z); - if(!(tileentity instanceof TileBook)) - return; - TileBook tile = (TileBook) tileentity; - if(tile.book.getItem() == Items.written_book) - return; - boolean sign = buffer.readBoolean(); - ItemStack book = ItemStack.loadItemStackFromNBT(Server.readNBT(buffer)); - if(book == null) - return; - if(book.getItem() == Items.writable_book && !sign && ItemWritableBook.func_150930_a(book.getTagCompound())){ - tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8)); - } - if(book.getItem() == Items.written_book && sign && ItemEditableBook.validBookTagContents(book.getTagCompound())){ - tile.book.setTagInfo("author", new NBTTagString(player.getCommandSenderName())); - tile.book.setTagInfo("title", new NBTTagString(book.getTagCompound().getString("title"))); - tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8)); - tile.book.func_150996_a(Items.written_book); + if (player.worldObj.blockExists(x, y, z)) { + TileEntity tileentity = player.worldObj.getTileEntity(x, y, z); + if (!(tileentity instanceof TileBook)) + return; + TileBook tile = (TileBook) tileentity; + if (tile.book.getItem() == Items.written_book) + return; + boolean sign = buffer.readBoolean(); + ItemStack book = ItemStack.loadItemStackFromNBT(Server.readNBT(buffer)); + if (book == null) + return; + if (book.getItem() == Items.writable_book && !sign && ItemWritableBook.func_150930_a(book.getTagCompound())) { + tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8)); + } + if (book.getItem() == Items.written_book && sign && ItemEditableBook.validBookTagContents(book.getTagCompound())) { + tile.book.setTagInfo("author", new NBTTagString(player.getCommandSenderName())); + tile.book.setTagInfo("title", new NBTTagString(book.getTagCompound().getString("title"))); + tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8)); + tile.book.func_150996_a(Items.written_book); + } } } else if(type == EnumPlayerPacket.ScreenSize){ From 654ea09152e63ab5ccdcd0a9302eb089916323b8 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 21 Jan 2024 10:54:21 +0300 Subject: [PATCH 07/40] 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 08/40] 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 09/40] 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 10/40] 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 11/40] 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 12/40] 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 13/40] 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 14/40] 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 15/40] 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 16/40] 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 17/40] 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 18/40] 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 19/40] 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 20/40] 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 21/40] 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 22/40] 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 23/40] 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 24/40] 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 25/40] 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 26/40] 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 27/40] 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 28/40] 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 32d9869d4323725932b02d74408f116edd8a36ca Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 21 Jan 2024 22:26:25 -0600 Subject: [PATCH 29/40] Added yes/no subgui on clicking the disband button, colored text next to party leaders on the party list, and more lang text for the party gui --- .../client/gui/player/inventory/GuiParty.java | 66 ++++++++++++++----- .../assets/customnpcs/lang/en_US.lang | 16 +++++ 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index ce7dcfd30..c151d9a28 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -2,6 +2,8 @@ package noppes.npcs.client.gui.player.inventory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiYesNo; +import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; @@ -9,6 +11,7 @@ import net.minecraft.util.StatCollector; import noppes.npcs.client.Client; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.gui.SubGuiNpcTextArea; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.data.Party; @@ -17,9 +20,10 @@ import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.TabRegistry; import java.util.ArrayList; +import java.util.Collection; import java.util.UUID; -public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData { +public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData, GuiYesNoCallback { private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); private final EntityPlayer player; private Minecraft mc = Minecraft.getMinecraft(); @@ -48,13 +52,13 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT // //create party button // - GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 20, "Create Party"); + GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 20, "party.createParty"); createPartyButton.width = 100; this.addButton(createPartyButton); - this.addLabel(new GuiNpcLabel(201, "You're not in a party!", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 30)); - this.addLabel(new GuiNpcLabel(202, "Either wait for an invite", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 20)); - this.addLabel(new GuiNpcLabel(203, "or create one.", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 10)); + this.addLabel(new GuiNpcLabel(201, "party.partyInfo1", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 30)); + this.addLabel(new GuiNpcLabel(202, "party.partyInfo2", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 20)); + this.addLabel(new GuiNpcLabel(203, "party.partyInfo3", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 10)); //party invites list // @@ -64,11 +68,11 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT inviteScroll.guiTop = guiTop + 5; this.addScroll(inviteScroll); - GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "Accept"); + GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "party.accept"); acceptButton.width = 60; this.addButton(acceptButton); - GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 80, guiTop + ySize - 12, "Ignore"); + GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 80, guiTop + ySize - 12, "party.ignore"); ignoreButton.width = 60; this.addButton(ignoreButton); } else { @@ -79,28 +83,39 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT playerScroll.setSize(150, 160); playerScroll.guiLeft = guiLeft + 5; playerScroll.guiTop = guiTop + 5; - playerScroll.setList(new ArrayList<>(party.getPlayerNames())); + + ArrayList arrayList = new ArrayList<>(); + Collection playerNames = party.getPlayerNames(); + for (String s : playerNames) { + if (party.getPartyLeaderName().equals(s)) { + arrayList.add(s + " §e[" + StatCollector.translateToLocal("party.leader").toUpperCase() + "]"); + } else { + arrayList.add(s); + } + } + + playerScroll.setList(arrayList); this.addScroll(playerScroll); //set leader button // - GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "Make Leader"); + GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "party.makeLeader"); leaderButton.width = 70; this.addButton(leaderButton); //kick player button // - GuiNpcButton kickButton = new GuiNpcButton(315, guiLeft + 85, guiTop + ySize - 12, "Kick"); + GuiNpcButton kickButton = new GuiNpcButton(315, guiLeft + 85, guiTop + ySize - 12, "party.kick"); kickButton.width = 70; this.addButton(kickButton); //toggle friendly fire // - GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize/2 + 95, guiTop + ySize/2, new String[] {"On", "Off"}, 0); //party.friendlyFire() ? 0 : 1 + GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize/2 + 95, guiTop + ySize/2, new String[] {"gui.on", "gui.off"}, party.friendlyFire() ? 0 : 1); friendlyFireButton.width = 40; this.addButton(friendlyFireButton); - GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, "Friendly Fire:", guiLeft + xSize/2 + 20, guiTop + ySize/2 + 5); + GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, StatCollector.translateToLocal("party.friendlyFire") + ":", guiLeft + xSize/2 + 20, guiTop + ySize/2 + 5); this.addLabel(friendlyFireLabel); //send invite button (opens subgui) @@ -108,29 +123,48 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize/2 + 20, guiTop + ySize/2 + 40,100, 20, ""); this.addTextField(playerTextField); - GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize/2 + 125, guiTop + ySize/2 + 40, "Invite"); + GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize/2 + 125, guiTop + ySize/2 + 40, "party.invite"); inviteButton.width = 50; this.addButton(inviteButton); //disband party // - GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "Disband Party"); + GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.disbandParty"); disbandButton.width = 100; this.addButton(disbandButton); } } } + @Override + public void confirmClicked(boolean flag, int i) { + if (flag) { + switch (i) { + case 0: + Client.sendData(EnumPacketServer.DisbandParty); + receivedData = false; + initGui(); + break; + } + } + displayGuiScreen(this); + } + @Override protected void actionPerformed(GuiButton guibutton){ + Party party = ClientCacheHandler.party; + switch (guibutton.id) { case 200: Client.sendData(EnumPacketServer.CreateParty); receivedData = false; break; + case 320: + party.toggleFriendlyFire(); + break; case 335: - Client.sendData(EnumPacketServer.DisbandParty); - receivedData = false; + GuiYesNo guiyesno = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("party.disbandConfirm"), 0); + displayGuiScreen(guiyesno); break; } initGui(); diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 95c763d61..319863445 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -128,6 +128,22 @@ gui.filters=Filters gui.selectAll=Select All gui.deselectAll=Deselect All gui.loading=Loading +gui.off=Off +gui.on=On + +party.accept=Accept +party.createParty=Create Party +party.disbandParty=Disband Party +party.disbandConfirm=Are you sure you want to disband the party? +party.friendlyFire=Friendly Fire +party.ignore=Ignore +party.invite=Invite +party.kick=Kick +party.leader=Leader +party.makeLeader=Make Leader +party.partyInfo1=You're not in a party! +party.partyInfo2=Either wait for an invite +party.partyInfo3=or create one. scale.shared=Shared filter.contains=Contains From 54f4ed5c16a3f1b0b77d496eaf5d1593c16dc3c9 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 22 Jan 2024 08:05:03 +0300 Subject: [PATCH 30/40] 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 4abbb62e69a9f177ce0f102a1f9eb9fdd8bdaf2c Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Mon, 22 Jan 2024 00:57:59 -0600 Subject: [PATCH 31/40] -Parties: Kicking, inviting players, setting a leader, friendly fire toggle, and leaving a party are all functional over packets -Created a new type of achievement that uses the bag icon, used for party messages --- .../java/noppes/npcs/NoppesUtilServer.java | 4 + .../java/noppes/npcs/PacketHandlerServer.java | 39 +++++- .../java/noppes/npcs/ServerTickHandler.java | 15 +++ ...hievement.java => MessageAchievement.java} | 13 +- .../npcs/client/PacketHandlerClient.java | 5 +- .../client/gui/player/inventory/GuiParty.java | 121 ++++++++++++------ .../npcs/constants/EnumPacketClient.java | 1 + .../npcs/constants/EnumPacketServer.java | 2 +- .../noppes/npcs/controllers/data/Party.java | 66 ++++++---- .../npcs/controllers/data/PlayerData.java | 25 +++- .../assets/customnpcs/lang/en_US.lang | 6 + 11 files changed, 224 insertions(+), 73 deletions(-) rename src/main/java/noppes/npcs/client/{QuestAchievement.java => MessageAchievement.java} (59%) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index f790873ed..b4572f305 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -851,6 +851,10 @@ public class NoppesUtilServer { return null; } + static public EntityPlayer getPlayerByName(String playername){ + return MinecraftServer.getServer().getConfigurationManager().func_152612_a(playername); + } + public static Entity GetDamageSourcee(DamageSource damagesource) { Object entity = damagesource.getEntity(); if(entity == null) { diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index d163b7a7a..b8b8fcb6d 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -2,6 +2,7 @@ package noppes.npcs; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; import cpw.mods.fml.relauncher.Side; import foxz.utils.Market; @@ -123,12 +124,6 @@ public class PacketHandlerServer{ if (playerData.partyUUID != null) { Party party = PartyController.Instance().getParty(playerData.partyUUID); compound = party.writeToNBT(); - - Quest quest = (Quest) QuestController.Instance.get(party.getCurrentQuestID()); - if (quest != null) { - compound.setString("QuestName", quest.getName()); - compound.setString("QuestCategory", quest.getCategory().getName()); - } } Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else if (type == EnumPacketServer.DisbandParty) { @@ -140,6 +135,38 @@ public class PacketHandlerServer{ NBTTagCompound compound = new NBTTagCompound(); compound.setBoolean("Disband", true); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + } else if (type == EnumPacketServer.KickPlayer) { + EntityPlayer kickPlayer = NoppesUtilServer.getPlayerByName(Server.readString(buffer)); + if (kickPlayer != null) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + if (playerData.partyUUID != null) { + Party party = PartyController.Instance().getParty(playerData.partyUUID); + party.removePlayer(kickPlayer); + Server.sendData(player, EnumPacketClient.GUI_DATA, party.writeToNBT()); + } + } + } else if (type == EnumPacketServer.SavePartyData) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + if (playerData.partyUUID != null) { + Party party = PartyController.Instance().getParty(playerData.partyUUID); + party.readClientNBT(Server.readNBT(buffer)); + } + } else if (type == EnumPacketServer.SetPartyLeader) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + if (playerData.partyUUID != null) { + Party party = PartyController.Instance().getParty(playerData.partyUUID); + party.setLeader(NoppesUtilServer.getPlayerByName(Server.readString(buffer))); + Server.sendData(player, EnumPacketClient.GUI_DATA, party.writeToNBT()); + } + } else if (type == EnumPacketServer.PartyInvite) { + EntityPlayer invitedPlayer = NoppesUtilServer.getPlayerByName(Server.readString(buffer)); + if (invitedPlayer != null) { + PlayerData senderData = PlayerDataController.Instance.getPlayerData(player); + PlayerData invitedData = PlayerDataController.Instance.getPlayerData(invitedPlayer); + if (senderData.partyUUID != null && invitedData.partyUUID == null) {//only send invite if player is not in a party + invitedData.inviteToParty(PartyController.Instance().getParty(senderData.partyUUID)); + } + } } if(type.needsNpc && npc == null){ diff --git a/src/main/java/noppes/npcs/ServerTickHandler.java b/src/main/java/noppes/npcs/ServerTickHandler.java index 4ef57f89e..661c7d4a5 100644 --- a/src/main/java/noppes/npcs/ServerTickHandler.java +++ b/src/main/java/noppes/npcs/ServerTickHandler.java @@ -7,6 +7,8 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase; import net.minecraft.server.MinecraftServer; import net.minecraft.world.WorldServer; import noppes.npcs.client.AnalyticsTracking; +import noppes.npcs.controllers.PlayerDataController; +import noppes.npcs.controllers.data.PlayerData; import java.net.InetAddress; import java.net.UnknownHostException; @@ -40,5 +42,18 @@ public class ServerTickHandler { serverName = e; } AnalyticsTracking.sendData(event.player, "join", serverName); + + PlayerData playerData = PlayerDataController.Instance.getPlayerData(event.player); + if (playerData != null) { + playerData.onLogin(); + } + } + + @SubscribeEvent + public void playerLogout(PlayerEvent.PlayerLoggedOutEvent event) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(event.player); + if (playerData != null) { + playerData.onLogout(); + } } } diff --git a/src/main/java/noppes/npcs/client/QuestAchievement.java b/src/main/java/noppes/npcs/client/MessageAchievement.java similarity index 59% rename from src/main/java/noppes/npcs/client/QuestAchievement.java rename to src/main/java/noppes/npcs/client/MessageAchievement.java index 98c24fc3f..464ca1a43 100644 --- a/src/main/java/noppes/npcs/client/QuestAchievement.java +++ b/src/main/java/noppes/npcs/client/MessageAchievement.java @@ -1,20 +1,27 @@ package noppes.npcs.client; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.stats.Achievement; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; import noppes.npcs.CustomItems; -public class QuestAchievement extends Achievement{ +public class MessageAchievement extends Achievement{ private String description; private String message; - public QuestAchievement(String message, String description) { - super("",message, 0, 0, CustomItems.letter==null?Items.paper:CustomItems.letter, null); + + public MessageAchievement(Item item, String message, String description) { + super("",message, 0, 0, item, null); this.description = description; this.message = message; } + + public MessageAchievement(String message, String description) { + this(CustomItems.letter==null ? Items.paper : CustomItems.letter, message, description); + } + @Override public IChatComponent func_150951_e() { diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index d7a0c6365..8c06befaa 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -9,6 +9,7 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.achievement.GuiAchievement; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -76,10 +77,10 @@ public class PacketHandlerClient extends PacketHandlerServer{ player.addChatMessage(new ChatComponentTranslation(message)); } - else if(type == EnumPacketClient.MESSAGE){ + else if(type == EnumPacketClient.MESSAGE || type == EnumPacketClient.PARTY_MESSAGE){ String description = StatCollector.translateToLocal(Server.readString(buffer)); String message = Server.readString(buffer); - Achievement ach = new QuestAchievement(message, description); + Achievement ach = type == EnumPacketClient.MESSAGE ? new MessageAchievement(message, description) : new MessageAchievement(CustomItems.bag == null ? Items.paper : CustomItems.bag, message, description); Minecraft.getMinecraft().guiAchievement.func_146256_a(ach); ObfuscationReflectionHelper.setPrivateValue(GuiAchievement.class, Minecraft.getMinecraft().guiAchievement, ach.getDescription(), 4); } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index c151d9a28..e08e36672 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -11,7 +11,6 @@ import net.minecraft.util.StatCollector; import noppes.npcs.client.Client; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.CustomNpcResourceListener; -import noppes.npcs.client.gui.SubGuiNpcTextArea; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.data.Party; @@ -30,6 +29,10 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT private boolean receivedData; private long renderTicks; + private String selectedPlayer; + + private boolean partyChanged = false; + private boolean isLeader; public GuiParty(EntityPlayer player) { super(); @@ -97,41 +100,49 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT playerScroll.setList(arrayList); this.addScroll(playerScroll); - //set leader button - // - GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "party.makeLeader"); - leaderButton.width = 70; - this.addButton(leaderButton); + if (this.isLeader) { + //set leader button + // + GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "party.makeLeader"); + leaderButton.width = 70; + this.addButton(leaderButton); - //kick player button - // - GuiNpcButton kickButton = new GuiNpcButton(315, guiLeft + 85, guiTop + ySize - 12, "party.kick"); - kickButton.width = 70; - this.addButton(kickButton); + //kick player button + // + GuiNpcButton kickButton = new GuiNpcButton(310, guiLeft + 85, guiTop + ySize - 12, "party.kick"); + kickButton.width = 70; + this.addButton(kickButton); - //toggle friendly fire - // - GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize/2 + 95, guiTop + ySize/2, new String[] {"gui.on", "gui.off"}, party.friendlyFire() ? 0 : 1); - friendlyFireButton.width = 40; - this.addButton(friendlyFireButton); + //toggle friendly fire + // + GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize / 2 + 95, guiTop + ySize / 2, new String[]{"gui.on", "gui.off"}, party.friendlyFire() ? 0 : 1); + friendlyFireButton.width = 40; + this.addButton(friendlyFireButton); - GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, StatCollector.translateToLocal("party.friendlyFire") + ":", guiLeft + xSize/2 + 20, guiTop + ySize/2 + 5); - this.addLabel(friendlyFireLabel); + GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, StatCollector.translateToLocal("party.friendlyFire") + ":", guiLeft + xSize / 2 + 20, guiTop + ySize / 2 + 5); + this.addLabel(friendlyFireLabel); - //send invite button (opens subgui) - // - GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize/2 + 20, guiTop + ySize/2 + 40,100, 20, ""); - this.addTextField(playerTextField); + //send invite button (opens subgui) + // + GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize / 2 + 20, guiTop + ySize / 2 + 40, 100, 20, ""); + this.addTextField(playerTextField); - GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize/2 + 125, guiTop + ySize/2 + 40, "party.invite"); - inviteButton.width = 50; - this.addButton(inviteButton); + GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize / 2 + 125, guiTop + ySize / 2 + 40, "party.invite"); + inviteButton.width = 50; + this.addButton(inviteButton); - //disband party - // - GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.disbandParty"); - disbandButton.width = 100; - this.addButton(disbandButton); + //disband party + // + GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.leaveParty"); + disbandButton.width = 100; + this.addButton(disbandButton); + } else { + //leave party + // + GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.disbandParty"); + disbandButton.width = 100; + this.addButton(disbandButton); + } } } } @@ -141,11 +152,20 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT if (flag) { switch (i) { case 0: + Client.sendData(EnumPacketServer.SetPartyLeader, this.selectedPlayer); + break; + case 1: + Client.sendData(EnumPacketServer.KickPlayer, this.selectedPlayer); + break; + case 2: Client.sendData(EnumPacketServer.DisbandParty); - receivedData = false; - initGui(); + break; + case 3: + Client.sendData(EnumPacketServer.KickPlayer, this.player.getCommandSenderName()); break; } + receivedData = false; + initGui(); } displayGuiScreen(this); } @@ -159,12 +179,37 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT Client.sendData(EnumPacketServer.CreateParty); receivedData = false; break; + case 305: + if (!party.getPartyLeaderName().equals(this.selectedPlayer)) { + GuiYesNo yesnoLeader = new GuiYesNo(this, StatCollector.translateToLocal("party.leaderConfirm"), this.selectedPlayer, 0); + displayGuiScreen(yesnoLeader); + } + break; + case 310: + if (!party.getPartyLeaderName().equals(this.selectedPlayer)) { + GuiYesNo yesnoKick = new GuiYesNo(this, StatCollector.translateToLocal("party.kickConfirm"), this.selectedPlayer, 1); + displayGuiScreen(yesnoKick); + } + break; case 320: party.toggleFriendlyFire(); + this.partyChanged = true; + break; + case 330: + String inviteName = this.getTextField(325).getText(); + if (!inviteName.isEmpty() && !party.getPlayerNames(true).contains(inviteName.toLowerCase())) { + Client.sendData(EnumPacketServer.PartyInvite, inviteName); + this.getTextField(325).setText(""); + } break; case 335: - GuiYesNo guiyesno = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("party.disbandConfirm"), 0); - displayGuiScreen(guiyesno); + if (this.isLeader) { + GuiYesNo yesnoDisband = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("party.disbandConfirm"), 2); + displayGuiScreen(yesnoDisband); + } else { + GuiYesNo yesnoLeave = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("party.leaveConfirm"), 3); + displayGuiScreen(yesnoLeave); + } break; } initGui(); @@ -233,8 +278,10 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT party = ClientCacheHandler.party; } party.readFromNBT(compound); + this.isLeader = ClientCacheHandler.party.getPartyLeaderName().equals(this.player.getCommandSenderName()); } else if (compound.hasKey("Disband")) { ClientCacheHandler.party = null; + this.isLeader = false; } initGui(); @@ -248,12 +295,14 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT @Override public void save() { - + if (this.partyChanged) { + Client.sendData(EnumPacketServer.SavePartyData, ClientCacheHandler.party.writeClientNBT()); + } } @Override public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { - + this.selectedPlayer = guiCustomScroll.getSelected(); } @Override diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 091588edd..3bca0b655 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -4,6 +4,7 @@ noppes.npcs.constants; public enum EnumPacketClient { CHAT, MESSAGE, + PARTY_MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index fb776be91..fed898905 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -95,7 +95,7 @@ public enum EnumPacketServer { CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, - CreateParty, GetPartyData, DisbandParty, + SavePartyData, CreateParty, GetPartyData, DisbandParty, KickPlayer, PartyInvite, SetPartyLeader, ServerUpdateSkinOverlays; diff --git a/src/main/java/noppes/npcs/controllers/data/Party.java b/src/main/java/noppes/npcs/controllers/data/Party.java index 3f9c95d75..cb09b3636 100644 --- a/src/main/java/noppes/npcs/controllers/data/Party.java +++ b/src/main/java/noppes/npcs/controllers/data/Party.java @@ -2,6 +2,7 @@ package noppes.npcs.controllers.data; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; @@ -27,7 +28,6 @@ public class Party { private final ArrayList partyOrder = new ArrayList<>(); private int currentQuestID = -1; - private boolean friendlyFire; //Client-sided @@ -66,12 +66,10 @@ public class Party { return true; } - public boolean removePlayer(String playerName) { - UUID uuid = getUUID(playerName); - if (uuid == null){ - return false; - } + public boolean removePlayer(EntityPlayer player) { + if (player == null) return false; + UUID uuid = player.getUniqueID(); if(partyMembers.containsKey(uuid)){ partyMembers.remove(uuid); partyOrder.remove(uuid); @@ -88,22 +86,8 @@ public class Party { return false; } - public boolean removePlayer(EntityPlayer player) { - UUID uuid = player.getUniqueID(); - if(partyMembers.containsKey(uuid)){ - partyMembers.remove(uuid); - partyOrder.remove(uuid); - - if(uuid.equals(partyLeader)){ - if(partyMembers.size() > 0){ - partyLeader = partyOrder.get(0); - } - } - - return true; - } - - return false; + public boolean removePlayer(String playerName) { + return playerName != null && this.removePlayer(NoppesUtilServer.getPlayerByName(playerName)); } public boolean hasPlayer(EntityPlayer player) { @@ -149,7 +133,20 @@ public class Party { } public Collection getPlayerNames() { - return this.partyMembers.values(); + return this.getPlayerNames(false); + } + + public Collection getPlayerNames(boolean lowercase) { + Collection names = this.partyMembers.values(); + if (!lowercase) { + return names; + } + + ArrayList lowerNames = new ArrayList<>(); + for (String s : names) { + lowerNames.add(s.toLowerCase()); + } + return lowerNames; } public Collection getPlayerUUIDs() { @@ -215,6 +212,7 @@ public class Party { public void readFromNBT(NBTTagCompound compound) { this.partyLeaderName = compound.getString("PartyLeader"); this.currentQuestID = compound.getInteger("PartyQuestID"); + this.friendlyFire = compound.getBoolean("FriendlyFire"); NBTTagList list = compound.getTagList("PartyMembers", 10); for (int i = 0; i < list.tagCount(); i++) { @@ -231,7 +229,8 @@ public class Party { compound.setString("PartyUUID", this.partyUUID.toString()); compound.setInteger("PartyQuestID", this.currentQuestID); - compound.setString("PartyLeader", getPartyLeader().getCommandSenderName()); + compound.setBoolean("FriendlyFire", this.friendlyFire); + NBTTagList list = new NBTTagList(); for (UUID uuid : this.partyOrder) { NBTTagCompound uuidCompound = new NBTTagCompound(); @@ -241,6 +240,25 @@ public class Party { } compound.setTag("PartyMembers", list); + compound.setString("PartyLeader", getPartyLeader().getCommandSenderName()); + Quest quest = (Quest) QuestController.Instance.get(this.getCurrentQuestID()); + if (quest != null) { + compound.setString("QuestName", quest.getName()); + compound.setString("QuestCategory", quest.getCategory().getName()); + } + + return compound; + } + + public void readClientNBT(NBTTagCompound compound) { + this.currentQuestID = compound.getInteger("PartyQuestID"); + this.friendlyFire = compound.getBoolean("FriendlyFire"); + } + + public NBTTagCompound writeClientNBT() { + NBTTagCompound compound = new NBTTagCompound(); + compound.setInteger("PartyQuestID", this.currentQuestID); + compound.setBoolean("FriendlyFire", this.friendlyFire); return compound; } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index f5a3ca9a9..cec4b7356 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -2,14 +2,17 @@ package noppes.npcs.controllers.data; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; import noppes.npcs.LogWriter; +import noppes.npcs.Server; import noppes.npcs.api.entity.ICustomNpc; import noppes.npcs.api.handler.*; import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumRoleType; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.entity.EntityCustomNpc; @@ -24,6 +27,7 @@ import noppes.npcs.util.NBTJsonUtil; import java.io.File; import java.io.FileOutputStream; +import java.util.HashSet; import java.util.UUID; public class PlayerData implements IExtendedEntityProperties, IPlayerData { @@ -41,7 +45,9 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public EntityNPCInterface editingNpc; public NBTTagCompound cloned; + public UUID partyUUID = null; + private final HashSet partyInvites = new HashSet<>(); public EntityPlayer player; @@ -55,6 +61,15 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public ScreenSize screenSize = new ScreenSize(-1,-1); + public void onLogin() { + + } + + public void onLogout() { + this.partyUUID = null; + this.partyInvites.clear(); + } + @Override public void saveNBTData(NBTTagCompound nbtTagCompound) { } @@ -128,7 +143,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { @Override public void init(Entity entity, World world) { - + } public void setGUIOpen(boolean bool) { @@ -180,6 +195,14 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { world.spawnEntityInWorld(npc); } + public void inviteToParty(Party party) { + if (party != null && this.partyUUID == null && !this.partyInvites.contains(party.getPartyUUID())) { + this.partyInvites.add(party.getPartyUUID()); + Server.sendData((EntityPlayerMP)this.player, EnumPacketClient.PARTY_MESSAGE, "party.inviteAlert", party.getPartyLeader().getCommandSenderName()); + Server.sendData((EntityPlayerMP)this.player, EnumPacketClient.CHAT, "party.inviteChat", " ", party.getPartyLeader().getCommandSenderName(), "!"); + } + } + public void setCompanion(ICustomNpc npc) { this.setCompanion((EntityNPCInterface) npc.getMCEntity()); } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 319863445..fc2975a0f 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -138,8 +138,14 @@ party.disbandConfirm=Are you sure you want to disband the party? party.friendlyFire=Friendly Fire party.ignore=Ignore party.invite=Invite +party.inviteAlert=Invited to Party +party.inviteChat=You've been invited to a party by party.kick=Kick +party.kickConfirm=Are you sure you want to kick this player? party.leader=Leader +party.leaderConfirm=Are you sure you want to make this player the party leader? +party.leaveParty=Leave Party +party.leaveConfirm=Are you sure you want to leave the party? party.makeLeader=Make Leader party.partyInfo1=You're not in a party! party.partyInfo2=Either wait for an invite From b42ab9425106d518ddf25fbc628626838a902e22 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 22 Jan 2024 19:50:40 +0300 Subject: [PATCH 32/40] 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 b712d5390bfad9fdcdbd05d8cc14facf9ac60ab9 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 22 Jan 2024 10:53:20 -0600 Subject: [PATCH 33/40] Invites are now fully functional, can be accepted and ignored --- .../java/noppes/npcs/PacketHandlerServer.java | 61 ++++++++++++++++--- .../client/gui/player/inventory/GuiParty.java | 47 ++++++++++++-- .../npcs/constants/EnumPacketServer.java | 2 +- .../noppes/npcs/controllers/data/Party.java | 10 ++- .../npcs/controllers/data/PlayerData.java | 22 +++++++ 5 files changed, 124 insertions(+), 18 deletions(-) diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index b8b8fcb6d..038baed6e 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -2,7 +2,6 @@ package noppes.npcs; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; import cpw.mods.fml.relauncher.Side; import foxz.utils.Market; @@ -113,19 +112,12 @@ public class PacketHandlerServer{ PlayerDataController.Instance.getPlayerData(player).animationData.cacheAnimation(buffer.readInt()); return; } else if (type == EnumPacketServer.GetPartyData || type == EnumPacketServer.CreateParty) { - PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); if (type == EnumPacketServer.CreateParty) { Party party = PartyController.Instance().createParty(); party.addPlayer(player); party.setLeader(player); } - - NBTTagCompound compound = new NBTTagCompound(); - if (playerData.partyUUID != null) { - Party party = PartyController.Instance().getParty(playerData.partyUUID); - compound = party.writeToNBT(); - } - Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + sendPartyData(player); } else if (type == EnumPacketServer.DisbandParty) { PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); if (playerData.partyUUID != null) { @@ -142,7 +134,11 @@ public class PacketHandlerServer{ if (playerData.partyUUID != null) { Party party = PartyController.Instance().getParty(playerData.partyUUID); party.removePlayer(kickPlayer); - Server.sendData(player, EnumPacketClient.GUI_DATA, party.writeToNBT()); + if (kickPlayer != player) { + sendPartyData(player); + } else { + sendInviteData((EntityPlayerMP) kickPlayer); + } } } } else if (type == EnumPacketServer.SavePartyData) { @@ -167,6 +163,22 @@ public class PacketHandlerServer{ invitedData.inviteToParty(PartyController.Instance().getParty(senderData.partyUUID)); } } + } else if (type == EnumPacketServer.GetPartyInviteList) { + sendInviteData(player); + } else if (type == EnumPacketServer.AcceptInvite) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + String uuidString = Server.readString(buffer); + if (uuidString != null) { + UUID uuid = UUID.fromString(uuidString); + playerData.acceptInvite(uuid); + } + } else if (type == EnumPacketServer.IgnoreInvite) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + String uuidString = Server.readString(buffer); + if (uuidString != null) { + UUID uuid = UUID.fromString(uuidString); + playerData.ignoreInvite(uuid); + } } if(type.needsNpc && npc == null){ @@ -214,6 +226,35 @@ public class PacketHandlerServer{ } } + public static void sendPartyData(EntityPlayerMP player) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + + if (playerData.partyUUID != null) { + Party party = PartyController.Instance().getParty(playerData.partyUUID); + Server.sendData(player, EnumPacketClient.GUI_DATA, party.writeToNBT()); + } else { + sendInviteData(player); + } + } + + public static void sendInviteData(EntityPlayerMP player) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + if (playerData.partyUUID == null) { + NBTTagCompound compound = new NBTTagCompound(); + NBTTagList list = new NBTTagList(); + HashSet partyInvites = playerData.getPartyInvites(); + for (UUID uuid : partyInvites) { + Party party = PartyController.Instance().getParty(uuid); + NBTTagCompound partyCompound = new NBTTagCompound(); + partyCompound.setString("PartyLeader", party.getPartyLeaderName()); + partyCompound.setString("PartyUUID", party.getPartyUUID().toString()); + list.appendTag(partyCompound); + } + compound.setTag("PartyInvites", list); + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + } + } + private void isGuiOpenPacket(ByteBuf buffer, EntityPlayerMP player) throws IOException { NoppesUtilServer.isGUIOpen(buffer, player); } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index e08e36672..36eaa7a34 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -6,6 +6,7 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import noppes.npcs.client.Client; @@ -20,6 +21,7 @@ import tconstruct.client.tabs.TabRegistry; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.UUID; public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData, GuiYesNoCallback { @@ -29,11 +31,15 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT private boolean receivedData; private long renderTicks; + private String selectedPlayer; + private String selectedInvite; private boolean partyChanged = false; private boolean isLeader; + private final HashMap invites = new HashMap<>(); + public GuiParty(EntityPlayer player) { super(); this.player = player; @@ -46,6 +52,7 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT public void initGui(){ super.initGui(); + this.selectedInvite = this.selectedPlayer = null; Party party = ClientCacheHandler.party; TabRegistry.addTabsToList(buttonList); TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); @@ -69,6 +76,7 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT inviteScroll.setSize(150, 160); inviteScroll.guiLeft = guiLeft + 5; inviteScroll.guiTop = guiTop + 5; + inviteScroll.setList(new ArrayList<>(this.invites.keySet())); this.addScroll(inviteScroll); GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "party.accept"); @@ -133,15 +141,15 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT //disband party // - GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.leaveParty"); + GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.disbandParty"); disbandButton.width = 100; this.addButton(disbandButton); } else { //leave party // - GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.disbandParty"); - disbandButton.width = 100; - this.addButton(disbandButton); + GuiNpcButton leaveButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.leaveParty"); + leaveButton.width = 100; + this.addButton(leaveButton); } } } @@ -179,6 +187,18 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT Client.sendData(EnumPacketServer.CreateParty); receivedData = false; break; + case 215: + if (this.selectedInvite != null) { + Client.sendData(EnumPacketServer.AcceptInvite, this.selectedInvite); + receivedData = false; + } + break; + case 220: + if (this.selectedInvite != null) { + Client.sendData(EnumPacketServer.IgnoreInvite, this.selectedInvite); + receivedData = false; + } + break; case 305: if (!party.getPartyLeaderName().equals(this.selectedPlayer)) { GuiYesNo yesnoLeader = new GuiYesNo(this, StatCollector.translateToLocal("party.leaderConfirm"), this.selectedPlayer, 0); @@ -282,6 +302,16 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT } else if (compound.hasKey("Disband")) { ClientCacheHandler.party = null; this.isLeader = false; + } else if (compound.hasKey("PartyInvites")) { + ClientCacheHandler.party = null; + this.invites.clear(); + NBTTagList list = compound.getTagList("PartyInvites", 10); + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound listCompound = list.getCompoundTagAt(i); + String inviteName = listCompound.getString("PartyLeader"); + String partyUUID = listCompound.getString("PartyUUID"); + this.invites.put(inviteName, partyUUID); + } } initGui(); @@ -302,7 +332,14 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT @Override public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { - this.selectedPlayer = guiCustomScroll.getSelected(); + switch (guiCustomScroll.id) { + case 210: + this.selectedInvite = this.invites.get(guiCustomScroll.getSelected()); + break; + case 300: + this.selectedPlayer = guiCustomScroll.getSelected(); + break; + } } @Override diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index fed898905..656e2e57f 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -95,7 +95,7 @@ public enum EnumPacketServer { CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, - SavePartyData, CreateParty, GetPartyData, DisbandParty, KickPlayer, PartyInvite, SetPartyLeader, + SavePartyData, CreateParty, GetPartyData, DisbandParty, KickPlayer, PartyInvite, GetPartyInviteList, AcceptInvite, IgnoreInvite, SetPartyLeader, ServerUpdateSkinOverlays; diff --git a/src/main/java/noppes/npcs/controllers/data/Party.java b/src/main/java/noppes/npcs/controllers/data/Party.java index cb09b3636..5192ad126 100644 --- a/src/main/java/noppes/npcs/controllers/data/Party.java +++ b/src/main/java/noppes/npcs/controllers/data/Party.java @@ -80,6 +80,9 @@ public class Party { } } + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + playerData.partyUUID = null; + return true; } @@ -106,9 +109,12 @@ public class Party { return NoppesUtilServer.getPlayer(this.partyLeader); } - @SideOnly(Side.CLIENT) public String getPartyLeaderName() { - return this.partyLeaderName; + if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { + return this.partyLeaderName; + } else { + return this.getPartyLeader().getCommandSenderName(); + } } public boolean setLeader(EntityPlayer player){ diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index cec4b7356..35078c5c3 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -8,12 +8,14 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; import noppes.npcs.LogWriter; +import noppes.npcs.PacketHandlerServer; import noppes.npcs.Server; import noppes.npcs.api.entity.ICustomNpc; import noppes.npcs.api.handler.*; import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.controllers.PartyController; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -203,6 +205,26 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { } } + public void ignoreInvite(UUID uuid) { + if (uuid != null) { + this.partyInvites.remove(uuid); + PacketHandlerServer.sendInviteData((EntityPlayerMP) player); + } + } + + public void acceptInvite(UUID uuid) { + if (uuid != null) { + this.partyInvites.remove(uuid); + Party party = PartyController.Instance().getParty(uuid); + party.addPlayer(player); + PacketHandlerServer.sendPartyData((EntityPlayerMP) player); + } + } + + public HashSet getPartyInvites() { + return (HashSet) this.partyInvites.clone(); + } + public void setCompanion(ICustomNpc npc) { this.setCompanion((EntityNPCInterface) npc.getMCEntity()); } From d6875c4ecc53fd6c8eca38db21fb52ede8aaba00 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 22 Jan 2024 20:30:54 +0300 Subject: [PATCH 34/40] 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 35/40] 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 From 3637c9bfda4a44e1ca4b0b28158c92771fdfb46b Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 22 Jan 2024 11:44:25 -0600 Subject: [PATCH 36/40] Fixes to selecting players and invites in the party gui not having intended results --- .../client/gui/player/inventory/GuiParty.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index 36eaa7a34..6cf6aec7e 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -188,27 +188,31 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT receivedData = false; break; case 215: - if (this.selectedInvite != null) { + if (this.selectedInvite != null && !this.selectedInvite.isEmpty()) { Client.sendData(EnumPacketServer.AcceptInvite, this.selectedInvite); receivedData = false; + return; } break; case 220: - if (this.selectedInvite != null) { + if (this.selectedInvite != null && !this.selectedInvite.isEmpty()) { Client.sendData(EnumPacketServer.IgnoreInvite, this.selectedInvite); receivedData = false; + return; } break; case 305: - if (!party.getPartyLeaderName().equals(this.selectedPlayer)) { + if (this.selectedPlayer != null && !this.selectedPlayer.isEmpty() && !party.getPartyLeaderName().equals(this.selectedPlayer)) { GuiYesNo yesnoLeader = new GuiYesNo(this, StatCollector.translateToLocal("party.leaderConfirm"), this.selectedPlayer, 0); displayGuiScreen(yesnoLeader); + return; } break; case 310: - if (!party.getPartyLeaderName().equals(this.selectedPlayer)) { + if (this.selectedPlayer != null && !this.selectedPlayer.isEmpty() && !party.getPartyLeaderName().equals(this.selectedPlayer)) { GuiYesNo yesnoKick = new GuiYesNo(this, StatCollector.translateToLocal("party.kickConfirm"), this.selectedPlayer, 1); displayGuiScreen(yesnoKick); + return; } break; case 320: @@ -289,21 +293,17 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT @Override public void setGuiData(NBTTagCompound compound) { this.receivedData = true; + ClientCacheHandler.party = null; if (compound.hasKey("PartyUUID")) { - Party party = ClientCacheHandler.party; UUID uuid = UUID.fromString(compound.getString("PartyUUID")); - if (party == null || !party.getPartyUUID().equals(uuid)) { - ClientCacheHandler.party = new Party(uuid); - party = ClientCacheHandler.party; - } + ClientCacheHandler.party = new Party(uuid); + Party party = ClientCacheHandler.party; party.readFromNBT(compound); this.isLeader = ClientCacheHandler.party.getPartyLeaderName().equals(this.player.getCommandSenderName()); } else if (compound.hasKey("Disband")) { - ClientCacheHandler.party = null; this.isLeader = false; } else if (compound.hasKey("PartyInvites")) { - ClientCacheHandler.party = null; this.invites.clear(); NBTTagList list = compound.getTagList("PartyInvites", 10); for (int i = 0; i < list.tagCount(); i++) { @@ -337,7 +337,7 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT this.selectedInvite = this.invites.get(guiCustomScroll.getSelected()); break; case 300: - this.selectedPlayer = guiCustomScroll.getSelected(); + this.selectedPlayer = guiCustomScroll.getSelected().replace(" §e[" + StatCollector.translateToLocal("party.leader").toUpperCase() + "]", ""); break; } } From cea054560fb8744773927a9655dee29a58924696 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 22 Jan 2024 12:04:09 -0600 Subject: [PATCH 37/40] Implemented friendly fire. --- src/main/java/noppes/npcs/ServerEventsHandler.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index c1bd4399e..46ff76c54 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -21,6 +21,7 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.StatCollector; import net.minecraft.village.MerchantRecipeList; import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.EntityInteractEvent; @@ -135,7 +136,20 @@ public class ServerEventsHandler { } } } + } + @SubscribeEvent + public void invoke(LivingAttackEvent event) { + if(!(event.source != null && event.source.getEntity() instanceof EntityPlayer) || !(event.entityLiving instanceof EntityPlayer) || FMLCommonHandler.instance().getEffectiveSide().isClient()) + return; + + EntityPlayer sourcePlayer = (EntityPlayer) event.source.getEntity(); + + PlayerData playerData = PlayerDataController.Instance.getPlayerData(sourcePlayer); + PlayerData targetData = PlayerDataController.Instance.getPlayerData((EntityPlayer) event.entityLiving); + if (playerData.partyUUID != null && playerData.partyUUID.equals(targetData.partyUUID)) { + event.setCanceled(true); + } } @SubscribeEvent From 803042397e72129bbafd599140b3f6f35ee2060e Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 22 Jan 2024 13:43:15 -0500 Subject: [PATCH 38/40] Update api --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index e3980ce21..28e74054b 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit e3980ce21720e963bb3d3169931885eb0bc60caa +Subproject commit 28e74054b7bcea56e7fcb63ba2ee6330407b40e3 From 21d0a4163684a7c3b1f2837a65bbe09f9318d33c Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 22 Jan 2024 13:45:17 -0500 Subject: [PATCH 39/40] 1.9 Beta 4 --- build.gradle | 2 +- src/main/java/noppes/npcs/CustomNpcs.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index a1879f7de..c8813fb74 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ configurations { apply plugin: 'forge' -version = "1.9-beta3.2" +version = "1.9-beta4" group= "com.kamkeel.customnpc-plus" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "CustomNPC-Plus" diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 17bb45199..d78f46e16 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -35,7 +35,7 @@ import noppes.npcs.scripted.NpcAPI; import java.io.File; import java.util.Set; -@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.9-beta3") +@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.9-beta4") public class CustomNpcs { @SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy") From 651c8db5761d9622507f8306b1af6daab7361512 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 22 Jan 2024 13:49:47 -0500 Subject: [PATCH 40/40] Fix GlStateManager to GL11 --- .../blocks/BlockScriptedRenderer.java | 117 ++++++++---------- 1 file changed, 55 insertions(+), 62 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 75f1f825c..96aa40e7e 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java @@ -1,7 +1,5 @@ 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; @@ -9,12 +7,8 @@ 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; @@ -37,97 +31,96 @@ public class BlockScriptedRenderer extends BlockRendererInterface{ @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks) { TileScripted tile = (TileScripted) te; - GlStateManager.pushMatrix(); - GlStateManager.disableBlend(); + GL11.glPushMatrix(); + GL11.glDisable(GL11.GL_BLEND); RenderHelper.enableStandardItemLighting(); - GlStateManager.translate(x + 0.5, y, z + 0.5); - if(overrideModel()){ - GlStateManager.translate(0, 0.5, 0); + GL11.glTranslatef((float) (x + 0.5), (float) y, (float) (z + 0.5)); + if (overrideModel()) { + GL11.glTranslatef(0, 0.5F, 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); + } else { + GL11.glRotatef(tile.rotationY, 0, 1, 0); + GL11.glRotatef(tile.rotationX, 1, 0, 0); + GL11.glRotatef(tile.rotationZ, 0, 0, 1); + GL11.glScalef(tile.scaleX, tile.scaleY, tile.scaleZ); + GL11.glTranslatef(0, 0.5F, 0); renderItem(te, tile.itemModel); } - GlStateManager.popMatrix(); + GL11.glPopMatrix(); - if(!tile.text1.text.isEmpty()) { + if (!tile.text1.text.isEmpty()) { drawText(tile.text1, x, y, z); } - if(!tile.text2.text.isEmpty()) { + if (!tile.text2.text.isEmpty()) { drawText(tile.text2, x, y, z); } - if(!tile.text3.text.isEmpty()) { + if (!tile.text3.text.isEmpty()) { drawText(tile.text3, x, y, z); } - if(!tile.text4.text.isEmpty()) { + if (!tile.text4.text.isEmpty()) { drawText(tile.text4, x, y, z); } - if(!tile.text5.text.isEmpty()) { + if (!tile.text5.text.isEmpty()) { drawText(tile.text5, x, y, z); } - if(!tile.text6.text.isEmpty()) { + 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){ + 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); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glColor3f(1, 1, 1); + GL11.glPushMatrix(); + GL11.glTranslatef((float) (x + 0.5), (float) (y + 0.5), (float) (z + 0.5)); + GL11.glRotatef(text1.rotationY, 0, 1, 0); + GL11.glRotatef(text1.rotationX, 1, 0, 0); + GL11.glRotatef(text1.rotationZ, 0, 0, 1); + GL11.glScalef(text1.scale, text1.scale, 1); + GL11.glTranslatef(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); + GL11.glTranslatef(0.0F, 0.5F, 0.01F); + GL11.glScalef(f3, -f3, f3); + GL11.glNormal3f(0.0F, 0.0F, -1.0F * f3); + GL11.glDepthMask(false); FontRenderer fontrenderer = Minecraft.getMinecraft().fontRenderer; float lineOffset = 0; - if(text1.textBlock.lines.size() < 14) + if (text1.textBlock.lines.size() < 14) lineOffset = (14f - text1.textBlock.lines.size()) / 2; - for(int i = 0; i < text1.textBlock.lines.size(); i++){ + 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); + 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(); + GL11.glDepthMask(true); + GL11.glColor3f(1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); } - private void renderItem(TileEntity tile, ItemStack stack){ + private void renderItem(TileEntity tile, ItemStack stack) { Minecraft mc = Minecraft.getMinecraft(); - if(stack != null) { + 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)) { + 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()) + 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) { + 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(); @@ -145,23 +138,23 @@ public class BlockScriptedRenderer extends BlockRendererInterface{ } } - private void renderBlock(TileScripted tile, Block b){ - GlStateManager.pushMatrix(); + private void renderBlock(TileScripted tile, Block b) { + GL11.glPushMatrix(); 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); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glTranslatef(-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(); + if (b.getTickRandomly() && random.nextInt(12) == 1) + b.randomDisplayTick(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, random); + GL11.glPopMatrix(); } - private boolean overrideModel(){ + private boolean overrideModel() { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - if(held == null) + if (held == null) return false; return held.getItem() == CustomItems.wand || held.getItem() == CustomItems.scripter;