Jump to content

Simontange

Members
  • Posts

    27
  • Joined

  • Last visited

Everything posted by Simontange

  1. Oh thank you i didn't found the source code of the shield , I will go looking at the code and the openGl tutorial and try to get this work ^^
  2. Okay thank you a lot for the help on my capabilities errors I learned a lot ?
  3. Okay thank you but I never made rendering yet do you know a good tutorial or something like forgedocs i found pretty nothing ?
  4. Hello I am making a mod and I want to render something when for exemple the player press a key, something like an aura like this : But I didn't found something to render this around the player on an event the only mod i found that make something same is Matter overdrive with the personal shield ability, it looks like this : Thank you to reading this I hope someone know how to do this or at least what I must look at and excuse me for this bad english ^^
  5. oh yeah it worked thank you. if I want to send a message to the server and to obtain a awnser to my packet sould I make another message class and handler or exists a easy way to do this ?
  6. I have an null point exeption I don't understand why I think it is a registering thing but I made like the explained in ForgeDocds here my code : message handler for sending from server to client the error points capNenClient.setNen(capa.getNen()); it worked before but now not... public class ImessageNenHandler implements IMessageHandler<ImessageNen, IMessage> { @Override public IMessage onMessage(ImessageNen message, MessageContext ctx) { IThreadListener thread = MainHunterXHunter.proxy.getListener(ctx); final EntityPlayer player = MainHunterXHunter.proxy.getPlayerEntityFromContext(ctx); PlayerNen capa = message.getValue(); thread.addScheduledTask(new Runnable() { @Override public void run() { if(player!=null){ PlayerNen capNenClient = player.getCapability(PlayerProp.Player_Nen,null); if(capa!=null && capNenClient!=null){ System.out.println("on message verif"); capNenClient.setNen(capa.getNen()); } } } }); return null; } } message class : public class ImessageNen implements IMessage { private PlayerNen value ; public ImessageNen() {} public ImessageNen(PlayerNen value) { this.value = value; } @Override public void fromBytes(ByteBuf buf) { int [] tmp ={buf.readInt(),buf.readInt()}; this.value.setNen(tmp); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.value.getNen()[0]); buf.writeInt(this.value.getNen()[1]); } public PlayerNen getValue() { return value; } public void setValue(PlayerNen value) { this.value = value; } } the main class : @Mod(modid = MainHunterXHunter.modId,name = MainHunterXHunter.name, version = MainHunterXHunter.version, acceptedMinecraftVersions = "1.12.2") public class MainHunterXHunter { @SidedProxy(serverSide = "com.hunterxhunter.proxy.ServerProxy", clientSide = "com.hunterxhunter.proxy.ClientProxy") public static IProxy proxy; public static SimpleNetworkWrapper NETWORK =NetworkRegistry.INSTANCE.newSimpleChannel(MainHunterXHunter.modId); public static final String modId = "hunterxhuntermod"; public static final String name = "Hunter X Hunter Mod"; public static final String version = "1.0"; public static final HxhTab maTab = new HxhTab(); @Mod.Instance(modId) public static MainHunterXHunter instance; @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); System.out.println(name + " is loading!"); MinecraftForge.EVENT_BUS.register(PlayerPropEvent.instance); CapabilityManager.INSTANCE.register(PlayerNen.class, new NenStorage() /*Capability.IStorage<PlayerNen>()*/{ @Nullable @Override public NBTBase writeNBT(Capability<PlayerNen> capability, PlayerNen instance, EnumFacing side) { throw new UnsupportedOperationException(); } @Override public void readNBT(Capability<PlayerNen> capability, PlayerNen instance, EnumFacing side, NBTBase nbt) { throw new UnsupportedOperationException(); } }, ()-> null); //NETWORKSERVER = NetworkRegistry.INSTANCE.newSimpleChannel(MainHunterXHunter.modId+"server"); NETWORK.registerMessage(ImessageNenHandler.class, ImessageNen.class, 0, Side.CLIENT); //NETWORK.registerMessage(ImessHandleChanges.class, ImessageNenChanges.class, 2, Side.SERVER); } @Mod.EventHandler public void init(FMLInitializationEvent event) { proxy.init(event); } @Mod.EventHandler public void postInit(FMLPostInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new NenOverlay()); MinecraftForge.EVENT_BUS.register(new NenOverlayString()); proxy.postInit(event); } @Mod.EventBusSubscriber public static class RegistrationHandler { @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { ModItems.register(event.getRegistry()); } @SubscribeEvent public static void registerItems(ModelRegistryEvent event) { ModItems.registerModels(); } } } the message to send from client to server public class ImessageNenChanges implements IMessage { private int value ; public ImessageNenChanges(int value) { this.value = value; } public ImessageNenChanges() {} @Override public void fromBytes(ByteBuf buf) { this.value=buf.readInt(); } public int getValue() { return value; } public void setValue(int value) { this.value = value; } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.value); } } handler for message from client to server public class ImessHandleChanges implements IMessageHandler <ImessageNenChanges, IMessage> { @Override public IMessage onMessage(ImessageNenChanges message, MessageContext ctx) { IThreadListener thread = MainHunterXHunter.proxy.getListener(ctx); final EntityPlayer player = MainHunterXHunter.proxy.getPlayerEntityFromContext(ctx); PlayerNen playerNen = PlayerProp.getPlayerNen(player); int perCent = message.getValue(); thread.addScheduledTask(new Runnable() { @Override public void run() { int[]tmp={0,playerNen.getNen()[1]}; if(playerNen!=null&&perCent>=0){ if(perCent<=100) { tmp[0] = (playerNen.getNen()[0] - (int) (playerNen.getNen()[1] * (perCent / 100))); }else{ tmp[0] = (playerNen.getNen()[0] + (int) (playerNen.getNen()[1] * (perCent / 100))); } if(tmp[0]>playerNen.getNen()[1]){ tmp[0]=playerNen.getNen()[1]; }else if(tmp[0]<0){ tmp[0]=0; } playerNen.setNen(tmp); } } }); return null; } }
  7. Oh I missunderstood the simplelmpl tutorial on forgedocs It is juste the last parametre on the registering line that we must change but I must register it on both, thank you.
  8. Oh yeah I forgot to delete this, I had a NullPointerExeption error and was looking if It was the empty contructor the problem but it wasen't. So I must create a new message and in the messageHandler do What I want to the capability ? And I must register the message and the SimpleNetworkWrapper on serverSide beacause I am sending from client to server but Forge Don't fire the preInit On the serverside
  9. And here my ServerProxy class public class implements public static NETWORKSERVER; @Override public void preInitout"register network server =====================================================88888888"; NETWORKSERVER INSTANCEmodId+"server"; NETWORKSERVERclass, class, , SERVER;
  10. Now I want to change my nen by pressing a key but the keypressed event is a client side event so I must send a custom packet to the server, I use the same class as the one I use to send packets from the server to the client but it don't work what I am doing wrong ? public class ImessageNen implements IMessage { private PlayerNen value ; public ImessageNen() { value = new PlayerNen(); } public ImessageNen(PlayerNen value) { this.value = value; } @Override public void fromBytes(ByteBuf buf) { int [] tmp ={buf.readInt(),buf.readInt()}; this.value.setNen(tmp); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.value.getNen()[0]); buf.writeInt(this.value.getNen()[1]); } public PlayerNen getValue() { return value; } public void setValue(PlayerNen value) { this.value = value; } } public class ImessageNenHandler implements IMessageHandler<ImessageNen, IMessage> { @Override public IMessage onMessage(ImessageNen message, MessageContext ctx) { IThreadListener thread = MainHunterXHunter.proxy.getListener(ctx); final EntityPlayer player = MainHunterXHunter.proxy.getPlayerEntityFromContext(ctx); PlayerNen capa = message.getValue(); thread.addScheduledTask(new Runnable() { @Override public void run() { if(player!=null){ PlayerNen capNenClient = player.getCapability(PlayerProp.Player_Nen,null); if(capa!=null && capNenClient!=null){ System.out.println("on message verif"); capNenClient.setNen(capa.getNen()); } } } }); return null; } } this is the method I call when the key is pressed(by the way I changes the double nen by an int array and nen is [0] and nenMax[1]) : public static boolean changePerCentNen (PlayerNen playerNen, EntityPlayer player, int perCent){ int[]tmp={0,playerNen.getNen()[1]}; boolean hasEnough = true; if(playerNen!=null&&perCent>=0){ if(perCent<=100) { tmp[0] = (playerNen.getNen()[0] - (int) (playerNen.getNen()[1] * (perCent / 100))); }else{ tmp[0] = (playerNen.getNen()[0] + (int) (playerNen.getNen()[1] * (perCent / 100))); } if(tmp[0]>playerNen.getNen()[1]){ tmp[0]=playerNen.getNen()[1]; }else if(tmp[0]<0){ tmp[0]=0; hasEnough = false; } playerNen.setNen(tmp); } if(player!=null) { PlayerNen nen = player.getCapability(PlayerProp.Player_Nen, null); if (nen != null) { ImessageNen mess =new ImessageNen(nen); if(mess!=null) { NETWORKSERVER.sendToServer(mess); System.out.println("set percent nen message "); } } } return hasEnough; }
  11. Yeah It was fixed by the respawn event here are my events : public class PlayerPropEvent { public static PlayerPropEvent instance = new PlayerPropEvent(); @SubscribeEvent public void onEntityContstructing (AttachCapabilitiesEvent<net.minecraft.entity.Entity> event){ if (event.getObject() instanceof EntityPlayer){ if (!event.getObject().hasCapability(PlayerProp.Player_Nen,null)){ System.out.println("verify attatch "); event.addCapability(new ResourceLocation(MainHunterXHunter.modId,"nen"),new PropDispatcher()); } } } @SubscribeEvent public void onPlayerCloned(PlayerEvent.Clone event){ System.out.println("clone"); if(event.isWasDeath()){ if(event.getOriginal().hasCapability(PlayerProp.Player_Nen,null)){ PlayerNen old = event.getOriginal().getCapability(PlayerProp.Player_Nen,null); PlayerNen newstore = PlayerProp.getPlayerNen(event.getEntityPlayer()); newstore.copyNen(old); System.out.println("clone done"); System.out.println("old :"+old); System.out.println("new :"+newstore); } } } @SubscribeEvent public void onPlayerRespawn(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent event){ EntityPlayer player = event.player; if(player!=null) { PlayerNen nen = player.getCapability(PlayerProp.Player_Nen, null); if (nen != null) { ImessageNen mess =new ImessageNen(nen); if(mess!=null) { NETWORK.sendTo(mess, (EntityPlayerMP) player); System.out.println("respawn message et nen = "+ nen); } } } } public int tick=0; @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event){ EntityPlayer player = event.player ; PlayerNen nen = PlayerProp.getPlayerNen(player); if (event.phase == TickEvent.Phase.START){ tick +=1; if(tick ==20) { if (nen.getNen()[0] < nen.getNen()[1]) { System.out.println("incrementation"); int tmp []={0,0}; tmp[0]=nen.getNen()[0]+1; tmp[1]=nen.getNen()[1]; nen.setNen(tmp); tick=0; } } } } @SubscribeEvent public void onPlayerLoggIn (net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event){ EntityPlayer player = event.player; if(player!=null) { PlayerNen nen = player.getCapability(PlayerProp.Player_Nen, null); System.out.println("debug"); if (nen != null) { ImessageNen mess =new ImessageNen(nen); if(mess!=null) { NETWORK.sendTo(mess, (EntityPlayerMP) player); } } } }
  12. Yes I made this (not for the dimension but I will do it when the death works)
  13. I get it to work the only issue is that when the player dyes the overlay say it has 0 nen but I know in the capability is is 25 and when I quit minecraft and restart the world it goes back to 25 I think it is a problem with the registering beacause I must restart the game what can I do ?
  14. Soooo I think it is beacause in my overlay it takes the client side of the player and the capability is on the server side I go try to make an custom packet handler
  15. I works I don't know why but now it works fine the problem is in the NenOverlay because I looked the value saved and loaded from NBTload and save and it is good it keeps it trouth the sessions
  16. So I made a buch of println to see when forge use what and the issue is that on logging in in the world serializeNBT set the Nen at 20 back even when the game savec my nen the session before
  17. Or am I getting the value the wrong way In my NenOverlay class ? public class NenOverlay extends Gui { private final ResourceLocation bar = new ResourceLocation(MainHunterXHunter.modId, "textures/barre.png"); @SubscribeEvent public void renderOverlay (RenderGameOverlayEvent.Pre event ){ Minecraft mc = Minecraft.getMinecraft(); EntityPlayer player = mc.player ; PlayerNen nen = PlayerProp.getPlayerNen(player); final int externalBarH = 20, externalBarL = 108, internalBarH = 14, internalBarL = 102; double tmp=0; int lenthBar =0; if (event.getType()== RenderGameOverlayEvent.ElementType.TEXT){ mc.renderEngine.bindTexture(bar); tmp = internalBarL/250.0; lenthBar = (int)(tmp*nen.getNen()); drawTexturedModalRect(5,5,0,0,externalBarL,externalBarH); drawTexturedModalRect(8,8,3,20,lenthBar,internalBarH); }
  18. Because when I go back to title screen and after in the world it don't save my data, on the death I now I must use the event clone player but It is the same for logging ?
  19. Yeah so I need Compound because I store A value withe a key to call it Oh yes I forgot a word ^^ where should I call these funcions
  20. There is a lot of subClasses but I was thinking NBTTags are juste like keys to find the value forge is seeking at is'nt that ? And where should I these functions ? @Override public NBTTagCompound serializeNBT() { NBTTagCompound nbt = new NBTTagCompound(); playerNen.saveNBTData(nbt); return nbt; } @Override public void deserializeNBT(NBTTagCompound nbt) { playerNen.loadNBTData(nbt); }
  21. Okay thank you. now I have an other issue I want it to save it when i log out and load it when i log in i think i must use the NBT write and read in a PlayerLoggedInEvent but I can't use the method without NBTtagCompound where can I get it ?
  22. I don't know the name in english, in java it is like : int tab [] = new int[10];
  23. thank you so much it works fine now, I have another question if I want to store a table of variables can I do like this ?
  24. Okay thank you this will optimise my code. So if I understand your thread I sould delete my common proxy and make a serverproxy and put my code inside my mod class ?
  25. What is the event Pre ? and why it is better, my class Overlay works fine when i test it with the life bar and it works fine. public class CommonProxy { @Mod.EventHandler public void preInit (FMLPreInitializationEvent event ){ MinecraftForge.EVENT_BUS.register(PlayerPropEvent.instance); CapabilityManager.INSTANCE.register(PlayerNen.class, new Capability.IStorage<PlayerNen>(){ @Nullable @Override public NBTBase writeNBT(Capability<PlayerNen> capability, PlayerNen instance, EnumFacing side) { throw new UnsupportedOperationException(); } @Override public void readNBT(Capability<PlayerNen> capability, PlayerNen instance, EnumFacing side, NBTBase nbt) { throw new UnsupportedOperationException(); } }, ()-> null); } this is my preInit on commonproxy I don't have git and it seems complicaded to use I never used it sorry
×
×
  • Create New...

Important Information

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