| 1 | package net.minecraft.world.demo;
|
| 2 |
|
| 3 | import net.minecraft.entity.player.EntityPlayer;
|
| 4 | import net.minecraft.item.ItemStack;
|
| 5 | import net.minecraft.network.play.server.S2BPacketChangeGameState;
|
| 6 | import net.minecraft.server.management.ItemInWorldManager;
|
| 7 | import net.minecraft.util.BlockPos;
|
| 8 | import net.minecraft.util.ChatComponentTranslation;
|
| 9 | import net.minecraft.util.EnumFacing;
|
| 10 | import net.minecraft.world.World;
|
| 11 |
|
| 12 | public class DemoWorldManager extends ItemInWorldManager
|
| 13 | {
|
| 14 | private boolean field_73105_c;
|
| 15 | private boolean demoTimeExpired;
|
| 16 | private int field_73104_e;
|
| 17 | private int field_73102_f;
|
| 18 |
|
| 19 | public DemoWorldManager(World worldIn)
|
| 20 | {
|
| 21 | super(worldIn);
|
| 22 | }
|
| 23 |
|
| 24 | public void updateBlockRemoving()
|
| 25 | {
|
| 26 | super.updateBlockRemoving();
|
| 27 | ++this.field_73102_f;
|
| 28 | long i = this.theWorld.getTotalWorldTime();
|
| 29 | long j = i / 24000L + 1L;
|
| 30 |
|
| 31 | if (!this.field_73105_c && this.field_73102_f > 20)
|
| 32 | {
|
| 33 | this.field_73105_c = true;
|
| 34 | this.thisPlayerMP.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(5, 0.0F));
|
| 35 | }
|
| 36 |
|
| 37 | this.demoTimeExpired = i > 120500L;
|
| 38 |
|
| 39 | if (this.demoTimeExpired)
|
| 40 | {
|
| 41 | ++this.field_73104_e;
|
| 42 | }
|
| 43 |
|
| 44 | if (i % 24000L == 500L)
|
| 45 | {
|
| 46 | if (j <= 6L)
|
| 47 | {
|
| 48 | this.thisPlayerMP.addChatMessage(new ChatComponentTranslation("demo.day." + j, new Object[0]));
|
| 49 | }
|
| 50 | }
|
| 51 | else if (j == 1L)
|
| 52 | {
|
| 53 | if (i == 100L)
|
| 54 | {
|
| 55 | this.thisPlayerMP.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(5, 101.0F));
|
| 56 | }
|
| 57 | else if (i == 175L)
|
| 58 | {
|
| 59 | this.thisPlayerMP.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(5, 102.0F));
|
| 60 | }
|
| 61 | else if (i == 250L)
|
| 62 | {
|
| 63 | this.thisPlayerMP.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(5, 103.0F));
|
| 64 | }
|
| 65 | }
|
| 66 | else if (j == 5L && i % 24000L == 22000L)
|
| 67 | {
|
| 68 | this.thisPlayerMP.addChatMessage(new ChatComponentTranslation("demo.day.warning", new Object[0]));
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | /**
|
| 73 | * Sends a message to the player reminding them that this is the demo version
|
| 74 | */
|
| 75 | private void sendDemoReminder()
|
| 76 | {
|
| 77 | if (this.field_73104_e > 100)
|
| 78 | {
|
| 79 | this.thisPlayerMP.addChatMessage(new ChatComponentTranslation("demo.reminder", new Object[0]));
|
| 80 | this.field_73104_e = 0;
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | /**
|
| 85 | * If not creative, it calls sendBlockBreakProgress until the block is broken first. tryHarvestBlock can also be the
|
| 86 | * result of this call.
|
| 87 | */
|
| 88 | public void onBlockClicked(BlockPos pos, EnumFacing side)
|
| 89 | {
|
| 90 | if (this.demoTimeExpired)
|
| 91 | {
|
| 92 | this.sendDemoReminder();
|
| 93 | }
|
| 94 | else
|
| 95 | {
|
| 96 | super.onBlockClicked(pos, side);
|
| 97 | }
|
| 98 | }
|
| 99 |
|
| 100 | public void blockRemoving(BlockPos pos)
|
| 101 | {
|
| 102 | if (!this.demoTimeExpired)
|
| 103 | {
|
| 104 | super.blockRemoving(pos);
|
| 105 | }
|
| 106 | }
|
| 107 |
|
| 108 | /**
|
| 109 | * Attempts to harvest a block
|
| 110 | */
|
| 111 | public boolean tryHarvestBlock(BlockPos pos)
|
| 112 | {
|
| 113 | return this.demoTimeExpired ? false : super.tryHarvestBlock(pos);
|
| 114 | }
|
| 115 |
|
| 116 | /**
|
| 117 | * Attempts to right-click use an item by the given EntityPlayer in the given World
|
| 118 | */
|
| 119 | public boolean tryUseItem(EntityPlayer player, World worldIn, ItemStack stack)
|
| 120 | {
|
| 121 | if (this.demoTimeExpired)
|
| 122 | {
|
| 123 | this.sendDemoReminder();
|
| 124 | return false;
|
| 125 | }
|
| 126 | else
|
| 127 | {
|
| 128 | return super.tryUseItem(player, worldIn, stack);
|
| 129 | }
|
| 130 | }
|
| 131 |
|
| 132 | /**
|
| 133 | * Activate the clicked on block, otherwise use the held item.
|
| 134 | */
|
| 135 | public boolean activateBlockOrUseItem(EntityPlayer player, World worldIn, ItemStack stack, BlockPos pos, EnumFacing side, float offsetX, float offsetY, float offsetZ)
|
| 136 | {
|
| 137 | if (this.demoTimeExpired)
|
| 138 | {
|
| 139 | this.sendDemoReminder();
|
| 140 | return false;
|
| 141 | }
|
| 142 | else
|
| 143 | {
|
| 144 | return super.activateBlockOrUseItem(player, worldIn, stack, pos, side, offsetX, offsetY, offsetZ);
|
| 145 | }
|
| 146 | }
|
| 147 | }
|
| 148 |
|