Jump to content

Curly_dev

Members
  • Posts

    9
  • Joined

  • Last visited

Curly_dev's Achievements

Tree Puncher

Tree Puncher (2/8)

1

Reputation

  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);
  2. Will try and come back.
  3. 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?
  4. public static boolean canHaveAttributes(Entity entity) { if (entity instanceof EntityLivingBase) return true; return false; } Yes if i comment the MinecraftForge.EVENT_BUS.register(new ArmorHandler()); it goes quick.
  5. 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.
  6. 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.
  7. Perfect now it works. Now i understand. Regarding code style, where should i register if not in common Proxy? That's where most tutorials say to put it and didn't find anything else to help. Thank you.
  8. 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;
  9. 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.