Jump to content

[1.8] proxy thing i have doubs about how to use them.<SOLVED>


perromercenary00

Recommended Posts

good days

im trying to fix some omisions in my first mod and there is this proxy thing, in the basic guides they dont speak much about proxy's,

now i been reading MinecraftByExample codes to realize how to use proxies, for whath i habe understood, there is this this to proxy's

for the way , commonProxy run in local world and server and here goes every item/block registry and the unlocalizated name variable

and clienProxy run just in local world and has the register textures to use whith the items,

 

so there is mi piece of mod whit just one item a bow "arcoMercenario"

 

package mercenarymod;

import mercenarymod.blocks.MercenaryModBlocks;
import mercenarymod.items.MercenaryModItems;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraft.creativetab.CreativeTabs;

@Mod(modid = Mercenary.MODID, version = Mercenary.VERSION)
public class Mercenary
{
    public static final String MODID = "modmercenario";
    public static final String VERSION = "1.7";
    
    public static SimpleNetworkWrapper network;
    
    // Says where the client and server 'proxy' code is loaded.
    @SidedProxy(clientSide="mercenario.ClientProxy", serverSide="mercenarymod.CommonProxy")
    public static CommonProxy proxy;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
    proxy.preInit(event);
    }
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    proxy.init(event);
    }
    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
    proxy.postInit(event);
    }
    
    public static CreativeTabs herramientas = new CreativeTabs("Herraminetas armas y\n armaduras mercenarias") {
        @Override
        @SideOnly(Side.CLIENT)
        public Item getTabIconItem() {
            //return MercenaryModItems.aceroMercenario;
              return Items.potato;
         }
    };

    public static CreativeTabs materiales = new CreativeTabs("materiales mercenarios") {
        @Override
        @SideOnly(Side.CLIENT)
        public Item getTabIconItem() {
            //return MercenaryModItems.nokiaMercenaria;
              return Items.potato;
        }
    };

      
    
}

 

eclipse make my add the "event" inside  proxy.preInit(event);  coz "The method preInit(FMLPreInitializationEvent) in the type CommonProxy is not applicable for the arguments ()"

 

 

mercenario.ClientProxy

package mercenarymod;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import mercenarymod.CommonProxy;
import mercenarymod.blocks.MercenaryModBlocks;
import mercenarymod.items.MercenaryModItems;

public class ClientProxy extends CommonProxy {
       
        @Override
        public void registerRenderers() {
                // This is for rendering entities and so forth later on
        }
        
        @Mod.EventHandler
        public void preInit(FMLPreInitializationEvent event) {
        Configuration config = new Configuration(event.getSuggestedConfigurationFile());	

        }
     
