Skip to content

Commit 1e2bdbc

Browse files
committed
Damage Type+Tags Datapacks
1 parent 8a144ce commit 1e2bdbc

File tree

5 files changed

+112
-9
lines changed

5 files changed

+112
-9
lines changed

src/main/java/org/spongepowered/api/datapack/DataPackType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.spongepowered.api.advancement.AdvancementTemplate;
2828
import org.spongepowered.api.adventure.ChatTypeTemplate;
29+
import org.spongepowered.api.event.cause.entity.damage.DamageTypeTemplate;
2930
import org.spongepowered.api.item.recipe.RecipeRegistration;
3031
import org.spongepowered.api.registry.RegistryType;
3132
import org.spongepowered.api.tag.TagTemplate;
@@ -96,5 +97,7 @@ interface Factory {
9697
DataPackType<JigsawPoolTemplate> jigsawPool();
9798

9899
DataPackType<ChatTypeTemplate> chatType();
100+
101+
DataPackType<DamageTypeTemplate> damageType();
99102
}
100103
}

src/main/java/org/spongepowered/api/datapack/DataPackTypes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.spongepowered.api.adventure.ChatTypeTemplate;
3030
import org.spongepowered.api.block.BlockType;
3131
import org.spongepowered.api.entity.EntityType;
32+
import org.spongepowered.api.event.cause.entity.damage.DamageType;
33+
import org.spongepowered.api.event.cause.entity.damage.DamageTypeTemplate;
3234
import org.spongepowered.api.fluid.FluidType;
3335
import org.spongepowered.api.item.ItemType;
3436
import org.spongepowered.api.item.recipe.RecipeRegistration;
@@ -99,6 +101,9 @@ public final class DataPackTypes {
99101

100102
public static final DataPackType<ChatTypeTemplate> CHAT_TYPE = Sponge.game().factoryProvider().provide(DataPackType.Factory.class).chatType();
101103

104+
public static final DataPackType<DamageTypeTemplate> DAMAGE_TYPE = Sponge.game().factoryProvider().provide(DataPackType.Factory.class).damageType();
105+
public static final DataPackType<TagTemplate<DamageType>> DAMAGE_TYPE_TAG = Sponge.game().factoryProvider().provide(DataPackType.Factory.class).tag(RegistryTypes.DAMAGE_TYPE);
106+
102107
// SORTFIELDS:OFF
103108

104109
// TODO `worldgen/world_preset`? WorldGenerationConfig? with mapping of LevelStems

src/main/java/org/spongepowered/api/datapack/DataPacks.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.spongepowered.api.adventure.ChatTypeTemplate;
2929
import org.spongepowered.api.block.BlockType;
3030
import org.spongepowered.api.entity.EntityType;
31+
import org.spongepowered.api.event.cause.entity.damage.DamageType;
32+
import org.spongepowered.api.event.cause.entity.damage.DamageTypeTemplate;
3133
import org.spongepowered.api.fluid.FluidType;
3234
import org.spongepowered.api.item.ItemType;
3335
import org.spongepowered.api.item.recipe.RecipeRegistration;
@@ -95,6 +97,9 @@ public final class DataPacks {
9597
public static final DataPack<JigsawPoolTemplate> JIGSAW_POOL = DataPackTypes.JIGSAW_POOL.pack("plugin_worldgen", "Sponge plugin provided jigsaw pools");
9698
public static final DataPack<ChatTypeTemplate> CHAT_TYPE = DataPackTypes.CHAT_TYPE.pack("plugin_chat_types", "Sponge plugin provided chat types");
9799

100+
public static final DataPack<DamageTypeTemplate> DAMAGE_TYPE = DataPackTypes.DAMAGE_TYPE.pack("plugin_damage_types", "Sponge plugin provided damage types");
101+
public static final DataPack<TagTemplate<DamageType>> DAMAGE_TYPE_TAG = DataPackTypes.DAMAGE_TYPE_TAG.pack("plugin_damage_types", "Sponge plugin provided damage type tags");
102+
98103
// SORTFIELDS:ON
99104

100105
private DataPacks() {

src/main/java/org/spongepowered/api/event/cause/entity/damage/DamageType.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
2929
import org.spongepowered.api.registry.DefaultedRegistryValue;
3030
import org.spongepowered.api.tag.Tag;
31+
import org.spongepowered.api.tag.Taggable;
3132
import org.spongepowered.api.util.Nameable;
3233
import org.spongepowered.api.util.annotation.CatalogedBy;
3334

@@ -38,16 +39,8 @@
3839
* can damage an {@link Entity} with varying {@link DamageType}s depending on the circumstances.
3940
*/
4041
@CatalogedBy(DamageTypes.class)
41-
public interface DamageType extends DefaultedRegistryValue, Nameable {
42+
public interface DamageType extends DefaultedRegistryValue, Nameable, Taggable<DamageType> {
4243

43-
/**
44-
* Creates a new {@link Builder builder} to build a {@link DamageType}.
45-
*
46-
* @return A new builder
47-
*/
48-
static Builder builder() {
49-
return Sponge.game().builderProvider().provide(Builder.class);
50-
}
5144

5245
/**
5346
* Gets the amount of exhaustion this {@link DamageType} will add to the entity, generally only to players.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.event.cause.entity.damage;
26+
27+
import org.spongepowered.api.Sponge;
28+
import org.spongepowered.api.datapack.DataPackEntry;
29+
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
30+
import org.spongepowered.api.util.DataPackEntryBuilder;
31+
32+
/**
33+
* A template for {@link DamageType damage types}.
34+
*/
35+
36+
public interface DamageTypeTemplate extends DataPackEntry<DamageTypeTemplate> {
37+
38+
static Builder builder() {
39+
return Sponge.game().builderProvider().provide(Builder.class).reset();
40+
}
41+
42+
/**
43+
* Returns the damage type
44+
*
45+
* @return the damage type
46+
*/
47+
DamageType type();
48+
49+
50+
interface Builder extends DataPackEntryBuilder<DamageType, DamageTypeTemplate, Builder> {
51+
52+
/**
53+
* Sets the name of the {@link DamageType}.
54+
* Used as part of the death message translation key.
55+
* TODO falling/intentional game design?
56+
*
57+
* @param name The name
58+
*
59+
* @return This builder, for chaining
60+
*/
61+
Builder name(String name);
62+
63+
/**
64+
* Sets damage scaling
65+
*
66+
* @param scaling the daamge scaling
67+
*
68+
* @return This builder
69+
*/
70+
Builder scaling(DamageScaling scaling);
71+
72+
/**
73+
* Sets damage effects
74+
*
75+
* @param effect the damage effect
76+
*
77+
* @return This builder
78+
*/
79+
Builder effect(DamageEffect effect);
80+
81+
/**
82+
* Sets the amount of exhaustion a {@link DamageSource} of this type will
83+
* add to the entity, generally only to players.
84+
*
85+
* TODO check if this is still correct
86+
* <p>In vanilla gameplay, the default is 0.1, unless if the damage
87+
* is absolute or bypasses armor, where the exhaustion gets set to 0.
88+
* </p>
89+
*
90+
* @param exhaustion The amount of exhaustion to add to the entity
91+
* @return This builder
92+
*/
93+
Builder exhaustion(double exhaustion);
94+
95+
}
96+
97+
}

0 commit comments

Comments
 (0)