Search in sources :

Example 21 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project LogisticsPipes by RS485.

the class LPChatListener method serverChat.

@SubscribeEvent
public void serverChat(ServerChatEvent event) {
    EntityPlayerMP player = event.player;
    if (LPChatListener.tasks.containsKey(event.username)) {
        if (event.message.startsWith("/")) {
            player.addChatComponentMessage(new ChatComponentText(ChatColor.RED + "You need to answer the question, before you can use any other command"));
            MainProxy.sendPacketToPlayer(PacketHandler.getPacket(OpenChatGui.class), player);
        } else {
            if (!event.message.equalsIgnoreCase("true") && !event.message.equalsIgnoreCase("false") && !event.message.equalsIgnoreCase("on") && !event.message.equalsIgnoreCase("off") && !event.message.equalsIgnoreCase("0") && !event.message.equalsIgnoreCase("1") && !event.message.equalsIgnoreCase("no") && !event.message.equalsIgnoreCase("yes")) {
                player.addChatComponentMessage(new ChatComponentText(ChatColor.RED + "Not a valid answer."));
                player.addChatComponentMessage(new ChatComponentText(ChatColor.AQUA + "Please enter " + ChatColor.RESET + "<" + ChatColor.GREEN + "yes" + ChatColor.RESET + "/" + ChatColor.RED + "no " + ChatColor.RESET + "| " + ChatColor.GREEN + "true" + ChatColor.RESET + "/" + ChatColor.RED + "flase " + ChatColor.RESET + "| " + ChatColor.GREEN + "on" + ChatColor.RESET + "/" + ChatColor.RED + "off " + ChatColor.RESET + "| " + ChatColor.GREEN + "1" + ChatColor.RESET + "/" + ChatColor.RED + "0" + ChatColor.RESET + ">"));
                MainProxy.sendPacketToPlayer(PacketHandler.getPacket(OpenChatGui.class), player);
            } else {
                boolean flag = event.message.equalsIgnoreCase("true") || event.message.equalsIgnoreCase("on") || event.message.equalsIgnoreCase("1") || event.message.equalsIgnoreCase("yes");
                if (!handleAnswer(flag, player)) {
                    player.addChatComponentMessage(new ChatComponentText(ChatColor.RED + "Error: Could not handle answer."));
                }
            }
        }
        event.setCanceled(true);
    } else if (LPChatListener.morePageDisplays.containsKey(event.username)) {
        if (!LPChatListener.morePageDisplays.get(event.username).isTerminated()) {
            if (event.message.startsWith("/")) {
                player.addChatComponentMessage(new ChatComponentText(ChatColor.RED + "Exit " + ChatColor.AQUA + "PageView" + ChatColor.RED + " first!"));
                MainProxy.sendPacketToPlayer(PacketHandler.getPacket(OpenChatGui.class), player);
                event.setCanceled(true);
            } else {
                if (LPChatListener.morePageDisplays.get(event.username).handleChat(event.message, player)) {
                    event.setCanceled(true);
                }
            }
        }
    }
}
Also used : OpenChatGui(logisticspipes.network.packets.gui.OpenChatGui) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ChatComponentText(net.minecraft.util.ChatComponentText) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 22 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project LogisticsPipes by RS485.

the class LPChatListener method clientChat.