        @Mod.EventHandler
        public void init(FMLInitializationEvent event) {

        	ModelBakery.addVariantName(MercenaryModItems.arcoMercenario, new String[]{     
            		"modmercenario:arcos/arcomercenario/arcomercenario00",
            		"modmercenario:arcos/arcomercenario/arcomercenario01",
            		"modmercenario:arcos/arcomercenario/arcomercenario02",
            		"modmercenario:arcos/arcomercenario/arcomercenario03",
            		"modmercenario:arcos/arcomercenario/flechaMercenaria" });
          
            Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(MercenaryModItems.arcoMercenario,0 , 
            new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario00", "inventory"));
        }
     
        @Mod.EventHandler
        public void postInit(FMLPostInitializationEvent event) {
        }
}

 

mercenarymod.CommonProxy

package mercenarymod;

import mercenarymod.blocks.MercenaryModBlocks;
import mercenarymod.items.MercenaryModItems;
import net.minecraft.item.Item;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class CommonProxy {

        // Client stuff
        public void registerRenderers() {
                // Nothing here as the server doesn't render graphics or entities!
        }
        
        public static Item arcoMercenario;
        
        @Mod.EventHandler
        public void preInit(FMLPreInitializationEvent event) {
        	
        	arcoMercenario = (mercenarymod.items.arcos.arcoMercenario)(new mercenarymod.items.arcos.arcoMercenario().setUnlocalizedName("arcoMercenario"));
        	GameRegistry.registerItem(arcoMercenario, "arcoMercenario");
        }
     
        @Mod.EventHandler
        public void init(FMLInitializationEvent event) {
        }
     
        @Mod.EventHandler
        public void postInit(FMLPostInitializationEvent event) {
        }
}

 

the bow

 

mercenarymod.items.arcos.arcoMercenario.java

package mercenarymod.items.arcos;

import mercenarymod.Mercenary;
import mercenarymod.items.MercenaryModItems;
import mercenarymod.utilidades.chat;
import mercenarymod.utilidades.nbtMercenaria;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class arcoMercenario extends Item
{
    
   
    //public static String name = "arcoMercenario";
    
    int tick=0;
    int texturajson=0;
    boolean tighten=false;
    boolean animacion=false;
    boolean continuar=false;
        
    float f=0.0F;
    int municion=0;
    int municionMax=0;
    static int municionMax0=32;

    public arcoMercenario()
    {
    	
    	//setUnlocalizedName(Mercenary.MODID + "_" + name);
    	//GameRegistry.registerItem(this, name);
    	setCreativeTab(Mercenary.herramientas);
        this.maxStackSize = 1;
        this.setMaxDamage(500);
        
    }
    
  //######################################################################################3	
  	 @Override
  public ModelResourceLocation getModel(ItemStack arco, EntityPlayer playerIn, int useRemaining){
  	
  	ModelResourceLocation modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario00", "inventory");	 
  	animacion(arco, playerIn);
  	
  	if ((tick%10)==0){ //just to not check it every tick, it lags
  		
  	animacion=nbtMercenaria.getBooleantag(arco, "animacion");
  	//System.out.println("Animacion="+animacion);
  		
  	if(!animacion){
  	
  	tighten=false;
  	
  	}
  	}
  		
  	//System.out.println("textura="+textura);
  	switch(this.texturajson){
    default:modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario00", "inventory") ;break;
  	case  1:modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario01", "inventory") ;break;
  	case  2:modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario02", "inventory") ;break;	
  	case  3:modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario03", "inventory") ;break;
  	    	                }
  	  	
  	tick++;
  	if (tick>100){tick=0;nbtMercenaria.setBooleantag(arco, "animacion",false);animacion=false;}
    	return modelresourcelocation;
    	
  		}

  //####################################################################################3	
  void animacion(ItemStack arco, EntityPlayer playerIn){	 //int tick
  	
  	//System.out.println("()this.thick="+tick+" cambioDeBotella="+cambioDeBotella+" giro="+giro);
  	 
  	 if ((tighten)){
  	 System.out.println("tighten="+tick);	 
  	 switch (tick){
  	 case 0:  texturajson=0;f=0.50F;break;
  	 case 7:  texturajson=1;f=1.00F;break;
  	 case 14: texturajson=2;f=1.50F;break;
  	 case 21: texturajson=3;f=2.00F;break;
  	 case 28: if(continuar){tick=20;};break;
  	 case 30: texturajson=0;tick=0;nbtMercenaria.setBooleantag(arco, "animacion",false);tighten=false;break;
  	          }   }
  	 else{texturajson=0;}
  	 
  	 
  	 
  }

//####################################################################################3		

void inicializar(ItemStack arco){  //this do nothing for now

int municion=0;
int metadata=arco.getMetadata();

switch(metadata){
case 1: municion=municionMax0/2;break;
case 2: municion=municionMax0;break;
default:municion=0;break;
            	}

nbtMercenaria.setInttag(arco, "municion", municion);
nbtMercenaria.setBooleantag(arco, "animacion", false);
nbtMercenaria.setBooleantag(arco, "liberar", false);
nbtMercenaria.setInttag(arco, "cargador", 0);
nbtMercenaria.setInttag(arco, "textura", 0);			


}
  
//####################################################################################3
    public void onPlayerStoppedUsing(ItemStack arco, World worldIn, EntityPlayer playerIn, int timeLeft)
    {
    	
    	
    	if (!worldIn.isRemote){
    		
    	playerIn.inventory.consumeInventoryItem(MercenaryModItems.flechaMercenaria);	
    		
    	EntityArrow entityarrow = new EntityArrow(worldIn, playerIn, f );	
    		
    	worldIn.spawnEntityInWorld(entityarrow);	
    	
    	chat.chatdp(playerIn, "disparando f="+f);
    	
    	f=0.0F;
    	
    	nbtMercenaria.setBooleantag(arco, "animacion", false);
    	    	
    		
    	                       }
    	
    	
    	
    	texturajson=0;tick=0;tighten=false;continuar=false;
    	
    }

    public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer playerIn)
    {
    	//texturajson=0;tick=0;tighten=false;
        return stack;
        
    }

    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 72000;
    }

    public EnumAction getItemUseAction(ItemStack stack)
    {
        return EnumAction.BOW;
    }

    
    //#####################################################################################3
    public ItemStack onItemRightClick(ItemStack arco, World worldIn, EntityPlayer playerIn)
    {
    	
    	if (!worldIn.isRemote){
    		/*
    		BlockPos ppos=playerIn.getPosition();
    		double x=ppos.getX();
    		double y=ppos.getY();
    		double z=ppos.getZ();
    		
    		EntityBreakingFX(worldIn, x, y, z, Items.emerald);
    		*/
    		
    		if (playerIn.capabilities.isCreativeMode 
    		|| playerIn.inventory.hasItem(MercenaryModItems.flechaMercenaria)){ //mercenaryArrow
    		//|| playerIn.inventory.hasItem(Items.arrow)){
    		
    		//municion=nbtMercenaria.getInttag(arco, "municion"); //not now
    		nbtMercenaria.setBooleantag(arco, "animacion", true);
    		animacion=true;
    		tighten=true;
    		//chat.chatdp(playerIn, "has item "+tick);
    		
    	                     }}
    	
    	if (tighten){
    		playerIn.setItemInUse(arco, this.getMaxItemUseDuration(arco));	
    		tick=0;
    		continuar=true;
    		//chat.chatdp(playerIn, "En Uso"+tick);  // in use
    		}
        
        return arco;
    }

    public int getItemEnchantability()
    {
        return 1;
    }
}

 

