-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacketHandler.java
More file actions
126 lines (104 loc) · 3.65 KB
/
Copy pathPacketHandler.java
File metadata and controls
126 lines (104 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package treebreaker;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import net.minecraft.block.Block;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
public class PacketHandler implements IPacketHandler {
@Override
public void onPacketData(INetworkManager manager,
Packet250CustomPayload packet, Player player) {
if(packet.channel != Config.channel) {
return;
}
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(packet.data));
try {
String command = stream.readUTF();
if(command.equalsIgnoreCase(EnumCommand.BREAK.toString())) {
int x = stream.readInt();
int y = stream.readInt();
int z = stream.readInt();
breakBlock(player, x, y, z);
}
if(command.equalsIgnoreCase(EnumCommand.TARGET.toString())) {
int size = stream.readInt();
TreeBreaker.config.logs.clear();
for(int i = 0; i < size; ++i) {
int blockId = stream.readInt();
int metadata = stream.readInt();
TreeBreaker.config.logs.add(blockId);
}
size = stream.readInt();
TreeBreaker.config.leaves.clear();
for(int i = 0; i < size; ++i) {
int blockId = stream.readInt();
int metadata = stream.readInt();
TreeBreaker.config.leaves.add(blockId);
}
printTarget(player);
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
private void printTarget(Player player) {
if(player instanceof EntityClientPlayerMP) {
EntityClientPlayerMP thePlayer = (EntityClientPlayerMP) player;
String target = "";
for(int blockId : TreeBreaker.config.logs) {
if(target.isEmpty() == false) {
target += ", ";
}
target += Block.blocksList[blockId].getLocalizedName();
}
for(int blockId : TreeBreaker.config.leaves) {
if(target.isEmpty() == false) {
target += ", ";
}
target += Block.blocksList[blockId].getLocalizedName();
}
thePlayer.addChatMessage("TreeBreaker Target = " + target);
}
}
private void breakBlock(Player player, int x, int y, int z) {
EntityPlayerMP thePlayer = (EntityPlayerMP) player;
World theWorld = thePlayer.worldObj;
int blockId = theWorld.getBlockId(x, y, z);
if(blockId == 0) return;
Block block = Block.blocksList[blockId];
if(block == null) return;
int metadata = theWorld.getBlockMetadata(x, y, z);
ItemStack itemStack = thePlayer.getCurrentEquippedItem();
if(itemStack == null) return;
int currentItem = thePlayer.inventory.currentItem;
block.onBlockDestroyedByPlayer(theWorld, x, y, z, blockId);
theWorld.playAuxSFX(2001, x, y, z, block.blockID + (theWorld.getBlockMetadata(x, y, z) << 12));
boolean flag = theWorld.setBlockAndMetadataWithNotify(x, y, z, 0, 0, 3);
if (block != null && flag) {
block.removeBlockByPlayer(theWorld, thePlayer, x, y, z);
}
itemStack.onBlockDestroyed(theWorld, blockId, x, y, z, thePlayer);
if (itemStack.stackSize == 0) {
// itemstack.onItemDestroyedByUse(minecraft.thePlayer);
thePlayer.destroyCurrentEquippedItem();
//ret = false;
}
boolean flag1 = thePlayer.canHarvestBlock(block);
if (flag1) {
if(TreeBreaker.config.drop_to_player) {
block.harvestBlock(theWorld, thePlayer, (int)thePlayer.posX, (int)thePlayer.posY, (int)thePlayer.posZ, metadata);
}
else {
block.harvestBlock(theWorld, thePlayer, x, y, z, metadata);
}
}
}
}