NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityMossGenerator.java

70 lines
2.8 KiB
Java
Raw Normal View History

2019-02-01 17:42:59 +01:00
package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
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;
2019-02-01 17:42:59 +01:00
import net.minecraft.block.Block;
2019-10-20 22:30:49 +02:00
import net.minecraft.block.BlockState;
2021-12-04 15:40:09 +01:00
import net.minecraft.tileentity.ITickableBlockEntity;
2019-02-01 17:42:59 +01:00
import net.minecraft.util.math.BlockPos;
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-04 15:40:09 +01:00
public BlockEntityMossGenerator() {
2020-01-22 01:32:26 +01:00
super(ModTileEntities.MOSS_GENERATOR);
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-04 15:40:09 +01:00
LevelData data = (LevelData) ILevelData.getLevelData(this.level);
2019-02-01 17:42:59 +01:00
List<BlockPos> possibleOffsets = new ArrayList<>();
int range = 2;
for (int x = -range; x <= range; x++)
for (int y = -range; y <= range; y++)
for (int z = -range; z <= range; z++) {
2021-12-04 15:40:09 +01:00
BlockPos offset = this.worldPosition.add(x, y, z);
boolean isRecent = data.recentlyConvertedMossStones.contains(offset);
2021-12-04 15:40:09 +01:00
BlockState state = this.level.getBlockState(offset);
if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) {
if (isRecent)
continue;
2019-02-01 17:42:59 +01:00
possibleOffsets.add(offset);
} else if (isRecent) {
data.recentlyConvertedMossStones.remove(offset);
}
2019-02-01 17:42:59 +01:00
}
if (possibleOffsets.isEmpty())
return;
2021-12-04 15:40:09 +01:00
BlockPos offset = possibleOffsets.get(this.level.rand.nextInt(possibleOffsets.size()));
BlockState state = this.level.getBlockState(offset);
2019-10-20 22:30:49 +02:00
BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state);
2019-02-01 17:42:59 +01:00
int toAdd = 7000;
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-04 15:40:09 +01:00
this.level.playEvent(2001, offset, Block.getStateId(state));
this.level.setBlockState(offset, result);
2019-02-01 17:42:59 +01:00
}
}
@Override
public boolean wantsLimitRemover() {
return true;
}
2019-02-01 17:42:59 +01:00
}