it shows no errors in eclipse but when try to run

 

08:00:08] [Client thread/ERROR] [FML]: Caught exception from modmercenario
java.lang.NullPointerException
at net.minecraft.client.resources.model.ModelBakery.addVariantName(ModelBakery.java:835) ~[forgeSrc-1.8-11.14.1.1336.jar:?]
at mercenarymod.ClientProxy.init(ClientProxy.java:38) ~[bin/:?]
at mercenarymod.Mercenary.init(Mercenary.java:61) ~[bin/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_76]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_76]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_76]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_76]
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:518) ~[forgeSrc-1.8-11.14.1.1336.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_76]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_76]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_76]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_76]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[forgeSrc-1.8-11.14.1.1336.jar:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[forgeSrc-1.8-11.14.1.1336.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_76]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_76]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_76]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_76]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:692) [Loader.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:291) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:522) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:356) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_76]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_76]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_76]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_76]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:85) [start/:?]
at GradleStart.main(GradleStart.java:45) [start/:?]
[08:00:08] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:660]: ---- Minecraft Crash Report ----
// On the bright side, I bought you a teddy bear!

 

 

i need thath modelBakery  in CommonProxy to register the json's for the pulling animation but  lets remove it to later fix

 

now minecraft runs but there is no bow anywhere the register dont works i dunnot now why , an the modelBakery is an importan issue

coz eclipse says nothings wrong whith code i get mas i dont have any idea of whath coul be posibly wrong here

 

 

help please

 

 


 

 

Link to comment
Share on other sites

Don't put @Mod.EventHandler in any class except the main class - it does not belong in your proxies at all.

 

Your client proxy extends the common, so you need to call 'super.whateverMethod' from each of your methods, otherwise the stuff in common proxy never gets called, meaning that your Item was never initialized and thus the crash.

Link to comment
Share on other sites

good days 

 

alredy remove the notations "@Mod.EventHandler" in clienproxy and commondproxy and now i have some progress and some new questions

 

I set some systemouts to see whats working and now eclipse its ignoring the CommonProxy but is loading ClientProxy and CommonProxy is the one registering the items in to workaround i have to move the mercenaryModItems.init();  to the preInit() in the main class

 