@SubscribeEvent
public void clientChat(ClientChatReceivedEvent event) {
    IChatComponent message = event.message;
    if (message != null) {
        String realMessage = null;
        try {
            realMessage = message.getFormattedText();
        } catch (ClassCastException e) {
        //Ignore that
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (realMessage != null) {
            if (realMessage.equals("%LPCLEARCHAT%")) {
                clearChat();
                event.setCanceled(true);
            }
            if (realMessage.equals("%LPSTORESENDMESSAGE%")) {
                storeSendMessages();
                event.setCanceled(true);
            }
            if (realMessage.equals("%LPRESTORESENDMESSAGE%")) {
                restoreSendMessages();
                event.setCanceled(true);
            }
            if (realMessage.startsWith("%LPADDTOSENDMESSAGE%")) {
                addSendMessages(realMessage.substring(20));
                event.setCanceled(true);
            }
            if (realMessage.contains("LPDISPLAYMISSING") && LPConstants.DEBUG) {
                System.out.println("LIST:");
                StringUtils.UNTRANSLATED_STRINGS.forEach(System.out::println);
            }
        }
    }
}
Also used : IChatComponent(net.minecraft.util.IChatComponent) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 23 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project LogisticsPipes by RS485.

the class QueuedTasks method tickEnd.

@SuppressWarnings({ "rawtypes" })
@SubscribeEvent
public void tickEnd(ServerTickEvent event) {
    if (event.phase != Phase.END) {
        return;
    }
    Callable call = null;
    while (!QueuedTasks.queue.isEmpty()) {
        synchronized (QueuedTasks.queue) {
            call = QueuedTasks.queue.removeFirst();
        }
        if (call != null) {
            try {
                call.call();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    MainProxy.proxy.tick();
    synchronized (LPTravelingItem.forceKeep) {
        Iterator<Pair<Integer, Object>> iter = LPTravelingItem.forceKeep.iterator();
        while (iter.hasNext()) {
            Pair<Integer, Object> pair = iter.next();
            pair.setValue1(pair.getValue1() - 1);
            if (pair.getValue1() < 0) {
                iter.remove();
            }
        }
    }
}
Also used : Callable(java.util.concurrent.Callable) Pair(logisticspipes.utils.tuples.Pair) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 24 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project LogisticsPipes by RS485.

the class RenderTickHandler method renderWorldLast.

//private static final ResourceLocation TEXTURE = new ResourceLocation("logisticspipes", "textures/blocks/pipes/White.png");
@SubscribeEvent
public void renderWorldLast(RenderWorldLastEvent worldEvent) {
    if (LogisticsRenderPipe.config.isUseNewRenderer()) {
        if (displayPipeGhost()) {
            Minecraft mc = Minecraft.getMinecraft();
            EntityPlayer player = mc.thePlayer;
            MovingObjectPosition box = mc.objectMouseOver;
            if (box != null && box.typeOfHit == MovingObjectType.BLOCK) {
                ItemStack stack = FMLClientHandler.instance().getClient().thePlayer.inventory.mainInventory[FMLClientHandler.instance().getClient().thePlayer.inventory.currentItem];
                CoreUnroutedPipe pipe = ((ItemLogisticsPipe) stack.getItem()).getDummyPipe();
                int i = box.blockX;
                int j = box.blockY;
                int k = box.blockZ;
                World world = player.getEntityWorld();
                int side = box.sideHit;
                Block worldBlock = world.getBlock(i, j, k);
                if (worldBlock == Blocks.snow) {
                    side = 1;
                } else if (worldBlock != Blocks.vine && worldBlock != Blocks.tallgrass && worldBlock != Blocks.deadbush && (worldBlock == null || !worldBlock.isReplaceable(world, i, j, k))) {
                    if (side == 0) {
                        j--;
                    }
                    if (side == 1) {
                        j++;
                    }
                    if (side == 2) {
                        k--;
                    }
                    if (side == 3) {
                        k++;
                    }
                    if (side == 4) {
                        i--;
                    }
                    if (side == 5) {
                        i++;
                    }
                }
                double xCoord = i;
                double yCoord = j;
                double zCoord = k;
                boolean isFreeSpace = true;
                ITubeOrientation orientation = null;
                if (pipe instanceof CoreMultiBlockPipe) {
                    CoreMultiBlockPipe multipipe = (CoreMultiBlockPipe) pipe;
                    DoubleCoordinates placeAt = new DoubleCoordinates(xCoord, yCoord, zCoord);
                    LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> globalPos = new LPPositionSet<>(DoubleCoordinatesType.class);
                    globalPos.add(new DoubleCoordinatesType<>(placeAt, CoreMultiBlockPipe.SubBlockTypeForShare.NON_SHARE));
                    LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> positions = multipipe.getSubBlocks();
                    orientation = multipipe.getTubeOrientation(player, (int) xCoord, (int) zCoord);
                    if (orientation != null) {
                        orientation.rotatePositions(positions);
                        positions.stream().map(pos -> pos.add(placeAt)).forEach(globalPos::add);
                        globalPos.addToAll(orientation.getOffset());
                        for (DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> pos : globalPos) {
                            if (!player.getEntityWorld().canPlaceEntityOnSide(LogisticsPipes.LogisticsPipeBlock, pos.getXInt(), pos.getYInt(), pos.getZInt(), false, side, player, stack)) {
                                TileEntity tile = player.getEntityWorld().getTileEntity(pos.getXInt(), pos.getYInt(), pos.getZInt());
                                boolean canPlace = false;
                                if (tile instanceof LogisticsTileGenericSubMultiBlock) {
                                    if (CoreMultiBlockPipe.canShare(((LogisticsTileGenericSubMultiBlock) tile).getSubTypes(), pos.getType())) {
                                        canPlace = true;
                                    }
                                }
                                if (!canPlace) {
                                    isFreeSpace = false;
                                    break;
                                }
                            }
                        }
                    } else {
                        return;
                    }
                } else {
                    if (!player.getEntityWorld().canPlaceEntityOnSide(LogisticsPipes.LogisticsPipeBlock, i, j, k, false, side, player, stack)) {
                        isFreeSpace = false;
                    }
                }
                if (isFreeSpace) {
                    GL11.glPushMatrix();
                    double x;
                    double y;
                    double z;
                    if (orientation != null) {
                        x = xCoord + orientation.getOffset().getXInt() - player.prevPosX - ((player.posX - player.prevPosX) * worldEvent.partialTicks);
                        y = yCoord + orientation.getOffset().getYInt() - player.prevPosY - ((player.posY - player.prevPosY) * worldEvent.partialTicks);
                        z = zCoord + orientation.getOffset().getZInt() - player.prevPosZ - ((player.posZ - player.prevPosZ) * worldEvent.partialTicks);
                    } else {
                        x = xCoord - player.prevPosX - ((player.posX - player.prevPosX) * worldEvent.partialTicks);
                        y = yCoord - player.prevPosY - ((player.posY - player.prevPosY) * worldEvent.partialTicks);
                        z = zCoord - player.prevPosZ - ((player.posZ - player.prevPosZ) * worldEvent.partialTicks);
                    }
                    GL11.glTranslated(x + 0.001, y + 0.001, z + 0.001);
                    GL11.glEnable(GL11.GL_BLEND);
                    //GL11.glDepthMask(false);
                    GL11.glDisable(GL11.GL_TEXTURE_2D);
                    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                    mc.renderEngine.bindTexture(new ResourceLocation("logisticspipes", "textures/blocks/pipes/White.png"));
                    Tessellator tess = Tessellator.instance;
                    CCRenderState.reset();
                    CCRenderState.useNormals = true;
                    CCRenderState.alphaOverride = 0xff;
                    GL11.glEnable(GL11.GL_TEXTURE_2D);
                    CCRenderState.alphaOverride = 0x50;
                    CCRenderState.useNormals = true;
                    CCRenderState.hasBrightness = false;
                    CCRenderState.startDrawing();
                    pipe.getHighlightRenderer().renderHighlight(orientation);
                    tess.draw();
                    CCRenderState.alphaOverride = 0xff;
                    GL11.glDisable(GL11.GL_BLEND);
                    GL11.glDepthMask(true);
                    GL11.glPopMatrix();
                }
            }
        }
    }
}
Also used : ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) EventPriority(cpw.mods.fml.common.eventhandler.EventPriority) Blocks(net.minecraft.init.Blocks) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) LogisticsPipes(logisticspipes.LogisticsPipes) ActiveRenderInfo(net.minecraft.client.renderer.ActiveRenderInfo) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) RenderTickEvent(cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) Minecraft(net.minecraft.client.Minecraft) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) LogisticsGuiOverrenderer(logisticspipes.renderer.LogisticsGuiOverrenderer) ClientViewController(logisticspipes.routing.debug.ClientViewController) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsRenderPipe(logisticspipes.renderer.LogisticsRenderPipe) FMLClientHandler(cpw.mods.fml.client.FMLClientHandler) Core(tv.twitch.Core) GL11(org.lwjgl.opengl.GL11) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) CCRenderState(codechicken.lib.render.CCRenderState) World(net.minecraft.world.World) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) CoordinateUtils(network.rs485.logisticspipes.world.CoordinateUtils) Phase(cpw.mods.fml.common.gameevent.TickEvent.Phase) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Tessellator(net.minecraft.client.renderer.Tessellator) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectType(net.minecraft.util.MovingObjectPosition.MovingObjectType) Tessellator(net.minecraft.client.renderer.Tessellator) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) ResourceLocation(net.minecraft.util.ResourceLocation) ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Minecraft(net.minecraft.client.Minecraft) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) LPPositionSet(logisticspipes.utils.LPPositionSet) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 25 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project LogisticsPipes by RS485.

