-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Json Things support for burning fluids
- Loading branch information
1 parent
2fa33b0
commit 4dd9249
Showing
5 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/main/java/slimeknights/tconstruct/plugin/jsonthings/FlexBlockTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package slimeknights.tconstruct.plugin.jsonthings; | ||
|
||
import dev.gigaherz.jsonthings.things.IFlexBlock; | ||
import dev.gigaherz.jsonthings.things.serializers.FlexBlockType; | ||
import dev.gigaherz.jsonthings.things.serializers.IBlockSerializer; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.GsonHelper; | ||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraft.world.effect.MobEffectInstance; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition.Builder; | ||
import net.minecraft.world.level.block.state.properties.Property; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraft.world.level.material.Material; | ||
import net.minecraftforge.common.util.Lazy; | ||
import slimeknights.mantle.data.loadable.Loadables; | ||
import slimeknights.mantle.data.loadable.primitive.ResourceLocationLoadable; | ||
import slimeknights.tconstruct.TConstruct; | ||
import slimeknights.tconstruct.plugin.jsonthings.block.FlexBurningLiquidBlock; | ||
import slimeknights.tconstruct.plugin.jsonthings.block.FlexMobEffectLiquidBlock; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
/** Collection of custom block types added by Tinkers */ | ||
public class FlexBlockTypes { | ||
/** Creates the supplier for a fluid in a fluid block */ | ||
private static Supplier<FlowingFluid> fluidSupplier(ResourceLocation name) { | ||
return Lazy.of(() -> { | ||
// TODO: make Mantle loadables resource location | ||
if (((ResourceLocationLoadable<Fluid>)Loadables.FLUID).fromKey(name, "fluid") instanceof FlowingFluid flowing) { | ||
return flowing; | ||
} else { | ||
throw new RuntimeException("LiquidBlock requires a flowing fluid"); | ||
} | ||
}); | ||
} | ||
|
||
/** Initializes the block types */ | ||
public static void init() { | ||
register("burning_liquid", data -> { | ||
ResourceLocation fluidField = Loadables.RESOURCE_LOCATION.getOrDefault(data, "fluid", null); | ||
int burnTime = GsonHelper.getAsInt(data, "burn_time"); | ||
float damage = GsonHelper.getAsFloat(data, "damage"); | ||
return (props, builder) -> { | ||
final List<Property<?>> _properties = builder.getProperties(); | ||
return new FlexBurningLiquidBlock(props, builder.getPropertyDefaultValues(), fluidSupplier(Objects.requireNonNullElse(fluidField, builder.getRegistryName())), burnTime, damage) { | ||
@Override | ||
protected void createBlockStateDefinition(Builder<Block,BlockState> stateBuilder) { | ||
super.createBlockStateDefinition(stateBuilder); | ||
_properties.forEach(stateBuilder::add); | ||
} | ||
}; | ||
}; | ||
}, Material.LAVA); | ||
register("mob_effect_liquid", data -> { | ||
ResourceLocation fluidField = Loadables.RESOURCE_LOCATION.getOrDefault(data, "fluid", null); | ||
ResourceLocation effectName = Loadables.RESOURCE_LOCATION.getIfPresent(data, "effect"); | ||
int effectLevel = GsonHelper.getAsInt(data, "burn_time"); | ||
return (props, builder) -> { | ||
final List<Property<?>> _properties = builder.getProperties(); | ||
Lazy<MobEffect> effect = Lazy.of(() -> ((ResourceLocationLoadable<MobEffect>)Loadables.MOB_EFFECT).fromKey(effectName, "effect")); | ||
return new FlexMobEffectLiquidBlock(props, builder.getPropertyDefaultValues(), fluidSupplier(Objects.requireNonNullElse(fluidField, builder.getRegistryName())), () -> new MobEffectInstance(effect.get(), 5*20, effectLevel - 1)) { | ||
@Override | ||
protected void createBlockStateDefinition(Builder<Block,BlockState> stateBuilder) { | ||
super.createBlockStateDefinition(stateBuilder); | ||
_properties.forEach(stateBuilder::add); | ||
} | ||
}; | ||
}; | ||
}, Material.WATER); | ||
} | ||
|
||
/** Local helper to register our stuff */ | ||
private static <T extends Block & IFlexBlock> void register(String name, IBlockSerializer<T> factory, Material defaultMaterial) { | ||
FlexBlockType.register(TConstruct.resourceString(name), factory, "translucent", true, defaultMaterial); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/slimeknights/tconstruct/plugin/jsonthings/block/FlexBurningLiquidBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package slimeknights.tconstruct.plugin.jsonthings.block; | ||
|
||
import dev.gigaherz.jsonthings.things.blocks.FlexLiquidBlock; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.world.damagesource.DamageSource; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.Property; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
|
||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
/** Json Things version of {@link slimeknights.tconstruct.fluids.block.BurningLiquidBlock} */ | ||
public class FlexBurningLiquidBlock extends FlexLiquidBlock { | ||
private final int burnTime; | ||
private final float damage; | ||
public FlexBurningLiquidBlock(Properties properties, Map<Property<?>,Comparable<?>> propertyDefaultValues, Supplier<FlowingFluid> fluidSupplier, int burnTime, float damage) { | ||
super(properties, propertyDefaultValues, fluidSupplier); | ||
this.burnTime = burnTime; | ||
this.damage = damage; | ||
} | ||
|
||
@Override | ||
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) { | ||
if (!entity.fireImmune() && entity.getFluidTypeHeight(getFluid().getFluidType()) > 0) { | ||
entity.setSecondsOnFire(burnTime); | ||
if (entity.hurt(DamageSource.LAVA, damage)) { | ||
entity.playSound(SoundEvents.GENERIC_BURN, 0.4F, 2.0F + level.random.nextFloat() * 0.4F); | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/slimeknights/tconstruct/plugin/jsonthings/block/FlexMobEffectLiquidBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package slimeknights.tconstruct.plugin.jsonthings.block; | ||
|
||
import dev.gigaherz.jsonthings.things.blocks.FlexLiquidBlock; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.effect.MobEffectInstance; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.Property; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
/** Json Things version of {@link slimeknights.tconstruct.fluids.block.BurningLiquidBlock} */ | ||
public class FlexMobEffectLiquidBlock extends FlexLiquidBlock { | ||
private final Supplier<MobEffectInstance> effect; | ||
public FlexMobEffectLiquidBlock(Properties properties, Map<Property<?>,Comparable<?>> propertyDefaultValues, Supplier<FlowingFluid> fluidSupplier, Supplier<MobEffectInstance> effect) { | ||
super(properties, propertyDefaultValues, fluidSupplier); | ||
this.effect = effect; | ||
} | ||
|
||
@Override | ||
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) { | ||
if (entity.getFluidTypeHeight(getFluid().getFluidType()) > 0 && entity instanceof LivingEntity living) { | ||
MobEffectInstance effect = this.effect.get(); | ||
effect.setCurativeItems(new ArrayList<>()); | ||
living.addEffect(effect); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/slimeknights/tconstruct/plugin/jsonthings/block/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
package slimeknights.tconstruct.plugin.jsonthings.block; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |