mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-24 05:54:27 +00:00
Revamp how the Ender IO works, should now work with most blocks
#2297 #1900
This commit is contained in:
1 parent
7b2943671b
commit
dfff76c0d7
8 files changed
+204
-413
No files matched your search
@@ -18,6 +18,7 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -112,7 +113,9 @@ public class ConduitBundleRenderer extends TileEntitySpecialRenderer implements
|
||||
//enable the alpha pass based on state so the only work around is to ensure we always render something in this
|
||||
//pass. Throwing in a polygon with a 0 area does the job
|
||||
//See: https://github.com/MinecraftForge/MinecraftForge/issues/981
|
||||
if(ForgeHooksClient.getWorldRenderPass() == 1) {
|
||||
int pass = MinecraftForgeClient.getRenderPass();
|
||||
pass = pass >= 0 ? pass : ForgeHooksClient.getWorldRenderPass();
|
||||
if(pass == 1) {
|
||||
Tessellator.instance.addVertexWithUV(x, y, z, 0, 0);
|
||||
Tessellator.instance.addVertexWithUV(x, y, z, 0, 0);
|
||||
Tessellator.instance.addVertexWithUV(x, y, z, 0, 0);
|
||||
@@ -122,10 +125,10 @@ public class ConduitBundleRenderer extends TileEntitySpecialRenderer implements
|
||||
IConduitBundle bundle = (IConduitBundle) world.getTileEntity(x, y, z);
|
||||
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
|
||||
|
||||
boolean renderedFacade = renderFacade(x, y, z, rb, bundle, player);
|
||||
boolean renderedFacade = renderFacade(x, y, z, pass, rb, bundle, player);
|
||||
boolean renderConduit = !renderedFacade || ConduitUtil.isFacadeHidden(bundle, player);
|
||||
|
||||
if(renderConduit && (ForgeHooksClient.getWorldRenderPass() == 0 || rb.overrideBlockTexture != null)) {
|
||||
if(renderConduit && (pass == 0 || rb.overrideBlockTexture != null)) {
|
||||
BlockCoord loc = bundle.getLocation();
|
||||
float brightness;
|
||||
if(!Config.updateLightingWhenHidingFacades && bundle.hasFacade() && ConduitUtil.isFacadeHidden(bundle, player)) {
|
||||
@@ -140,7 +143,7 @@ public class ConduitBundleRenderer extends TileEntitySpecialRenderer implements
|
||||
return renderedFacade || (bundle.hasFacade() && !bundle.getFacadeId().isOpaqueCube());
|
||||
}
|
||||
|
||||
private boolean renderFacade(int x, int y, int z, RenderBlocks rb, IConduitBundle bundle, EntityClientPlayerMP player) {
|
||||
private boolean renderFacade(int x, int y, int z, int pass, RenderBlocks rb, IConduitBundle bundle, EntityClientPlayerMP player) {
|
||||
boolean res = false;
|
||||
if(bundle.hasFacade()) {
|
||||
res = true;
|
||||
@@ -159,12 +162,11 @@ public class ConduitBundleRenderer extends TileEntitySpecialRenderer implements
|
||||
}
|
||||
facb.setBlockOverride(null);
|
||||
bundle.setFacadeId(facadeId, false);
|
||||
} else if(facadeId != null) {
|
||||
} else if (facadeId != null) {
|
||||
bundle.setFacadeRenderAs(FacadeRenderState.FULL);
|
||||
boolean isFacadeOpaque = facadeId.isOpaqueCube();
|
||||
|
||||
if((isFacadeOpaque && ForgeHooksClient.getWorldRenderPass() == 0) ||
|
||||
(rb.hasOverrideBlockTexture() || (!isFacadeOpaque && ForgeHooksClient.getWorldRenderPass() == 1))) {
|
||||
if ((isFacadeOpaque && pass == 0) || (rb.hasOverrideBlockTexture() || (!isFacadeOpaque && pass == 1))) {
|
||||
IBlockAccess origBa = rb.blockAccess;
|
||||
rb.blockAccess = new FacadeAccessWrapper(origBa);
|
||||
try {
|
||||
|
||||
@@ -11,16 +11,13 @@ import net.minecraft.world.World;
|
||||
|
||||
import com.enderio.core.api.client.gui.IResourceTooltipProvider;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.BlockEio;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.Log;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.api.teleport.ITravelAccessable;
|
||||
import crazypants.enderio.enderface.te.MeProxy;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.teleport.anchor.BlockTravelAnchor;
|
||||
|
||||
@@ -28,34 +25,19 @@ public class BlockEnderIO extends BlockEio implements IResourceTooltipProvider {
|
||||
|
||||
public static BlockEnderIO create() {
|
||||
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_ME_ACCESS_TERMINAL, new IGuiHandler() {
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
try {
|
||||
return MeProxy.createMeTerminalContainer(player, x, y, z, false);
|
||||
} catch (Exception e) {
|
||||
Log.warn("BlockEnderIO: Error occured creating the server gui element for an ME Terminal " + e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return MeProxy.instance.createTerminalGui(player, x, y, z);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PacketHandler.INSTANCE.registerMessage(PacketOpenRemoteUi.class, PacketOpenRemoteUi.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketOpenServerGUI.class, PacketOpenServerGUI.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketLockClientContainer.Handler.class, PacketLockClientContainer.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
|
||||
BlockEnderIO result = new BlockEnderIO();
|
||||
result.init();
|
||||
return result;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon frameIcon;
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon selectedOverlayIcon;
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon highlightOverlayIcon;
|
||||
|
||||
static int pass;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package crazypants.enderio.enderface;
|
||||
|
||||
import gnu.trove.map.TObjectIntMap;
|
||||
import gnu.trove.map.hash.TObjectIntHashMap;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ContainerPlayer;
|
||||
import net.minecraftforge.event.entity.player.PlayerOpenContainerEvent;
|
||||
|
||||
import com.enderio.core.common.Handlers.Handler;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event.Result;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
||||
|
||||
@Handler
|
||||
public enum EnderIOController {
|
||||
INSTANCE;
|
||||
|
||||
private TObjectIntMap<UUID> openedContainers = new TObjectIntHashMap<UUID>();
|
||||
private int clientWindowId;
|
||||
private boolean locked = false;
|
||||
|
||||
public void addContainer(EntityPlayerMP player, Container opened) {
|
||||
openedContainers.put(player.getGameProfile().getId(), opened.windowId);
|
||||
}
|
||||
|
||||
void lockAndWaitForChange(int windowId) {
|
||||
clientWindowId = windowId;
|
||||
locked = true;
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
locked = false;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onContainerTick(PlayerOpenContainerEvent event) {
|
||||
Container c = event.entityPlayer.openContainer;
|
||||
if (c != null && !(c instanceof ContainerPlayer) && (c.windowId == clientWindowId || openedContainers.containsValue(c.windowId))) {
|
||||
event.setResult(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(PlayerTickEvent event) {
|
||||
if (event.phase == Phase.END) {
|
||||
if (event.side.isServer()) {
|
||||
int windowId = openedContainers.get(event.player.getGameProfile().getId());
|
||||
if (event.player.openContainer == null || event.player.openContainer.windowId != windowId) {
|
||||
openedContainers.remove(event.player.getGameProfile().getId());
|
||||
}
|
||||
} else {
|
||||
int windowId = event.player.openContainer.windowId;
|
||||
if (windowId != clientWindowId && locked) {
|
||||
clientWindowId = windowId;
|
||||
locked = false;
|
||||
System.out.println("Unlocked and set windowId to " + clientWindowId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import com.enderio.core.common.vecmath.VecmathUtil;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.conduit.BlockConduitBundle;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.teleport.TravelController;
|
||||
@@ -204,24 +205,15 @@ public class GuiEnderface extends GuiScreen {
|
||||
private void doSelection(Vector3d start, Vector3d end) {
|
||||
start.add(origin);
|
||||
end.add(origin);
|
||||
List<MovingObjectPosition> hits = new ArrayList<MovingObjectPosition>();
|
||||
for (ViewableBlocks ug : blocks) {
|
||||
if(!ug.bc.equals(new BlockCoord(ioX, ioY, ioZ))) {
|
||||
MovingObjectPosition res = player.worldObj.rayTraceBlocks(Vec3.createVectorHelper(start.x, start.y, start.z),
|
||||
Vec3.createVectorHelper(end.x, end.y, end.z), false);
|
||||
MovingObjectPosition hit = player.worldObj.rayTraceBlocks(Vec3.createVectorHelper(start.x, start.y, start.z), Vec3.createVectorHelper(end.x, end.y, end.z),
|
||||
false);
|
||||
|
||||
if(res != null) {
|
||||
hits.add(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
MovingObjectPosition hit = getClosestHit(Vec3.createVectorHelper(start.x, start.y, start.z), hits);
|
||||
if(hit != null) {
|
||||
if (hit != null) {
|
||||
Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
|
||||
if(block == EnderIO.blockHyperCube || block == EnderIO.blockCapacitorBank) {
|
||||
if (block == EnderIO.blockHyperCube || block == EnderIO.blockCapacitorBank) {
|
||||
block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, 0, 0, 0, 0);
|
||||
} else {
|
||||
openInterface(hit.blockX, hit.blockY, hit.blockZ);
|
||||
openInterface(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, hit.hitVec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,6 +263,7 @@ public class GuiEnderface extends GuiScreen {
|
||||
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
mc.entityRenderer.enableLightmap(0);
|
||||
@@ -555,8 +548,9 @@ public class GuiEnderface extends GuiScreen {
|
||||
|
||||
}
|
||||
|
||||
void openInterface(int x, int y, int z) {
|
||||
PacketOpenRemoteUi p = new PacketOpenRemoteUi(x, y, z);
|
||||
void openInterface(int x, int y, int z, int side, Vec3 hitVec) {
|
||||
Vec3 relativeHit = Vec3.createVectorHelper(hitVec.xCoord - x, hitVec.yCoord - y, hitVec.zCoord - z);
|
||||
PacketOpenServerGUI p = new PacketOpenServerGUI(x, y, z, side, relativeHit);
|
||||
PacketHandler.INSTANCE.sendToServer(p);
|
||||
}
|
||||
|
||||
@@ -571,5 +565,4 @@ public class GuiEnderface extends GuiScreen {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package crazypants.enderio.enderface;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class PacketLockClientContainer implements IMessage {
|
||||
|
||||
private int windowId;
|
||||
private boolean lock = true;
|
||||
|
||||
public PacketLockClientContainer() {
|
||||
this.lock = false;
|
||||
}
|
||||
|
||||
public PacketLockClientContainer(int windowId) {
|
||||
this.windowId = windowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.windowId = buf.readInt();
|
||||
this.lock = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(windowId);
|
||||
buf.writeBoolean(lock);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PacketLockClientContainer, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketLockClientContainer message, MessageContext ctx) {
|
||||
if (message.lock) {
|
||||
EnderIOController.INSTANCE.lockAndWaitForChange(message.windowId);
|
||||
} else {
|
||||
EnderIOController.INSTANCE.unlock();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
package crazypants.enderio.enderface;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.ContainerBeacon;
|
||||
import net.minecraft.inventory.ContainerRepair;
|
||||
import net.minecraft.network.play.server.S2DPacketOpenWindow;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.ItemInWorldManager;
|
||||
import net.minecraft.tileentity.TileEntityBeacon;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class PacketOpenRemoteUi implements IMessage, IMessageHandler<PacketOpenRemoteUi, IMessage> {
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
public PacketOpenRemoteUi() {
|
||||
}
|
||||
|
||||
public PacketOpenRemoteUi(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buffer) {
|
||||
buffer.writeInt(x);
|
||||
buffer.writeInt(y);
|
||||
buffer.writeInt(z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buffer) {
|
||||
x = buffer.readInt();
|
||||
y = buffer.readInt();
|
||||
z = buffer.readInt();
|
||||
|
||||
}
|
||||
|
||||
public IMessage onMessage(PacketOpenRemoteUi message, MessageContext ctx) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) ctx.getServerHandler().playerEntity;
|
||||
net.minecraft.inventory.Container c = player.openContainer;
|
||||
PlayerProxy pp = new PlayerProxy(player, message.x, message.y, message.z);
|
||||
EntityPlayerMP proxy = createPlayerProxy(player, pp);
|
||||
proxy.playerNetServerHandler = player.playerNetServerHandler;
|
||||
proxy.inventory = player.inventory;
|
||||
proxy.currentWindowId = player.currentWindowId;
|
||||
proxy.inventoryContainer = player.inventoryContainer;
|
||||
proxy.openContainer = player.openContainer;
|
||||
proxy.worldObj = player.worldObj;
|
||||
|
||||
player.theItemInWorldManager.activateBlockOrUseItem(proxy, player.worldObj, null, message.x, message.y, message.z, 0, 0, 0, 0);
|
||||
player.theItemInWorldManager.thisPlayerMP = player;
|
||||
if(c != proxy.openContainer) {
|
||||
player.openContainer = proxy.openContainer;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T createPlayerProxy(EntityPlayerMP player, PlayerProxy proxy) {
|
||||
Enhancer e = new Enhancer();
|
||||
e.setCallback(proxy);
|
||||
|
||||
e.setSuperclass(player.getClass());
|
||||
Class<?>[] argTypes = new Class[] { MinecraftServer.class, WorldServer.class, GameProfile.class, ItemInWorldManager.class };
|
||||
Object[] args = new Object[] { player.mcServer, player.worldObj, player.getGameProfile(), player.theItemInWorldManager };
|
||||
|
||||
e.setInterceptDuringConstruction(false);
|
||||
@SuppressWarnings("unchecked")
|
||||
T proxifiedObj = (T) e.create(argTypes, args);
|
||||
|
||||
return proxifiedObj;
|
||||
}
|
||||
|
||||
public static class PlayerProxy implements MethodInterceptor {
|
||||
|
||||
private EntityPlayerMP realObj;
|
||||
|
||||
private Set<String> interceptNames = new HashSet<String>();
|
||||
|
||||
private Set<String> beaconNames = new HashSet<String>();
|
||||
private Set<String> anvilNames = new HashSet<String>();
|
||||
|
||||
private Set<String> distanceNames = new HashSet<String>();
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
public PlayerProxy(EntityPlayerMP obj, int x, int y, int z) {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
// TODO: Move to config? or use reflectioon helper?
|
||||
this.realObj = obj;
|
||||
interceptNames.add("openGui");
|
||||
interceptNames.add("func_146100_a");
|
||||
|
||||
interceptNames.add("displayGUIBrewingStand");
|
||||
interceptNames.add("func_71017_a");
|
||||
interceptNames.add("func_146098_a");
|
||||
|
||||
interceptNames.add("displayGUIChest");
|
||||
interceptNames.add("func_71007_a");
|
||||
|
||||
interceptNames.add("displayGUIDispenser");
|
||||
interceptNames.add("func_71006_a");
|
||||
interceptNames.add("func_146102_a");
|
||||
|
||||
interceptNames.add("displayGUIEnchantment");
|
||||
interceptNames.add("func_71002_c");
|
||||
|
||||
interceptNames.add("displayGUIFurnace");
|
||||
interceptNames.add("func_71042_a");
|
||||
interceptNames.add("func_146101_a");
|
||||
|
||||
interceptNames.add("displayGUIWorkbench");
|
||||
interceptNames.add("func_71058_b");
|
||||
|
||||
interceptNames.add("displayGuiHopper"); // for when its added
|
||||
interceptNames.add("func_94064_a"); // displayGuiHopper
|
||||
|
||||
interceptNames.add("displayGUIHopper");
|
||||
interceptNames.add("func_146093_a");
|
||||
|
||||
beaconNames.add("displayGUIBeacon");
|
||||
beaconNames.add("func_82240_a");
|
||||
beaconNames.add("func_146104_a");
|
||||
|
||||
anvilNames.add("displayGUIAnvil");
|
||||
anvilNames.add("func_82244_d");
|
||||
|
||||
distanceNames.add("getDistanceSq");
|
||||
distanceNames.add("getDistance");
|
||||
distanceNames.add("func_70092_e");
|
||||
distanceNames.add("func_70011_f");
|
||||
distanceNames.add("func_71569_e");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
|
||||
|
||||
if(interceptNames.contains(method.getName())) {
|
||||
|
||||
Object res = method.invoke(realObj, objects);
|
||||
if(realObj.openContainer != null) {
|
||||
realObj.openContainer = new ContainerWrapper(realObj.openContainer);
|
||||
}
|
||||
return res;
|
||||
|
||||
} else if(beaconNames.contains(method.getName())) {
|
||||
|
||||
// Beacon needs to be done manually for some reason to work properly
|
||||
TileEntityBeacon par1TileEntityBeacon = (TileEntityBeacon) objects[0];
|
||||
realObj.getNextWindowId();
|
||||
|
||||
realObj.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(realObj.currentWindowId, 7, par1TileEntityBeacon.getInventoryName(),
|
||||
par1TileEntityBeacon.getSizeInventory(), true));
|
||||
|
||||
realObj.openContainer = new ContainerBeacon(realObj.inventory, par1TileEntityBeacon) {
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer par1EntityPlayer) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
realObj.openContainer.windowId = realObj.currentWindowId;
|
||||
realObj.openContainer.addCraftingToCrafters(realObj);
|
||||
return null;
|
||||
|
||||
} else if(anvilNames.contains(method.getName())) {
|
||||
|
||||
realObj.getNextWindowId();
|
||||
realObj.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(realObj.currentWindowId, 8, "Repairing", 9, true));
|
||||
|
||||
realObj.openContainer = new ContainerRepair(realObj.inventory, realObj.worldObj, ((Integer) objects[0]).intValue(), ((Integer) objects[1]).intValue(),
|
||||
((Integer) objects[2]).intValue(), realObj) {
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer par1EntityPlayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
realObj.openContainer.windowId = realObj.currentWindowId;
|
||||
realObj.openContainer.addCraftingToCrafters(realObj);
|
||||
return null;
|
||||
|
||||
} else if(distanceNames.contains(method.getName())) {
|
||||
return 6;
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(realObj, objects);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package crazypants.enderio.enderface;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.util.Vec3;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
|
||||
public class PacketOpenServerGUI implements IMessage, IMessageHandler<PacketOpenServerGUI, IMessage> {
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int side;
|
||||
Vec3 hitVec;
|
||||
|
||||
public PacketOpenServerGUI() {
|
||||
}
|
||||
|
||||
public PacketOpenServerGUI(int x, int y, int z, int side, Vec3 hitVec) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.side = side;
|
||||
this.hitVec = hitVec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buffer) {
|
||||
buffer.writeInt(x);
|
||||
buffer.writeInt(y);
|
||||
buffer.writeInt(z);
|
||||
buffer.writeInt(side);
|
||||
buffer.writeDouble(hitVec.xCoord);
|
||||
buffer.writeDouble(hitVec.yCoord);
|
||||
buffer.writeDouble(hitVec.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buffer) {
|
||||
x = buffer.readInt();
|
||||
y = buffer.readInt();
|
||||
z = buffer.readInt();
|
||||
side = buffer.readInt();
|
||||
hitVec = Vec3.createVectorHelper(buffer.readDouble(), buffer.readDouble(), buffer.readDouble());
|
||||
}
|
||||
|
||||
public IMessage onMessage(PacketOpenServerGUI message, MessageContext ctx) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) ctx.getServerHandler().playerEntity;
|
||||
Container c = player.openContainer;
|
||||
|
||||
PacketHandler.INSTANCE.sendTo(new PacketLockClientContainer(player.openContainer.windowId), player);
|
||||
Vec3 hitVec = message.hitVec;
|
||||
player.theItemInWorldManager.activateBlockOrUseItem(player, player.worldObj, null, message.x, message.y, message.z, message.side, (float) hitVec.xCoord,
|
||||
(float) hitVec.yCoord, (float) hitVec.zCoord);
|
||||
player.theItemInWorldManager.thisPlayerMP = player;
|
||||
if (c != player.openContainer) {
|
||||
EnderIOController.INSTANCE.addContainer(player, player.openContainer);
|
||||
} else {
|
||||
PacketHandler.INSTANCE.sendTo(new PacketLockClientContainer(), player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
package crazypants.enderio.enderface.te;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
import crazypants.enderio.Log;
|
||||
|
||||
public class MeProxy {
|
||||
|
||||
public static final MeProxy instance = new MeProxy();
|
||||
|
||||
private MeProxy() {
|
||||
}
|
||||
|
||||
public boolean isMeAccessTerminal(EntityPlayer player, int x, int y, int z) {
|
||||
TileEntity te = player.worldObj.getTileEntity(x, y, z);
|
||||
if(te != null && (te.getClass().getName().equals("appeng.me.tile.TileTerminal") || te.getClass().getName().equals("appeng.me.tile.TileCraftingTerminal"))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isCraftingTerminal(EntityPlayer player, int x, int y, int z) {
|
||||
TileEntity te = player.worldObj.getTileEntity(x, y, z);
|
||||
if(te != null && te.getClass().getName().equals("appeng.me.tile.TileCraftingTerminal")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object createTerminalGui(EntityPlayer player, int x, int y, int z) {
|
||||
if(isCraftingTerminal(player, x, y, z)) {
|
||||
return createCraftingTerminalGui(player, x, y, z);
|
||||
}
|
||||
try {
|
||||
Class<?> cl = Class.forName("appeng.me.gui.GuiTerminal");
|
||||
cl.getDeclaredField("initialSearch").set(null, "");
|
||||
cl.getDeclaredField("initialScroll").set(null, 0);
|
||||
|
||||
Container c = MeProxy.createMeTerminalContainer(player, x, y, z, true);
|
||||
Constructor<?> constr = cl.getDeclaredConstructor(Container.class);
|
||||
return constr.newInstance(c);
|
||||
} catch (Exception e) {
|
||||
Log.warn("BlockEnderIO: Error occured creating the server element for an ME Terminal " + e);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object createCraftingTerminalGui(EntityPlayer player, int x, int y, int z) {
|
||||
try {
|
||||
|
||||
Class<?> cl = Class.forName("appeng.me.gui.GuiTerminal");
|
||||
cl.getDeclaredField("initialSearch").set(null, "");
|
||||
cl.getDeclaredField("initialScroll").set(null, 0);
|
||||
|
||||
cl = Class.forName("appeng.me.gui.GuiCraftingTerminal");
|
||||
Constructor<?> constr = cl.getDeclaredConstructor(Class.forName("appeng.me.container.ContainerCraftingTerminal"));
|
||||
|
||||
return constr.newInstance(createMeCraftingTerminalContainer(player, x, y, z, true));
|
||||
} catch (Exception e) {
|
||||
Log.warn("BlockEnderIO: Error occured creating the client gui for an ME Crafting Terminal " + e);
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Container createMeCraftingTerminalContainer(EntityPlayer player, int x, int y, int z, boolean isClient) throws Exception {
|
||||
Enhancer e = new Enhancer();
|
||||
e.setCallback(new ContainerTerminalProxy());
|
||||
|
||||
Class<?> baseClass = Class.forName("appeng.me.container.ContainerCraftingTerminal");
|
||||
e.setSuperclass(baseClass);
|
||||
Class<?> gteClass = Class.forName("appeng.api.me.tiles.IGridTileEntity");
|
||||
Class<?>[] argTypes = new Class[] { InventoryPlayer.class, gteClass };
|
||||
Object[] args = new Object[] { player.inventory, player.worldObj.getTileEntity(x, y, z) };
|
||||
|
||||
e.setInterceptDuringConstruction(false);
|
||||
|
||||
Container proxifiedObj = (Container) e.create(argTypes, args);
|
||||
if(!isClient) {
|
||||
proxifiedObj.setPlayerIsPresent(player, true);
|
||||
}
|
||||
return proxifiedObj;
|
||||
}
|
||||
|
||||
public static Container createMeTerminalContainer(EntityPlayer player, int x, int y, int z, boolean isClient) throws Exception {
|
||||
|
||||
if(isCraftingTerminal(player, x, y, z)) {
|
||||
return createMeCraftingTerminalContainer(player, x, y, z, isClient);
|
||||
}
|
||||
|
||||
Enhancer e = new Enhancer();
|
||||
e.setCallback(new ContainerTerminalProxy());
|
||||
|
||||
Class<?> baseClass = Class.forName("appeng.me.container.ContainerTerminal");
|
||||
e.setSuperclass(baseClass);
|
||||
Class<?> gteClass = Class.forName("appeng.api.me.tiles.IGridTileEntity");
|
||||
Class<?>[] argTypes = new Class[] { InventoryPlayer.class, gteClass, boolean.class };
|
||||
Object[] args = new Object[] { player.inventory, isClient ? null : player.worldObj.getTileEntity(x, y, z), false };
|
||||
|
||||
e.setInterceptDuringConstruction(false);
|
||||
|
||||
Container proxifiedObj = (Container) e.create(argTypes, args);
|
||||
if(!isClient) {
|
||||
proxifiedObj.setPlayerIsPresent(player, true);
|
||||
}
|
||||
return proxifiedObj;
|
||||
}
|
||||
|
||||
// private static void callSetPlayerPresent(EntityPlayer player, Container proxifiedObj) throws ClassNotFoundException, NoSuchMethodException,
|
||||
// IllegalAccessException, InvocationTargetException {
|
||||
// Class<?> baseClass = Class.forName("appeng.me.container.ContainerTerminal");
|
||||
// Method m = null;
|
||||
// try {
|
||||
// m = baseClass.getDeclaredMethod("func_75128_a", EntityPlayer.class, boolean.class);
|
||||
// } catch (Exception ex) {
|
||||
// //ignore, probaly de-obf environemnt
|
||||
// }
|
||||
// if(m == null) {
|
||||
// m = baseClass.getDeclaredMethod("setPlayerIsPresent", EntityPlayer.class, boolean.class);
|
||||
// }
|
||||
// m.invoke(proxifiedObj, player, true);
|
||||
// }
|
||||
|
||||
public static class ContainerTerminalProxy implements MethodInterceptor {
|
||||
|
||||
private ContainerTerminalProxy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
|
||||
if("func_75145_c".equals(method.getName()) || "canInteractWith".equals(method.getName())) {
|
||||
return true;
|
||||
}
|
||||
return methodProxy.invokeSuper(o, objects);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user