12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package me.km.effects;
- import me.km.KajetansMod;
- import java.util.ArrayList;
- import java.util.function.Consumer;
- import me.km.api.Location;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- public class EffectAirBlockChanger
- {
- private final World w;
- private final ArrayList<ChangeBlock> list;
-
- public EffectAirBlockChanger(World w)
- {
- this.w = w;
- list = new ArrayList<>();
- }
-
- public void addBlock(BlockPos pos)
- {
- if(!w.isAirBlock(pos) && w.getTileEntity(pos) == null)
- {
- list.add(new ChangeBlock(pos));
- }
- }
-
- public void run(int clean)
- {
- list.forEach(c -> c.run());
- KajetansMod.scheduler.scheduleTask(() -> list.forEach(c -> c.clear()), clean);
- }
-
- public World getWorld()
- {
- return w;
- }
-
- public void forEachLocation(Consumer<? super Location> c)
- {
- list.stream().map(l -> new Location(w, l.pos)).forEach(c);
- }
-
- private class ChangeBlock
- {
- private final BlockPos pos;
- private final IBlockState state;
- public ChangeBlock(BlockPos pos)
- {
- this.pos = pos;
- this.state = w.getBlockState(pos);
- }
- public void run()
- {
- w.setBlockToAir(pos);
- }
- public void clear()
- {
- w.setBlockState(pos, state);
- }
- }
- }
|