-
Notifications
You must be signed in to change notification settings - Fork 497
/
CoreProxy.java
140 lines (113 loc) · 4.01 KB
/
CoreProxy.java
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
* <p/>
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.proxy;
import java.lang.ref.WeakReference;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.SidedProxy;
import net.minecraftforge.common.util.FakePlayerFactory;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.ICoreProxy;
import buildcraft.core.LaserKind;
import buildcraft.core.lib.EntityBlock;
public class CoreProxy implements ICoreProxy {
@SidedProxy(clientSide = "buildcraft.core.proxy.CoreProxyClient", serverSide = "buildcraft.core.proxy.CoreProxy")
public static CoreProxy proxy;
/* BUILDCRAFT PLAYER */
protected static WeakReference<EntityPlayer> buildCraftPlayer = new WeakReference<EntityPlayer>(null);
public String getMinecraftVersion() {
return Loader.instance().getMinecraftModContainer().getVersion();
}
/* INSTANCES */
public Object getClient() {
return null;
}
public World getClientWorld() {
return null;
}
/* ENTITY HANDLING */
public void removeEntity(Entity entity) {
entity.worldObj.removeEntity(entity);
}
public String getItemDisplayName(ItemStack newStack) {
return "";
}
/* GFX */
public void initializeRendering() {
}
public void initializeEntityRendering() {
}
public void onCraftingPickup(World world, EntityPlayer player, ItemStack stack) {
stack.onCrafting(world, player, stack.stackSize);
}
public String playerName() {
return "";
}
private WeakReference<EntityPlayer> createNewPlayer(WorldServer world) {
EntityPlayer player = FakePlayerFactory.get(world, BuildCraftCore.gameProfile);
return new WeakReference<EntityPlayer>(player);
}
private WeakReference<EntityPlayer> createNewPlayer(WorldServer world, int x, int y, int z) {
EntityPlayer player = FakePlayerFactory.get(world, BuildCraftCore.gameProfile);
player.posX = x;
player.posY = y;
player.posZ = z;
return new WeakReference<EntityPlayer>(player);
}
@Override
public final WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world) {
if (CoreProxy.buildCraftPlayer.get() == null) {
CoreProxy.buildCraftPlayer = createNewPlayer(world);
} else {
CoreProxy.buildCraftPlayer.get().worldObj = world;
}
return CoreProxy.buildCraftPlayer;
}
public final WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world, int x, int y, int z) {
if (CoreProxy.buildCraftPlayer.get() == null) {
CoreProxy.buildCraftPlayer = createNewPlayer(world, x, y, z);
} else {
CoreProxy.buildCraftPlayer.get().worldObj = world;
CoreProxy.buildCraftPlayer.get().posX = x;
CoreProxy.buildCraftPlayer.get().posY = y;
CoreProxy.buildCraftPlayer.get().posZ = z;
}
return CoreProxy.buildCraftPlayer;
}
public EntityBlock newEntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize, LaserKind laserKind) {
return new EntityBlock(world, i, j, k, iSize, jSize, kSize);
}
/**
* This function returns either the player from the handler if it's on the
* server, or directly from the minecraft instance if it's the client.
*/
public EntityPlayer getPlayerFromNetHandler(INetHandler handler) {
if (handler instanceof NetHandlerPlayServer) {
return ((NetHandlerPlayServer) handler).playerEntity;
} else {
return null;
}
}
public TileEntity getServerTile(TileEntity source) {
return source;
}
public EntityPlayer getClientPlayer() {
return null;
}
}