EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/registry/infuser/data/InfuserAction.java

89 lines
2.5 KiB
Java
Raw Normal View History

2020-08-04 17:06:11 +00:00
package com.thebrokenrail.energonrelics.registry.infuser.data;
2020-07-30 02:51:29 +00:00
2020-08-03 17:00:08 +00:00
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
2020-07-30 02:51:29 +00:00
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2020-08-03 17:00:08 +00:00
import net.minecraft.item.Items;
2020-07-30 03:48:07 +00:00
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
2020-07-30 02:51:29 +00:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
2020-08-04 17:06:11 +00:00
/**
* Infuser Action
*/
public interface InfuserAction {
/**
* Run Infuser Action
* @param world World
* @param pos Infuser Position
*/
2020-07-30 02:51:29 +00:00
void run(World world, BlockPos pos);
2020-08-03 17:00:08 +00:00
@Environment(EnvType.CLIENT)
InfuserOutputItem display();
2020-08-04 17:06:11 +00:00
/**
* Infuser Action That Creates An Item
*/
2020-07-30 02:51:29 +00:00
class ItemAction implements InfuserAction {
2020-07-30 19:49:18 +00:00
final ItemStack stack;
2020-07-30 02:51:29 +00:00
2020-08-04 17:06:11 +00:00
public ItemAction(ItemStack stack) {
2020-07-30 02:51:29 +00:00
this.stack = stack;
}
2020-08-04 17:06:11 +00:00
public ItemAction(Item item) {
2020-07-30 02:51:29 +00:00
this(new ItemStack(item));
}
@Override
public void run(World world, BlockPos pos) {
Block.dropStack(world, pos, stack);
}
2020-08-03 17:00:08 +00:00
@Override
2020-08-03 22:04:11 +00:00
@Environment(EnvType.CLIENT)
2020-08-03 17:00:08 +00:00
public InfuserOutputItem display() {
return new InfuserOutputItem(true, stack);
}
2020-07-30 02:51:29 +00:00
}
2020-08-04 17:06:11 +00:00
/**
* Infuser Action That Creates An Explosion
*/
2020-07-30 02:51:29 +00:00
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);
2020-07-30 03:48:07 +00:00
}
2020-08-03 17:00:08 +00:00
@Override
2020-08-03 22:04:11 +00:00
@Environment(EnvType.CLIENT)
2020-08-03 17:00:08 +00:00
public InfuserOutputItem display() {
return new InfuserOutputItem(false, new ItemStack(Items.TNT));
}
2020-07-30 03:48:07 +00:00
}
2020-08-04 17:06:11 +00:00
/**
* Infuser Action That Creates Some Particles
*/
2020-07-30 03:48:07 +00:00
class ParticleAction implements InfuserAction {
@Override
public void run(World world, BlockPos pos) {
2020-07-30 19:49:18 +00:00
((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);
2020-07-30 02:51:29 +00:00
}
2020-08-03 17:00:08 +00:00
@Override
2020-08-03 22:04:11 +00:00
@Environment(EnvType.CLIENT)
2020-08-03 17:00:08 +00:00
public InfuserOutputItem display() {
return new InfuserOutputItem(false, new ItemStack(Items.FIRE_CHARGE));
}
2020-07-30 02:51:29 +00:00
}
}