Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello Everyone I have a problem, I've been trying to make an item that lets you zoom when certain key is pressed. I have 2 versions

 

Version 1:

 

package kaiKaii99Proxy;

 

import java.util.EnumSet;

 

import kaiKaii99.MainClass;

 

import org.lwjgl.input.Keyboard;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.Gui;

import net.minecraft.client.renderer.EntityRenderer;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import cpw.mods.fml.client.FMLClientHandler;

import cpw.mods.fml.common.FMLCommonHandler;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

import cpw.mods.fml.relauncher.ReflectionHelper;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

@SideOnly(Side.CLIENT)

public class ClientTickHandler extends Gui implements ITickHandler

{

 

public boolean isZoomed = false;

 

public boolean canZoom = false;

Class c = EntityRenderer.class;

Object o = Minecraft.getMinecraft().entityRenderer;

public ClientTickHandler()

{

super();

}

@Override

public EnumSet<TickType> ticks()

{

return EnumSet.of(TickType.RENDER);

}

 

@Override

public void tickEnd(EnumSet<TickType> type, Object... tickData)

{

               

               

                if(type.contains(TickType.RENDER)){

               

               

               

        if(Keyboard.isKeyDown(Keyboard.KEY_Z)){

        ReflectionHelper.setPrivateValue(c, o, 5D, 36);

        }

        if(!Keyboard.isKeyDown(Keyboard.KEY_Z)){

        ReflectionHelper.setPrivateValue(c, o, 1D, 36);

        }

      }

  }

 

 

 

 

@Override

public void tickStart(EnumSet<TickType> type, Object... tickData)

{

 

}

protected void drawGradientRect(int par1, int par2, int par3, int par4, int par5, int par6)

{

 

}

public void drawScreen(int par1, int par2, float par3)

{

 

}

public static void inizializePlayer(EntityPlayer par1EntityPlayer)

{

 

}

@Override

public String getLabel() {

 

return null;

}

}

 

 

and Version 2:

 

 

package kaiKaii99Proxy;

 

import java.util.EnumSet;

 

import kaiKaii99.MainClass;

 

import org.lwjgl.input.Keyboard;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.Gui;

import net.minecraft.client.renderer.EntityRenderer;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import cpw.mods.fml.client.FMLClientHandler;

import cpw.mods.fml.common.FMLCommonHandler;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

import cpw.mods.fml.relauncher.ReflectionHelper;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

@SideOnly(Side.CLIENT)

public class ClientTickHandler extends Gui implements ITickHandler

{

 

public boolean isZoomed = false;

 

public boolean canZoom = false;

Class c = EntityRenderer.class;

Object o = Minecraft.getMinecraft().entityRenderer;

public ClientTickHandler()

{

super();

}

@Override

public EnumSet<TickType> ticks()

{

return EnumSet.of(TickType.RENDER);

}

 

@Override

public void tickEnd(EnumSet<TickType> type, Object... tickData)

{

                Minecraft mc = Minecraft.getMinecraft();

               

                if(type.contains(TickType.RENDER)){

               

                if(mc.thePlayer.getCurrentEquippedItem() != null)

                {

                ItemStack currItem = mc.thePlayer.getCurrentEquippedItem();

                if(currItem.getItem() == MainClass.MagicGauntlet){

                canZoom = true;

                }else{

                canZoom = false;

                }

               

                }

               

        if(Keyboard.isKeyDown(Keyboard.KEY_Z) && canZoom == true){

        ReflectionHelper.setPrivateValue(c, o, 5D, 36);

        }

        if(!Keyboard.isKeyDown(Keyboard.KEY_Z) || canZoom != true){

        ReflectionHelper.setPrivateValue(c, o, 1D, 36);

        }

      }

  }

 

 

 

 

@Override

public void tickStart(EnumSet<TickType> type, Object... tickData)

{

 

}

protected void drawGradientRect(int par1, int par2, int par3, int par4, int par5, int par6)

{

 

}

public void drawScreen(int par1, int par2, float par3)

{

 

}

public static void inizializePlayer(EntityPlayer par1EntityPlayer)

{

 

}

@Override

public String getLabel() {

 

return null;

}

}

 

 

 

In version 1 it works almost perfectly, well, i can zoom but with any item in my hand.

and in version 2 when i press the key and i have the correct item in my hand, when i release the key, it stays there, the value does not go back.

 

If you help me i will add you to my mod's credits list.

 

Thanks in advance

Firstly, learn to use "else".

 

Secondly, I notice your zoom code is inside the "if(type.contains(TickType.RENDER)){" in the first version, but outside it in the second.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

  • 1 month later...
I notice your zoom code is inside the "if(type.contains(TickType.RENDER)){" in the first version, but outside it in the second.

I double checked; That is just weird formatting.

What I would do:

Minecraft mc = Minecraft.getMinecraft();
boolean changed = false;
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{ 
      if(type.contains(TickType.RENDER) && mc.thePlayer!=null){         
              if(mc.thePlayer.getCurrentEquippedItem() != null){
                      ItemStack currItem = mc.thePlayer.getCurrentEquippedItem();
                      if(currItem.getItem().itemID == MainClass.MagicGauntlet.itemID){
                             if(Keyboard.isKeyDown(Keyboard.KEY_Z)){
                                   if(!changed){
                                         ReflectionHelper.setPrivateValue(c, o, 5D, 36);
                                         changed = true;
                                   }
                                   return;
                             }
                       }
                 }
              if(changed){
                       ReflectionHelper.setPrivateValue(c, o, 1D, 36);
                       changed = false;
             }
        }
}

This is to avoid all unnecessary reflection uses.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.