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);
}
}
}
}
}
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);
}
}
}
}
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();
}
}
}
}
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();
}
}
}
}
}
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();
}
}
}
Aggregations