72 lines
2.2 KiB
Java
72 lines
2.2 KiB
Java
package com.thebrokenrail.energonrelics.block.entity.infuser;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.Items;
|
|
import net.minecraft.particle.ParticleTypes;
|
|
import net.minecraft.server.world.ServerWorld;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.explosion.Explosion;
|
|
|
|
interface InfuserAction {
|
|
void run(World world, BlockPos pos);
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
InfuserOutputItem display();
|
|
|
|
class ItemAction implements InfuserAction {
|
|
final ItemStack stack;
|
|
|
|
ItemAction(ItemStack stack) {
|
|
this.stack = stack;
|
|
}
|
|
|
|
ItemAction(Item item) {
|
|
this(new ItemStack(item));
|
|
}
|
|
|
|
@Override
|
|
public void run(World world, BlockPos pos) {
|
|
Block.dropStack(world, pos, stack);
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
@Override
|
|
public InfuserOutputItem display() {
|
|
return new InfuserOutputItem(true, stack);
|
|
}
|
|
}
|
|
|
|
class ExplosionAction implements InfuserAction {
|
|
@Override
|
|
public void run(World world, BlockPos pos) {
|
|
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
|
world.createExplosion(null, pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d, 3f, true, Explosion.DestructionType.DESTROY);
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
@Override
|
|
public InfuserOutputItem display() {
|
|
return new InfuserOutputItem(false, new ItemStack(Items.TNT));
|
|
}
|
|
}
|
|
|
|
class ParticleAction implements InfuserAction {
|
|
@Override
|
|
public void run(World world, BlockPos pos) {
|
|
((ServerWorld) world).spawnParticles(ParticleTypes.SMOKE, pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d, 38, 0.31f, 0.31f, 0.31f, 0f);
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
@Override
|
|
public InfuserOutputItem display() {
|
|
return new InfuserOutputItem(false, new ItemStack(Items.FIRE_CHARGE));
|
|
}
|
|
}
|
|
}
|