This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
Twine/src/main/java/com/thebrokenrail/twine/block/GlowingObsidianBlock.java

52 lines
2.1 KiB
Java
Raw Normal View History

2020-06-14 03:04:21 +00:00
package com.thebrokenrail.twine.block;
2020-06-17 21:57:52 +00:00
import com.thebrokenrail.twine.util.ItemUtil;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
2020-06-14 03:04:21 +00:00
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
2020-06-17 21:57:52 +00:00
import net.minecraft.client.item.TooltipContext;
2020-06-14 03:04:21 +00:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.Monster;
2020-06-17 21:57:52 +00:00
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
2020-06-17 21:57:52 +00:00
import net.minecraft.text.Text;
2020-06-14 03:04:21 +00:00
import net.minecraft.util.math.BlockPos;
2020-06-17 21:57:52 +00:00
import net.minecraft.world.BlockView;
2020-06-14 03:04:21 +00:00
import net.minecraft.world.World;
2020-06-17 21:57:52 +00:00
import java.util.List;
2020-06-14 03:04:21 +00:00
public class GlowingObsidianBlock extends Block {
public GlowingObsidianBlock() {
2020-06-18 22:25:33 +00:00
super(Settings.of(Material.STONE, MaterialColor.BLACK).requiresTool().strength(50.0F, 1200.0F).lightLevel(state -> 6).allowsSpawning((state, world, pos, type) -> false).emissiveLighting((state, world, pos) -> true));
2020-06-14 03:04:21 +00:00
}
@Override
public void onSteppedOn(World world, BlockPos pos, Entity entity) {
super.onSteppedOn(world, pos, entity);
2020-06-18 22:25:33 +00:00
if (!world.isClient() && entity instanceof LivingEntity) {
((ServerWorld) world).spawnParticles(ParticleTypes.SMOKE, pos.getX() + 0.5d, pos.getY() + 1d, pos.getZ() + 0.5d, 3 + world.getRandom().nextInt(3), 0.2d, 0.5d, 0.2d,0.01d);
if (entity.age % 10 == 0) {
final float amount = 2f;
if (entity instanceof Monster) {
((LivingEntity) entity).heal(amount);
} else {
entity.damage(DamageSource.MAGIC, amount);
}
2020-06-14 03:04:21 +00:00
}
}
}
2020-06-17 21:57:52 +00:00
@Override
@Environment(EnvType.CLIENT)
public void buildTooltip(ItemStack stack, BlockView world, List<Text> tooltip, TooltipContext options) {
super.buildTooltip(stack, world, tooltip, options);
ItemUtil.addTooltip("block", "glowing_obsidian", 2, tooltip);
}
2020-06-14 03:04:21 +00:00
}