forked from TheBrokenRail/EnergonRelics
89 lines
2.5 KiB
Java
89 lines
2.5 KiB
Java
package com.thebrokenrail.energonrelics.registry.infuser.data;
|
|
|
|
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;
|
|
|
|
/**
|
|
* Infuser Action
|
|
*/
|
|
public interface InfuserAction {
|
|
/**
|
|
* Run Infuser Action
|
|
* @param world World
|
|
* @param pos Infuser Position
|
|
*/
|
|
void run(World world, BlockPos pos);
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
InfuserOutputItem display();
|
|
|
|
/**
|
|
* Infuser Action That Creates An Item
|
|
*/
|
|
class ItemAction implements InfuserAction {
|
|
final ItemStack stack;
|
|
|
|
public ItemAction(ItemStack stack) {
|
|
this.stack = stack;
|
|
}
|
|
|
|
public ItemAction(Item item) {
|
|
this(new ItemStack(item));
|
|
}
|
|
|
|
@Override
|
|
public void run(World world, BlockPos pos) {
|
|
Block.dropStack(world, pos, stack);
|
|
}
|
|
|
|
@Override
|
|
@Environment(EnvType.CLIENT)
|
|
public InfuserOutputItem display() {
|
|
return new InfuserOutputItem(true, stack);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Infuser Action That Creates An Explosion
|
|
*/
|
|
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);
|
|
}
|
|
|
|
@Override
|
|
@Environment(EnvType.CLIENT)
|
|
public InfuserOutputItem display() {
|
|
return new InfuserOutputItem(false, new ItemStack(Items.TNT));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Infuser Action That Creates Some Particles
|
|
*/
|
|
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);
|
|
}
|
|
|
|
@Override
|
|
@Environment(EnvType.CLIENT)
|
|
public InfuserOutputItem display() {
|
|
return new InfuserOutputItem(false, new ItemStack(Items.FIRE_CHARGE));
|
|
}
|
|
}
|
|
}
|