the class RenderTickHandler method renderTick.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void renderTick(RenderTickEvent event) {
    if (event.phase == Phase.START) {
        if (LogisticsGuiOverrenderer.getInstance().isCompatibleGui()) {
            LogisticsGuiOverrenderer.getInstance().preRender();
        }
        ClientViewController.instance().tick();
    } else {
        renderTicks++;
        if (LogisticsHUDRenderer.instance().displayRenderer()) {
            GL11.glPushMatrix();
            Minecraft mc = FMLClientHandler.instance().getClient();
            //Orientation
            mc.entityRenderer.setupCameraTransform(event.renderTickTime, 1);
            ActiveRenderInfo.updateRenderInfo(mc.thePlayer, mc.gameSettings.thirdPersonView == 2);
            LogisticsHUDRenderer.instance().renderWorldRelative(renderTicks, event.renderTickTime);
            mc.entityRenderer.setupOverlayRendering();
            GL11.glPopMatrix();
            GL11.glPushMatrix();
            LogisticsHUDRenderer.instance().renderPlayerDisplay(renderTicks);
            GL11.glPopMatrix();
        } else if (LogisticsGuiOverrenderer.getInstance().isCompatibleGui()) {
            LogisticsGuiOverrenderer.getInstance().renderOverGui();
        }
    }
}
Also used : Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)109 EntityPlayer (net.minecraft.entity.player.EntityPlayer)45 ItemStack (net.minecraft.item.ItemStack)45 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)14 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 World (net.minecraft.world.World)11 Minecraft (net.minecraft.client.Minecraft)10 ChunkPosition (net.minecraft.world.ChunkPosition)9 EntityItem (net.minecraft.entity.item.EntityItem)8 ChatComponentText (net.minecraft.util.ChatComponentText)8 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 AffinityData (am2.playerextensions.AffinityData)5 SideOnly (cpw.mods.fml.relauncher.SideOnly)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Block (net.minecraft.block.Block)5 EntityEnderman (net.minecraft.entity.monster.EntityEnderman)5 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)5 ExtendedProperties (am2.playerextensions.ExtendedProperties)4