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