2019-02-01 17:42:59 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks.tiles;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.api.misc.ILevelData;
|
|
|
|
import de.ellpeck.naturesaura.misc.LevelData;
|
2020-01-22 23:21:52 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
2021-12-08 00:31:29 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2019-02-01 17:42:59 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickableBlockEntity {
|
2020-01-21 21:04:44 +01:00
|
|
|
|
2021-12-08 00:31:29 +01:00
|
|
|
public BlockEntityMossGenerator(BlockPos pos, BlockState state) {
|
2021-12-19 15:32:45 +01:00
|
|
|
super(ModBlockEntities.MOSS_GENERATOR, pos, state);
|
2020-01-21 21:04:44 +01:00
|
|
|
}
|
2019-02-01 17:42:59 +01:00
|
|
|
|
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
public void tick() {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!this.level.isClientSide) {
|
|
|
|
if (this.level.getGameTime() % 20 != 0)
|
2019-02-01 17:42:59 +01:00
|
|
|
return;
|
2021-12-15 16:30:22 +01:00
|
|
|
var data = (LevelData) ILevelData.getLevelData(this.level);
|
2019-02-01 17:42:59 +01:00
|
|
|
|
|
|
|
List<BlockPos> possibleOffsets = new ArrayList<>();
|
2021-12-15 16:30:22 +01:00
|
|
|
var range = 2;
|
|
|
|
for (var x = -range; x <= range; x++)
|
|
|
|
for (var y = -range; y <= range; y++)
|
|
|
|
for (var z = -range; z <= range; z++) {
|
|
|
|
var offset = this.worldPosition.offset(x, y, z);
|
|
|
|
var isRecent = data.recentlyConvertedMossStones.contains(offset);
|
|
|
|
var state = this.level.getBlockState(offset);
|
2020-01-26 00:43:12 +01:00
|
|
|
if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) {
|
|
|
|
if (isRecent)
|
|
|
|
continue;
|
2019-02-01 17:42:59 +01:00
|
|
|
possibleOffsets.add(offset);
|
2020-01-26 00:43:12 +01:00
|
|
|
} else if (isRecent) {
|
|
|
|
data.recentlyConvertedMossStones.remove(offset);
|
|
|
|
}
|
2019-02-01 17:42:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (possibleOffsets.isEmpty())
|
|
|
|
return;
|
2021-12-15 16:30:22 +01:00
|
|
|
var offset = possibleOffsets.get(this.level.random.nextInt(possibleOffsets.size()));
|
|
|
|
var state = this.level.getBlockState(offset);
|
|
|
|
var result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state);
|
2019-02-01 17:42:59 +01:00
|
|
|
|
2023-02-05 15:53:31 +01:00
|
|
|
var toAdd = 4000;
|
2021-03-30 15:44:31 +02:00
|
|
|
if (this.canGenerateRightNow(toAdd)) {
|
|
|
|
this.generateAura(toAdd);
|
2021-12-04 15:40:09 +01:00
|
|
|
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
|
2020-01-26 00:16:06 +01:00
|
|
|
new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.MOSS_GENERATOR));
|
2019-02-01 17:42:59 +01:00
|
|
|
}
|
|
|
|
|
2021-12-08 00:31:29 +01:00
|
|
|
this.level.levelEvent(2001, offset, Block.getId(state));
|
|
|
|
this.level.setBlockAndUpdate(offset, result);
|
2019-02-01 17:42:59 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-25 13:36:05 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wantsLimitRemover() {
|
|
|
|
return true;
|
|
|
|
}
|
2019-02-01 17:42:59 +01:00
|
|
|
}
|