Jump to content

robertx555

Members
  • Posts

    25
  • Joined

  • Last visited

Posts posted by robertx555

  1. What is the purpose of this capability?

     

    Unless I understood you wrong, you just need other mods to tell you what elements their mobs are. This can be done with datapacks.

     

    You load all the datapacks into a Hashmap<String,ElementData> where string is the mod id. And when you want to know mob's resistances, you just check that map.

     

    Entity Capabilities are for saving mob specific data, a hashmap works fine if that data is set at startup and same for each mob type.

     

  2. Is this mod released somewhere? If so that's against my permission as i reserved all rights. I only allowed private use of modified code.

     

    Also the 1.12.2 version has a crapton of my spaghetti code which is mostly ironed out in 1.14.4 as i spent months reworking most things. Yes, months to rework things, so i don't suggest you try fix.

     

    Also sorry sieben for the problems.

     

     

     

  3. I know that at least. Btw managed to gitignore build and eclipse folders so here's the new one 

     

    https://github.com/RobertSkalko/MMORPG-Mod

     

    Now i'm gonna see if i can use capabilities to save NBTTagCompound, i have like 20 stats so having 20 getter and setter functions seem like a disaster.  Anyway it's nearly midnight so i'll do it tomorrow 

     

    Thanks for the help! I won't need help anymore soon, got a lot of things to work on now! 

  4. i know but things are easier to balance if i only care about 1 player.. for example say i want to spawn random mobs around a player. It becomes more difficult to balance when multiple players are around. 1 player is lvl 100 the other is lvl 1, i would have to make it so both players can play somehow.. which would mean many changes

     

    didn't learn that yet, i'll try gitignore, kept hearing about it but now i see why it's useful

     

     

  5. Whoa i think i solved it! Thanks!

     

    @SubscribeEvent
    	public  void onTickCalcStats(TickEvent.PlayerTickEvent event) { 
    		
    		
    		if (event.phase == Phase.END ) {
    			
    			tick++;
    		
    		if (tick > 100 && event.player != null && event.side.isServer()) {			
    			
    			MAIN.player = event.player;
    			
    			EntityPlayer player = event.player;
    						
    			getStats();
    			
    			if (player.hasCapability(Entity_Data.Data, null)) {
    			
    			DataInterface data = player.getCapability(Entity_Data.Data, null);			
    			
    			data.setLevel(data.getLevel() +1);			
    					
    			player.sendMessage( new TextComponentString(data.getLevel()+ " "));
    									
    			}
    			IAttributeInstance health = player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH);
    		    health.setBaseValue(20);	
    		    
    			tick = 0;
    		}
    		}
    	}
    	

     

    You said i'm supposed to get player from event.. well servertickevent has no player but TickEvent.PlayerTickEvent does! I changed it and it suddenly magically worked! It saves on death and on quitting game! That answered another question, seems i don't have to call any other saving methods

     

    I'm gonna go and remove MAIN.player and update all the stuff.. xD

  6. 26 minutes ago, diesieben07 said:
    • That is the client player. The client does not save any data. If you want to modify the data, you must do it on the server. The fact that you are accessing this from the server thread only makes things worse, since you are now reaching across logical sides, which causes even more issues.
    • You can't just store a static reference to the player like that. The player object will change when you switch worlds, etc. Just use Minecraft::player directly if you need the client player.

    How would i set the player data on the server? 

     

    btw i uploaded to github in case it helps 

    https://github.com/RobertSkalko/Minecraft-Forge-Singleplayer-MMORPG-like-mod

  7. 2 minutes ago, diesieben07 said:
    • Don't subscribe to the bare AttachCapabilitiesEvent. In this case you want AttachCapabilitiesEvent<Entity> and check that the entity is a player.
    • Where is the data value read/written outside the nbt serialization? Which behavior makes you think it is not persisted?

     

    I made a small test for it in servertickevent

     

    if (MAIN.player.hasCapability(Entity_Data.Data, null)) {
    			
    			DataInterface data = MAIN.player.getCapability(Entity_Data.Data, null);			
    			
    			data.setLevel(data.getLevel() +1);			
    					
    			MAIN.player.sendMessage( new TextComponentString(data.getLevel()+ " "));

     

    Basically an increment every few ticks. I keep seeing increasing numbers.. until i leave game or die. It goes like 1,2,3,4 "i die" 1, 2 ,3 you get the idea. So either i have to save the data somehow or i messed something up with the compatibility

     

  8. Took me a while to get a working capability but now i don't see how i'm supposed to save them to disk. Here is my capability file, it's all registered and it works, just doesn't save 

     

    
    public class Entity_Data
    {   
           
        @CapabilityInject(DataInterface.class)
        public static final Capability<DataInterface> Data = null;
    
        public interface DataInterface {   
        	
            void setLevel(int value);
            int getLevel();
            
        }
    
        
        public static class EventHandler
        {
            @SubscribeEvent
            public void onEntityConstruct(AttachCapabilitiesEvent evt) 
            {
                evt.addCapability(new ResourceLocation(Ref.MODID, "Data"), new ICapabilitySerializable<NBTTagCompound>()
                {
                    DataInterface inst = Data.getDefaultInstance();
                                    
                    
                    @Override
                    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                        return capability == Data;
                    }
    
                    @Override
                    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                        return capability == Data ? Data.<T>cast(inst) : null;
                    }
                    
                    @Override
                    public NBTTagCompound serializeNBT() {             	               	
                        return (NBTTagCompound)Data.getStorage().writeNBT(Data, inst, null);
                    }
    
                    @Override
                    public void deserializeNBT(NBTTagCompound nbt) {
                        Data.getStorage().readNBT(Data, inst, null, nbt);
                    }
                    
                    
                    
                });
            }	
    
    	
    
           
        }
    
        
        public static class Storage implements IStorage<DataInterface>
        {
            @Override
            public NBTBase writeNBT(Capability<DataInterface> capability, DataInterface instance, EnumFacing side)
            {        	  	
            	NBTTagCompound nbt = new NBTTagCompound();
            	
            	nbt.setInteger("level", instance.getLevel());
            	
                return nbt;
            }
    
            @Override
            public void readNBT(Capability<DataInterface> capability, DataInterface instance, EnumFacing side, NBTBase nbt)
            {
            	
            	NBTTagCompound tag = (NBTTagCompound) nbt;
            	
            	instance.setLevel(tag.getInteger("level"));
            	
            	
            }
        }
    
        public static class DefaultImpl implements DataInterface
        {
            private int level = 1;
            @Override public int getLevel() { return level; }
            @Override public void setLevel(int value) { this.level = value; }
                          
            
        }

     

    Also i followed a tutorial on how to make player data persist through death but it doesn't work even though the chat message is sent as a confirmation the code ran

     

    
    	@SubscribeEvent		
    	public void onPlayerClone(PlayerEvent.Clone event){
    		
    		if (!event.getEntityPlayer().world.isRemote) {
    		
    		 event.getEntityPlayer().sendMessage(new TextComponentString("clone"));
    			
    		 EntityPlayer player = event.getEntityPlayer();
    		
    		 DataInterface data = player.getCapability(Entity_Data.Data, null);	
    		 		
    		 DataInterface oldData = event.getOriginal().getCapability(Entity_Data.Data, null);
    		
    		 
    		 data.setLevel(oldData.getLevel());
    		 
    		}
    	 
    	}

     

    Thanks for any help!

  9. Can close the thread, i read some other thread here 

     

    the suggestion to  open type hierarchy made me realize LivingDamageEvent event exists and that i can change the amount there with setamount!

     

    There is a class called ForgeHooks that contains all the events 

  10. I found 2 ways of doing this but they both seem the wrong way. I made my own stat system with nbt on items and if player has a total of say 50 dmg, i want the weapon to do 50 dmg. Here are the 2 ways i did this that i think are wrong

     

    firstly i tried just setting mob health but that has issues, the mobs don't drop any items then. 

     

    secondly, i tried using the attackentityfrom method and making it unique so i can identify it and not make an infinite loop, but this looks like a disaster in the making

     

    		if (event.getSource().isDamageAbsolute())return;		
    
    		event.getEntityLiving().attackEntityFrom(event.getSource().setDamageIsAbsolute(), combinedDMG);
    		
    		event.setCanceled(true);

     

    Am i missing the true way of doing this? And no i can't just change the dmg of items, there is crit chance, lifesteal etc to calculate too. 

     

    EDIT I THINK I FIGURED IT OUT, sec

  11. Thanks, i figured out how to do it! I don't think i have the best possible way but it works!

     

    First you add the tags

     

    NBTTagCompound com = new NBTTagCompound();

     

    com.setString("stats", "example stat");


    item.setTagCompound(com);

     

    then you display them

     


        @SubscribeEvent
        public void onTooltip(ItemTooltipEvent event) {


            ItemStack item = event.getItemStack();


        if (item.getTagCompound()!= null) {
                if (item.getTagCompound().hasKey("stats")) {
                    event.getToolTip().add(stats);        

    }

    }

     

    I got stuck because there wasn't setTooltip() method, i had to gettooltip() and then add().. You can also remove some of the tags from showing this way but attack speed and armor seems to stay lol

     

     

     

  12. 1 minute ago, Draco18s said:

    Not everything Bukkit does has a Forge equivalent and vice versa.

    You can add other tags and write your code to handle interpreting what they do, but each one will need separate code and possible their own event hooks.

    That is: making a critical damage stat and applying it to weapons and hooking into the right events, sure, its doable. It's just not two lines of code.

     

    Yeah i'm prepared to write code for many days.. but first i need to figure out how to add lore to items. I think i'm close to the answer, seems to be NBTTagList. I'll just fiddle with it until i figure it out 

  13. 20 minutes ago, Draco18s said:

    Lore doesn't actually make the item any different. It's just text displayed in a tooltip.

    You can modify the text displayed by subscribing to the ItemTooltipEvent, but adding "Crit chance: 5%"  won't actually make the item have a 5% crit chance.

    For actual effects, some of them can be handled via AttributeModifiers which can be applied via NBT tags on item stacks. But this is a very limited set of effects (namely, attack damage and attack speed).

    I know, i can make my own stat and dmg system that makes use of that text on items.

     

    Hm, itemtooltipevent? Can't i first give the item lore and then make it drop from a mob? The attributes are too limiting. 

     

    I already made the stat system for a bukkit server so i know it's possible, i just have to figure out the differences with forge modding 

  14. 7 minutes ago, Draco18s said:

    Are you...

    Adding lore to your own item?

    Or...

    Adding lore to a vanilla item?

     

    How you do this depends on the answer.

    i want to use vanilla items, a wooden sword for example, and be able to create infinite amounts of different items by changing the sword's lore. 

     

    like

    wooden sword: critical chance 5%

    wooden sword: critical damage 20%

  15. Hello, i'm trying to make a mod that makes some things easier on a server i play with, so the mod has to be 100% client side.

     

    My problem is i don't know which events are client side.

     

    I see 2 events which might be useful EntityItemPickupEven and PlayerEvent.ItemPickupEvent

     

    But i tried both and tried setting them to either event.setcanceled(true) or event.setresult(result.deny) and neither seem to stop my character from picking up items..

     

    So, yeah i'd just like to know how to stop myself from picking up items client side and if possible to know how i know which event is client side. Thanks for any help!

×
×
  • Create New...

Important Information

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