Skip to content

Commit

Permalink
fixing explosions
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed Aug 27, 2024
1 parent a9e5275 commit 30055c2
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ public final class Keys {
* determined randomly at the time of the explosion or computed from the
* context in which the {@link Explosive} explodes.</p>
*/
public static final Key<Value<Integer>> EXPLOSION_RADIUS = Keys.key(ResourceKey.sponge("explosion_radius"), Integer.class);
public static final Key<Value<Float>> EXPLOSION_RADIUS = Keys.key(ResourceKey.sponge("explosion_radius"), Float.class);

/**
* The eye height of an {@link Entity}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface Explosive extends Entity {
*
* @return The explosion radius
*/
default Optional<Value.Mutable<Integer>> explosionRadius() {
default Optional<Value.Mutable<Float>> explosionRadius() {
return this.getValue(Keys.EXPLOSION_RADIUS).map(Value::asMutable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
import org.spongepowered.api.world.biome.climate.TemperatureModifier;
import org.spongepowered.api.world.chunk.ChunkState;
import org.spongepowered.api.world.difficulty.Difficulty;
import org.spongepowered.api.world.explosion.ExplosionBlockInteraction;
import org.spongepowered.api.world.gamerule.GameRule;
import org.spongepowered.api.world.generation.carver.Carver;
import org.spongepowered.api.world.generation.carver.CarverType;
Expand Down Expand Up @@ -357,6 +358,8 @@ public final class RegistryTypes {

public static final DefaultedRegistryType<EquipmentType> EQUIPMENT_TYPE = RegistryTypes.spongeKeyInGame("equipment_type");

public static final RegistryType<ExplosionBlockInteraction> EXPLOSION_BLOCK_INTERACTION = RegistryTypes.spongeKeyInGame("explosion_block_interaction");

public static final DefaultedRegistryType<FireworkShape> FIREWORK_SHAPE = RegistryTypes.spongeKeyInGame("firework_shape");

public static final DefaultedRegistryType<FlatGeneratorConfig> FLAT_GENERATOR_CONFIG = RegistryTypes.spongeKeyInGame("flat_generator_config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ interface Builder extends org.spongepowered.api.util.Builder<Explosion, Builder>
Builder shouldPlaySmoke(boolean smoke);

/**
* Sets whether the affected blocks should be destroyed on explosion.
* Sets the desired block interaction.
*
* @param destroy Whether the affected blocks should be destroyed
* @param interaction the desired block interaction
* @return The builder, for chaining
*/
Builder shouldBreakBlocks(boolean destroy);
Builder blockInteraction(ExplosionBlockInteraction interaction);

/**
* Sets the resolution of the explosion.
Expand Down Expand Up @@ -244,4 +244,5 @@ default Builder knockback(double knockback) {
Explosion build() throws IllegalArgumentException;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.world.explosion;

import org.spongepowered.api.util.annotation.CatalogedBy;

@CatalogedBy(ExplosionBlockInteractions.class)
public interface ExplosionBlockInteraction {
// TODO mixin

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.world.explosion;

import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.registry.DefaultedRegistryReference;
import org.spongepowered.api.registry.Registry;
import org.spongepowered.api.registry.RegistryKey;
import org.spongepowered.api.registry.RegistryTypes;

public final class ExplosionBlockInteractions {
public static final DefaultedRegistryReference<ExplosionBlockInteraction> KEEP = ExplosionBlockInteractions.key(ResourceKey.sponge("keep"));
public static final DefaultedRegistryReference<ExplosionBlockInteraction> DESTROY = ExplosionBlockInteractions.key(ResourceKey.sponge("destroy"));
public static final DefaultedRegistryReference<ExplosionBlockInteraction> DESTROY_WITH_DECAY = ExplosionBlockInteractions.key(ResourceKey.sponge("destroy_with_decay"));
public static final DefaultedRegistryReference<ExplosionBlockInteraction> TRIGGER_BLOCK = ExplosionBlockInteractions.key(ResourceKey.sponge("trigger_block"));

private ExplosionBlockInteractions() {
}

public static Registry<ExplosionBlockInteraction> registry() {
return Sponge.game().registry(RegistryTypes.EXPLOSION_BLOCK_INTERACTION);
}

private static DefaultedRegistryReference<ExplosionBlockInteraction> key(final ResourceKey location) {
return RegistryKey.of(RegistryTypes.EXPLOSION_BLOCK_INTERACTION, location).asDefaultedReference(Sponge::game);
}
}

0 comments on commit 30055c2

Please sign in to comment.