2017-06-24 105 views
-2

爲什麼我得到這個錯誤?Java錯誤:構造函數C17PacketCustomPayload(String,byte [])未定義

The constructor C17PacketCustomPayload(String, byte[]) is undefined

Java代碼:

package pw.cinque.ping; 

import java.awt.Color; 

import net.minecraft.client.Minecraft; 

import net.minecraft.network.Packet; 

import net.minecraft.network.PacketBuffer; 

import net.minecraft.network.play.client.C17PacketCustomPayload; 

import net.minecraftforge.common.MinecraftForge; 

import net.minecraftforge.fml.common.FMLCommonHandler; 

import net.minecraftforge.fml.common.Mod; 

import net.minecraftforge.fml.common.gameevent.InputEvent; 

import net.minecraftforge.fml.common.Mod.EventHandler; 

import net.minecraftforge.fml.common.event.FMLInitializationEvent; 

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 

import net.minecraftforge.fml.common.gameevent.TickEvent; 

import java.awt.*; 

import java.nio.ByteBuffer; 

import org.lwjgl.input.Keyboard; 

@Mod(modid = Packets.MODID, version = Packets.VERSION) 
public class Packets 
{ 
    public static final String MODID = "Lower ur ping!"; 

    public static final String VERSION = "1.0"; 

    private static final Minecraft mc = Minecraft.getMinecraft(); 

    private boolean textGui; 

    private final int textGuiKey = Keyboard.KEY_P; 

    private boolean reachToogle; 

    private final int reachKey = Keyboard.KEY_L; 

    @EventHandler 
    public void init(FMLInitializationEvent event) 
    { 
     FMLCommonHandler.instance().bus().register(this); 

     MinecraftForge.EVENT_BUS.register(this); 

     System.out.println("Intialized Reach Mod by Shiny"); 
    } 

    @SubscribeEvent 
    public void onRender(TickEvent.RenderTickEvent e) { 

     if(textGui) 

      mc.fontRendererObj.drawStringWithShadow("Shiny", 2, 2, Color.BLACK.hashCode()); 

    } 


    @SubscribeEvent 
    public void onKeyInput(InputEvent.KeyInputEvent e) { 

     if(Keyboard.isKeyDown(textGuiKey)) { 

      textGui = !textGui; 

      return; 

     } 
     else if(Keyboard.isKeyDown(reachKey)) { 

       reachToogle = !reachToogle; 
      } 

     Packet spoofedReachPacket = manipulateReachPacket(spoofReachValue(4.2)); 

     mc.thePlayer.sendQueue.addToSendQueue(spoofedReachPacket); 
    } 

    private Packet manipulateReachPacket(byte[] spoofedReachValue) { 

     return new C17PacketCustomPayload("reach", spoofedReachValue); 
    } 

    private byte[] spoofReachValue(double reachValue) { 

     byte[] buffer = new byte[8]; 

     ByteBuffer.wrap(buffer).putDouble(reachValue`enter code here`); 

     return buffer; 
    } 
} 
+1

什麼構造函數_does_'C17PacketCustomPayload'有? –

+1

我猜測這意味着該構造函數沒有定義。問題是什麼? – EJoshuaS

回答

1

我猜你在這裏得到你的錯誤:

return new C17PacketCustomPayload("reach", spoofedReachValue); 

它說,構造函數是不確定的,這意味着該類C17PacketCustomPayload不有一個構造函數將一個字符串和/或byte []作爲參數。如果你創建了這個類自己,那麼你需要添加看起來像這樣

public C17PacketCustomPayload(String string, byte[] bytes){ 
//add behavior here 
} 

如果你沒有創建這個類,但僅僅是進口,那麼你需要查找正是這個參數構造函數取和方法相應地修復它。

0

Why I am getting this error?

從這些逆向工程javadocs可以明顯地看出答案。

Constructors: 

C17PacketCustomPayload() 
C17PacketCustomPayload(java.lang.String p1, PacketBuffer p1) 

在你的代碼,構造函數調用的第二個參數必須是一個PacketBuffer對象,而不是byte[]

相關問題