|
47 | 47 | import net.minecraft.world.item.component.ItemLore; |
48 | 48 | import net.minecraft.world.item.component.UseCooldown; |
49 | 49 | import net.minecraft.world.item.component.UseRemainder; |
| 50 | +import net.minecraft.world.item.component.Weapon; |
50 | 51 | import net.minecraft.world.item.consume_effects.ConsumeEffect; |
51 | 52 | import org.checkerframework.checker.nullness.qual.Nullable; |
52 | 53 | import org.spongepowered.api.Platform; |
|
65 | 66 | import org.spongepowered.common.adventure.SpongeAdventure; |
66 | 67 | import org.spongepowered.common.data.provider.DataProviderRegistrator; |
67 | 68 | import org.spongepowered.common.item.util.ItemStackUtil; |
| 69 | +import org.spongepowered.common.util.Constants; |
68 | 70 |
|
69 | 71 | import java.util.List; |
70 | 72 | import java.util.Optional; |
@@ -370,6 +372,57 @@ public static void register(final DataProviderRegistrator registrator) { |
370 | 372 | .get(h -> (ResourceKey) (Object) h.get(DataComponents.TOOLTIP_STYLE)) |
371 | 373 | .set((h, v) -> h.set(DataComponents.TOOLTIP_STYLE, (ResourceLocation) (Object) v)) |
372 | 374 | .delete(h -> h.remove(DataComponents.TOOLTIP_STYLE)) |
| 375 | + .create(Keys.WEAPON_DAMAGE_PER_ATTACK) |
| 376 | + .get(h -> { |
| 377 | + final @Nullable Weapon weapon = h.get(DataComponents.WEAPON); |
| 378 | + if (weapon == null) { |
| 379 | + return null; |
| 380 | + } |
| 381 | + return weapon.itemDamagePerAttack(); |
| 382 | + }) |
| 383 | + .set((h, v) -> { |
| 384 | + final @Nullable Weapon weapon = h.get(DataComponents.WEAPON); |
| 385 | + h.set(DataComponents.WEAPON, new Weapon(v, weapon == null ? 0 : weapon.disableBlockingForSeconds())); |
| 386 | + }) |
| 387 | + .delete(h -> { |
| 388 | + final @Nullable Weapon weapon = h.get(DataComponents.WEAPON); |
| 389 | + if (weapon == null) { |
| 390 | + return; |
| 391 | + } |
| 392 | + if (weapon.disableBlockingForSeconds() == 0) { |
| 393 | + h.remove(DataComponents.WEAPON); |
| 394 | + } else { |
| 395 | + h.set(DataComponents.WEAPON, new Weapon(0, weapon.disableBlockingForSeconds())); |
| 396 | + } |
| 397 | + }) |
| 398 | + .create(Keys.DISABLE_SHIELD_TICKS) |
| 399 | + .get(h -> { |
| 400 | + final @Nullable Weapon weapon = h.get(DataComponents.WEAPON); |
| 401 | + if (weapon == null) { |
| 402 | + return null; |
| 403 | + } |
| 404 | + return Ticks.of(Math.round( |
| 405 | + Constants.TickConversions.TICKS_PER_SECOND * weapon.disableBlockingForSeconds() |
| 406 | + )); |
| 407 | + }) |
| 408 | + .set((h, v) -> { |
| 409 | + final @Nullable Weapon weapon = h.get(DataComponents.WEAPON); |
| 410 | + h.set(DataComponents.WEAPON, new Weapon( |
| 411 | + weapon == null ? 0 : weapon.itemDamagePerAttack(), |
| 412 | + v.ticks() / (float) Constants.TickConversions.TICKS_PER_SECOND |
| 413 | + )); |
| 414 | + }) |
| 415 | + .delete(h -> { |
| 416 | + final @Nullable Weapon weapon = h.get(DataComponents.WEAPON); |
| 417 | + if (weapon == null) { |
| 418 | + return; |
| 419 | + } |
| 420 | + if (weapon.itemDamagePerAttack() == 0) { |
| 421 | + h.remove(DataComponents.WEAPON); |
| 422 | + } else { |
| 423 | + h.set(DataComponents.WEAPON, new Weapon(weapon.itemDamagePerAttack())); |
| 424 | + } |
| 425 | + }) |
373 | 426 | ; |
374 | 427 | } |
375 | 428 | // @formatter:on |
|
0 commit comments