Jump to content

Curly_dev

Members
  • Posts

    9
  • Joined

  • Last visited

Posts posted by Curly_dev

  1. For whoever is struggling with this like i did:

     

    private static final UUID setSpeedUUID = UUID.fromString("015ad548-47e6-11e8-842f-0ed5f89f718b");
    
    double speed = 0.1D;
    
    int operations = 0; (explained below in quote)
    
    String name = 'anything here';
    IAttributeInstance movement = player.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); //Player is EntityPlayerMP or EntityPlayer
    
    AttributeModifier setSpeedBonus = new AttributeModifier(setSpeedUUID, name, Math.abs(speed), operations);     
    if(movement.getModifier(setSpeedUUID) != null) {					
      movement.removeAllModifiers();
    }
    movement.applyModifier(setSpeedBonus);

     
     

    Quote

     

    A modifier's operation dictates how it modifies an attribute's base value. Three operations exist:

    Operation 0: Additive. Adds all of the modifiers' amounts to the current value of the attribute. For example, modifying an attribute with {Amount:2,Operation:0} and {Amount:4,Operation:0} with a Base of 3 results in 9 (3 + 2 + 4 = 9).

    Operation 1: Multiplicative. Multiplies the current value of the attribute by (1 + x), where x is the sum of the modifiers' amounts. For example, modifying an attribute with {Amount:2,Operation:1} and {Amount:4,Operation:1} with a Base of 3 results in 21 (3 * (1 + 2 + 4) = 21).

    Operation 2: Multiplicative. For every modifier, multiplies the current value of the attribute by (1 + x), where x is the amount of the particular modifier. Functions the same as Operation 1 if there is only a single modifier with operation 1 or 2. However, for multiple modifiers it will multiply the modifiers rather than adding them. For example, modifying an attribute with {Amount:2,Operation:2} and {Amount:4,Operation:2} with a Base of 3 results in 45 (3 * (1 + 2) * (1 + 4) = 45).[3]

    The mathematical behavior is as follows: Operation 0: Increment X by Amount, Operation 1: Increment Y by X * Amount, Operation 2: Y = Y * (1 + Amount) (equivalent to Increment Y by Y * Amount). The game first sets X = Base, then executes all Operation 0 modifiers, then sets Y = X, then executes all Operation 1 modifiers, and finally executes all Operation 2 modifiers.

     

           

    • Like 1
  2. I tried the usual:
     

    player.capabilities.setPlayerWalkSpeed(speed);


    No method for setPlayerWalkSpeed, and it's correct it doesn't have because is a EntityPlayerMP.
    There is any way to change speed while being on server side? The topic is kinda scarce.

    I tried:

    PlayerCapabilities cap = ObfuscationReflectionHelper.getPrivateValue(EntityPlayer.class, player, "capabilities", "field_71075_bZ");
    player.capabilities.setPlayerWalkSpeed(speed);
    
    ObfuscationReflectionHelper.setPrivateValue(PlayerCapabilities.class, cap, speed,"walkSpeed", "field_73357_f");

     

    It works as intended but the private field name changes from version to version and i would like something more maintanable(someone with forge 1.10 and i had 1.12 and the field name was the only problem).

    What are my choices?

  3. From an instant spawning it now looks like this:
    [19:57:06] [Server thread/INFO]: Preparing spawn area: 0%
    [19:57:07] [Server thread/INFO]: Preparing spawn area: 1%
    [19:57:08] [Server thread/INFO]: Preparing spawn area: 3%
    [19:57:09] [Server thread/INFO]: Preparing spawn area: 5%
    [19:57:10] [Server thread/INFO]: Preparing spawn area: 7%

    For 2 minutes.

    The idea was that i wanted some custom data for players... It works as intended once it loads. But it takes way too much.

  4. And another thing:
     

         public void attachCapability(AttachCapabilitiesEvent<Entity> event) {
            if (canHaveAttributes(event.getObject()))
            {
                EntityLivingBase ent = (EntityLivingBase)event.getObject();
        
                if (ent instanceof EntityPlayerMP)
                    event.addCapability(Armor, new ArmorProvider());
            }
         }


    There is any way better to put capabilities just on players? Because now it goes through all entities... and it takes a while.

  5. public class CommonProxy implements IProxy {
        
        public void preInit() {
            
        }
    
        public void init() {
            
        }
    
        public void postInit() {
            CapabilityManager.INSTANCE.register(Armor.class, new ArmorStorage(), Armor.class);
            MinecraftForge.EVENT_BUS.register(new EventEquipmentSets());
            MinecraftForge.EVENT_BUS.register(new ArmorHandler());
            
        }



    And the null is the Armor, because of
     

    public static final Capability<IArmor> Armor = null;
  6. public class ArmorProvider implements ICapabilitySerializable<NBTBase> {
    
         @CapabilityInject(IArmor.class)
    
         public static final Capability<IArmor> Armor = null;
    
        
         private IArmor instance = Armor.getDefaultInstance();
    
        
         @Override
         public boolean hasCapability(Capability<?> capability, EnumFacing facing)
         {
    
             return capability == Armor;
    
         }
    
        
         @Override
         public <T> T getCapability(Capability<T> capability, EnumFacing facing)
         {
    
             return capability == Armor ? Armor.<T> cast(this.instance) : null;
         }
    
        
         @Override
         public NBTBase serializeNBT()
         {
    
             return Armor.getStorage().writeNBT(Armor, this.instance, null);
    
         }
    
        
         @Override
         public void deserializeNBT(NBTBase nbt)
         {
    
             Armor.getStorage().readNBT(Armor, this.instance, null, nbt);
    
         }
    }


    It breaks at:

     private IArmor instance = Armor.getDefaultInstance();


    Because ... well it's null.

    But here:

    https://www.planetminecraft.com/blog/forge-tutorial-capability-system/
     

    And in other places it says this is how it supposed to be.


    http://mcforge.readthedocs.io/en/latest/datastorage/capabilities/#the-capability-system
     

    This doesn't offer any documentation if you make a custom one. It doesn't even say you need to subscribe an event to be able to do it...

    There is any good examples like really good working example or documentation on Capabilities?

×
×
  • Create New...

Important Information

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