whit this fix i get the items registered and now the bow works in eclipse

then compile it and put the jar in the server and this is odd very odd cos server is loading CommonProxy and do it whitout show any error

eclipse ignores commond proxy so i cant'n initialize mi items there,  but in minecraftServer it loads

 

anyway still having the same issue from long before, i have this item bow, it works in eclipse and if i put it in normal vainilla minecraft its works as well ,but when in a server it does nothing and sometimes desapear or become another item.

 

jumm so long the questions are,

 

-why is eclipse and vainilla minecraft ignoring this commond proxy  but server dont

-why this bow works in eclipse and vainilla minecraft but not in server

 

 

 

this is the source code https://drive.google.com/file/d/0B8sU_NyZQBd7Rk9VcXpLWWZTNXc/view?usp=sharing

 

this is the compiled mod https://drive.google.com/file/d/0B8sU_NyZQBd7ZmhNZThUZE9JSEU/view?usp=sharing

 

 

 

thi is log from server cmd

[08:43:27] [server thread/INFO] [sTDOUT]: [mercenarymod.CommonProxy:preInit:26]: ########


CommonProxy preInit()
08:43:27] [server thread/INFO] [FML]: Applying holder lookups
[08:43:27] [server thread/INFO] [FML]: Holder lookups applied
[08:43:27] [server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Loading properties
[08:43:27] [server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Default game type: SURVIVAL
[08:43:27] [server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Generating keypair
[08:43:27] [server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Starting Minecraft server on *:25565
[08:43:27] [server thread/WARN] [net.minecraft.server.dedicated.DedicatedServer]: **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!
[08:43:27] [server thread/WARN] [net.minecraft.server.dedicated.DedicatedServer]: The server will make no attempt to authenticate usernames. Beware.
[08:43:27] [server thread/WARN] [net.minecraft.server.dedicated.DedicatedServer]: While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.
[08:43:27] [server thread/WARN] [net.minecraft.server.dedicated.DedicatedServer]: To change this, set "online-mode" to "true" in the server.properties file.
[08:43:27] [server thread/INFO] [sTDOUT]: [mercenarymod.CommonProxy:init:40]: ########


CommonProxy init()
[08:43:27] [server thread/INFO] [sTDOUT]: [com.example.examplemod.ExampleMod:init:18]: DIRT BLOCK >> tile.dirt
[08:43:28] [server thread/INFO] [sTDOUT]: [mercenarymod.CommonProxy:postInit:53]: ########


CommonProxy postInit()

 

clean

CommonProxy

package mercenarymod;

import mercenarymod.blocks.MercenaryModBlocks;
import mercenarymod.items.MercenaryModItems;
import net.minecraft.item.Item;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class CommonProxy {

        // Client stuff
        public void registerRenderers() {
                // Nothing here as the server doesn't render graphics or entities!
        }
        
        //@Mod.EventHandler
        public void preInit() {
        System.out.println("########\n\n\n CommonProxy preInit()");	       	
        
        //MercenaryModItems.init();
        }
   
        //@Mod.EventHandler
        public void init() {
       	System.out.println("########\n\n\n CommonProxy init()");	
        }
     
        //@Mod.EventHandler
        public void postInit() {
        System.out.println("########\n\n\n CommonProxy postInit()");	   		
        }
        
}

 

 

clean

ClientProxy

package mercenarymod;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import mercenarymod.CommonProxy;
import mercenarymod.blocks.MercenaryModBlocks;
import mercenarymod.items.MercenaryModItems;

public class ClientProxy extends CommonProxy {
     
        //@Override
        public void registerRenderers() {
        // This is for rendering entities and so forth later on
        }
        
        public void preInit(){
        System.out.println("########\n\n\n ClientProxy preInit()");	
        }
     
        public void init() {
  	System.out.println("########\n\n\n ClientProxy init()");
        mercenarymod.MercenaryModTexturas.init();
        }
     
        public void postInit() {	
        System.out.println("########\n\n\n ClientProxy postInit()");
        }
}

 

Link to comment
Share on other sites

bueno

 

then this is the normal behavior

that whas the first thing i think,

but

in the greywolfs code he puts the items gameregistry and unlocalizated name in commonProxy, that dont work in mi code i dunot know why

 

then the mercenaryModitems.class  must be in the preinit from the main class to initializate all mi items this is the way i been seen it other codes

 

 

about the bow not working, this is just a scrap from all mi code i just get remove everything else, recipes, blocks, events, to make more easy the reason way this items fail, 

 

i have made a lot of items thath do something when rigth click, guns that shoot, chainsaw  , drills dinamite  but any of this items works when runing on a server

and now i I think the fault lies in the proxyes

 

in this case the bow must consume an arrow, thingten then release the arrow this is not happening when runing in the server but in eclipse or in minecraft normal game this works i have a video here to prove it

 

and this post is the begining of this threath 

http://www.minecraftforge.net/forum/index.php/topic,28397.0.html

 

and now then the question is the code i put on 7zip file this is the rigth way of using proxyes. ?

 

 

Link to comment
Share on other sites

good nigths

this afthernoon

i get epiphany in a hangover and realize mi troubles

 

the magic word Override when i do long time ago the first handgun i forget to override the onitemrigthclick from then i do all the rest items reusing  this code  changing only just things i need to change, and realize to the trouble whith nbttags returning null was just becoze some tags get written on local world

 

this is the new clean code i gonna use to redo all the rest 

this one its workin on the server 

 

package mercenarymod.items.arcos;

import mercenarymod.Mercenary;
import mercenarymod.items.MercenaryModItems;
import mercenarymod.utilidades.chat;
import mercenarymod.utilidades.nbtMercenaria;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.stats.StatList;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class arcoMercenario extends Item
{
    
    public arcoMercenario()
    {
    	String name = "arcoMercenario";
    	setUnlocalizedName(Mercenary.MODID + "_" + name);
    	GameRegistry.registerItem(this, name);
    	setCreativeTab(Mercenary.herramientas);
        this.maxStackSize = 1;
        this.setMaxDamage(1000);
        
    }

   
//####################################################################################3	    
@Override
public ModelResourceLocation getModel(ItemStack arco, EntityPlayer playerIn, int useRemaining){

int tick;
    if (useRemaining>970){tick=30-(useRemaining-970);}
    else {tick=30;}
    
    
	ModelResourceLocation modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario00", "inventory");	 

	int municion= getInttag(arco, "municion");

	if(municion < 0 | municion > 9998){intialize(arco,playerIn);}

	int texturajson=getInttag(arco, "texturajson");
	boolean shoot = getBooleantag(arco, "shoot");


    switch(texturajson){
    case   0:modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario00", "inventory") ;break;
	case   1:modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario01", "inventory") ;break;
	case   2:modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario02", "inventory") ;break;	
	case   3:modelresourcelocation = new ModelResourceLocation("modmercenario:arcos/arcomercenario/arcomercenario03", "inventory") ;break;
	    	            }

    if (shoot){
        	
    switch(tick){
    case 0:          setInttag(arco, "texturajson",0 );break;
    case 1:          setInttag(arco, "texturajson",1 );break;
    case 12:         setInttag(arco, "texturajson",2 );break;
    case 24:         setInttag(arco, "texturajson",3 );break;
       
                 }
    
        
    //System.out.println("useRemaining="+useRemaining+"\ntexturajson="+texturajson+"\n f="+getFloattag(arco, "strength")+" tick="+tick);
    //System.out.println("tick="+tick);
               }
     

	//setInttag(arco, "municion",10 );
   	return modelresourcelocation;
   	
		}



//#########################################################################3
@Override
public ItemStack onItemRightClick(ItemStack arco, World worldIn, EntityPlayer playerIn)
{

 //System.out.println(" On rigth click ");
 setBooleantag(arco, "shoot", true);
 playerIn.setItemInUse(arco, this.getMaxItemUseDuration(arco));

return arco; 
}

//####################################################################################3
@Override
public void onUsingTick(ItemStack arco, EntityPlayer player, int count)
{

}	 
@Override
public void onPlayerStoppedUsing(ItemStack arco, World worldIn, EntityPlayer playerIn, int timeLeft)
{
	int tick;
    if (timeLeft>970){tick=30-(timeLeft-970);}
    else {tick=30;}

 float f=((tick/30F)*3F);

  
 if (!worldIn.isRemote){

	    		 
    	playerIn.inventory.consumeInventoryItem(MercenaryModItems.flechaMercenaria);	
    		
    	EntityArrow entityarrow = new EntityArrow(worldIn, playerIn, f );	
    		
    	worldIn.spawnEntityInWorld(entityarrow);	
    	
    	//chat.chatdp(playerIn, "shooting force f="+f);
    		    	
    	setBooleantag(arco, "shoot", false);
    	
    	arco.damageItem(1, playerIn);//dañar con el uso
    	    	
    		
    	                       }
    	

}
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer playerIn)
{
      return stack;
}


public int getMaxItemUseDuration(ItemStack stack)
{
     return 1000;
}

@Override
public EnumAction getItemUseAction(ItemStack stack)
{

     return EnumAction.BOW;
}

//#########################################################################3 

public static void intialize(ItemStack arco, EntityPlayer playerIn){

//System.out.println("#\n#\n#\n Incializacion");

setInttag(arco, "texturajson", 0);
setInttag(arco, "municion", 0);
setBooleantag(arco, "reload", false);
setBooleantag(arco, "shoot", false);
setBooleantag(arco, "unload", false);
setFloattag(arco, "strength", 0.0F);


}

//#########################################################################3

public static int getInttag(ItemStack its, String tag){	

NBTTagCompound nsInt = new NBTTagCompound();

try {

	NBTTagCompound exi= its.getTagCompound();
	int ex=exi.getInteger(tag); 
	return ex;
  
} catch (Throwable any) {
 	return 9999;

}

}

//#########################################################################3

public static void setInttag(ItemStack its, String tag, int value){

try{
NBTTagCompound nsInt= its.getTagCompound();
nsInt.setInteger(tag, value);
its.setTagCompound(nsInt);

}catch(Throwable any) {

NBTTagCompound nsInt = new NBTTagCompound();
nsInt.setInteger(tag, value);	
its.setTagCompound(nsInt);	

}}
//#########################################################################3
public static float getFloattag(ItemStack its, String tag){	

NBTTagCompound nsInt = new NBTTagCompound();

try {

	NBTTagCompound exi= its.getTagCompound();
	float ex=exi.getFloat(tag); 
	return ex;
  
} catch (Throwable any) {
 	return 9999.00F;

}

}

//#########################################################################3

public static void setFloattag(ItemStack its, String tag, float value){

try{
NBTTagCompound nsInt= its.getTagCompound();
nsInt.setFloat(tag, value);
its.setTagCompound(nsInt);

}catch(Throwable any) {

NBTTagCompound nsInt = new NBTTagCompound();
nsInt.setFloat(tag, value);	
its.setTagCompound(nsInt);	

}}
//#########################################################################3

public static Boolean getBooleantag(ItemStack its, String tag){	

	NBTTagCompound nsInt = new NBTTagCompound();

	try {

		NBTTagCompound exi= its.getTagCompound();
		boolean ex=exi.getBoolean(tag);  
		return ex;
	  
 } catch (Throwable any) {
	 	return false;

 }

}

//#########################################################################3

public static void setBooleantag(ItemStack its, String tag, boolean value){

	try{
	NBTTagCompound nsInt= its.getTagCompound();
	nsInt.setBoolean(tag, value);
	its.setTagCompound(nsInt);

	}catch(Throwable any) {

	NBTTagCompound nsInt = new NBTTagCompound();
	nsInt.setBoolean(tag, value);	
	its.setTagCompound(nsInt);	

}}	



//#########################################################################3

public int getItemEnchantability()
{
    return 1;
}
    
//#########################################################################3	
    
    
}

 

there is still this little one misbehavior

when using the bow it begins to swing the bow , but is not like the swing of the pickaxe  this is more like,

let say i have a rawMutton on slot 0 of the hotbar and a block of wool in the second slot

and i change from slot 0 to slot 2 the rawMutton goes down and the block of wool cames up,

i think this is the behaviour of changin json files but dont understand why is happen to my items but is not hapening in the vainilla bow change texture

 

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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