    001    package net.minecraft.src;
    002
    003    public class DemoWorldManager extends ItemInWorldManager
    004    {
    005        private boolean field_73105_c = false;
    006        private boolean demoTimeExpired = false;
    007        private int field_73104_e = 0;
    008        private int field_73102_f = 0;
    009
    010        public DemoWorldManager(World par1World)
    011        {
    012            super(par1World);
    013        }
    014
    015        public void updateBlockRemoving()
    016        {
    017            super.updateBlockRemoving();
    018            ++this.field_73102_f;
    019            long var1 = this.theWorld.func_82737_E();
    020            long var3 = var1 / 24000L + 1L;
    021
    022            if (!this.field_73105_c && this.field_73102_f > 20)
    023            {
    024                this.field_73105_c = true;
    025                this.thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(5, 0));
    026            }
    027
    028            this.demoTimeExpired = var1 > 120500L;
    029
    030            if (this.demoTimeExpired)
    031            {
    032                ++this.field_73104_e;
    033            }
    034
    035            if (var1 % 24000L == 500L)
    036            {
    037                if (var3 <= 6L)
    038                {
    039                    this.thisPlayerMP.sendChatToPlayer(this.thisPlayerMP.translateString("demo.day." + var3, new Object[0]));
    040                }
    041            }
    042            else if (var3 == 1L)
    043            {
    044                if (var1 == 100L)
    045                {
    046                    this.thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(5, 101));
    047                }
    048                else if (var1 == 175L)
    049                {
    050                    this.thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(5, 102));
    051                }
    052                else if (var1 == 250L)
    053                {
    054                    this.thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(5, 103));
    055                }
    056            }
    057            else if (var3 == 5L && var1 % 24000L == 22000L)
    058            {
    059                this.thisPlayerMP.sendChatToPlayer(this.thisPlayerMP.translateString("demo.day.warning", new Object[0]));
    060            }
    061        }
    062
    063        /**
    064         * Sends a message to the player reminding them that this is the demo version
    065         */
    066        private void sendDemoReminder()
    067        {
    068            if (this.field_73104_e > 100)
    069            {
    070                this.thisPlayerMP.sendChatToPlayer(this.thisPlayerMP.translateString("demo.reminder", new Object[0]));
    071                this.field_73104_e = 0;
    072            }
    073        }
    074
    075        /**
    076         * if not creative, it calls destroyBlockInWorldPartially untill the block is broken first. par4 is the specific
    077         * side. tryHarvestBlock can also be the result of this call
    078         */
    079        public void onBlockClicked(int par1, int par2, int par3, int par4)
    080        {
    081            if (this.demoTimeExpired)
    082            {
    083                this.sendDemoReminder();
    084            }
    085            else
    086            {
    087                super.onBlockClicked(par1, par2, par3, par4);
    088            }
    089        }
    090
    091        public void uncheckedTryHarvestBlock(int par1, int par2, int par3)
    092        {
    093            if (!this.demoTimeExpired)
    094            {
    095                super.uncheckedTryHarvestBlock(par1, par2, par3);
    096            }
    097        }
    098
    099        /**
    100         * Attempts to harvest a block at the given coordinate
    101         */
    102        public boolean tryHarvestBlock(int par1, int par2, int par3)
    103        {
    104            return this.demoTimeExpired ? false : super.tryHarvestBlock(par1, par2, par3);
    105        }
    106
    107        /**
    108         * Attempts to right-click use an item by the given EntityPlayer in the given World
    109         */
    110        public boolean tryUseItem(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack)
    111        {
    112            if (this.demoTimeExpired)
    113            {
    114                this.sendDemoReminder();
    115                return false;
    116            }
    117            else
    118            {
    119                return super.tryUseItem(par1EntityPlayer, par2World, par3ItemStack);
    120            }
    121        }
    122
    123        /**
    124         * Activate the clicked on block, otherwise use the held item. Args: player, world, itemStack, x, y, z, side,
    125         * xOffset, yOffset, zOffset
    126         */
    127        public boolean activateBlockOrUseItem(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    128        {
    129            if (this.demoTimeExpired)
    130            {
    131                this.sendDemoReminder();
    132                return false;
    133            }
    134            else
    135            {
    136                return super.activateBlockOrUseItem(par1EntityPlayer, par2World, par3ItemStack, par4, par5, par6, par7, par8, par9, par10);
    137            }
    138        }
    139    }