slime split generator, part 1

This commit is contained in:
Ell 2020-09-28 16:45:37 +02:00
parent 5cfbb0f372
commit 6163c8efde
6 changed files with 173 additions and 1 deletions

View file

@ -0,0 +1,43 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.TileEntitySlimeSplitGenerator;
import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.SlimeEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockSlimeSplitGenerator extends BlockContainerImpl {
public BlockSlimeSplitGenerator() {
super("slime_split_generator", TileEntitySlimeSplitGenerator::new, Properties.from(Blocks.SLIME_BLOCK).hardnessAndResistance(2));
MinecraftForge.EVENT_BUS.register(new Events());
}
private static class Events {
@SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving();
if (!(entity instanceof SlimeEntity) || entity.world.isRemote)
return;
SlimeEntity slime = (SlimeEntity) entity;
int size = slime.getSlimeSize();
if (size <= 1)
return;
Helper.getTileEntitiesInArea(entity.world, entity.getPosition(), 8, tile -> {
if (!(tile instanceof TileEntitySlimeSplitGenerator))
return false;
TileEntitySlimeSplitGenerator gen = (TileEntitySlimeSplitGenerator) tile;
if (gen.isBusy())
return false;
gen.startGenerating(slime);
return true;
});
}
}
}

View file

@ -70,6 +70,7 @@ public final class ModBlocks {
public static Block LIGHT;
public static Block CHORUS_GENERATOR;
public static Block AURA_TIMER;
public static Block SLIME_SPLIT_GENERATOR;
public static Block.Properties prop(Material material, MaterialColor color) {
return Block.Properties.create(material, color);

View file

@ -40,4 +40,5 @@ public final class ModTileEntities {
public static TileEntityType<TileEntityAuraBloom> AURA_CACTUS;
public static TileEntityType<TileEntityChorusGenerator> CHORUS_GENERATOR;
public static TileEntityType<TileEntityAuraTimer> AURA_TIMER;
public static TileEntityType<TileEntitySlimeSplitGenerator> SLIME_SPLIT_GENERATOR;
}

View file

@ -0,0 +1,94 @@
package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.entity.monster.MagmaCubeEntity;
import net.minecraft.entity.monster.SlimeEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.math.BlockPos;
public class TileEntitySlimeSplitGenerator extends TileEntityImpl implements ITickableTileEntity {
private int generationTimer;
private int amountToRelease;
private int color;
public TileEntitySlimeSplitGenerator() {
super(ModTileEntities.SLIME_SPLIT_GENERATOR);
}
@Override
public void tick() {
if (this.world.isRemote || this.world.getGameTime() % 10 != 0)
return;
if (this.generationTimer > 0) {
int amount = this.amountToRelease * 10;
if (this.canGenerateRightNow(35, amount)) {
while (amount > 0) {
BlockPos pos = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
amount -= IAuraChunk.getAuraChunk(this.world, pos).storeAura(pos, amount);
}
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.SLIME_SPLIT_GEN_CREATE, this.color));
}
this.generationTimer -= 10;
}
}
@Override
public boolean wantsLimitRemover() {
return true;
}
public boolean isBusy() {
return this.generationTimer > 0;
}
public void startGenerating(SlimeEntity slime) {
int size = slime.getSlimeSize();
this.generationTimer = size * 30;
this.amountToRelease = (size * this.getGenerationAmount(slime)) / this.generationTimer;
this.color = this.getSlimeColor(slime);
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles((float) slime.getPosX(), (float) slime.getPosY(), (float) slime.getPosZ(), PacketParticles.Type.SLIME_SPLIT_GEN_START,
this.pos.getX(), this.pos.getY(), this.pos.getZ(), this.color));
}
@Override
public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type);
if (type == SaveType.TILE) {
compound.putInt("timer", this.generationTimer);
compound.putInt("amount", this.amountToRelease);
compound.putInt("color", this.color);
}
}
@Override
public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type);
if (type == SaveType.TILE) {
this.generationTimer = compound.getInt("timer");
this.amountToRelease = compound.getInt("amount");
this.color = compound.getInt("color");
}
}
private int getSlimeColor(SlimeEntity slime) {
if (slime instanceof MagmaCubeEntity) {
return 0x942516;
} else {
return 0x1ed921;
}
}
private int getGenerationAmount(SlimeEntity slime) {
if (slime instanceof MagmaCubeEntity) {
return 45000;
} else {
return 25000;
}
}
}

View file

@ -534,6 +534,38 @@ public class PacketParticles {
NaturesAuraAPI.instance().spawnMagicParticle(d0 + Math.cos(d24) * 5.0D, d13 - 0.4D, d18 + Math.sin(d24) * 5.0D, Math.cos(d24) * -2, 0.0D, Math.sin(d24) * -2, color, 2, 60, 0, false, true);
NaturesAuraAPI.instance().spawnMagicParticle(d0 + Math.cos(d24) * 5.0D, d13 - 0.4D, d18 + Math.sin(d24) * 5.0D, Math.cos(d24) * -2.5, 0.0D, Math.sin(d24) * -2.5, color, 2, 60, 0, false, true);
}
}),
SLIME_SPLIT_GEN_CREATE((message, world) -> {
for (int i = world.rand.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + world.rand.nextFloat() * 0.5F,
message.posY + 1.01F,
message.posZ + 0.25F + world.rand.nextFloat() * 0.5F,
world.rand.nextGaussian() * 0.01F,
world.rand.nextFloat() * 0.04F + 0.02F,
world.rand.nextGaussian() * 0.01F,
message.data[0], 1F + world.rand.nextFloat() * 1.5F, 40, 0F, false, true);
}),
SLIME_SPLIT_GEN_START((message, world) -> {
int x = message.data[0];
int y = message.data[1];
int z = message.data[2];
int color = message.data[3];
for (int i = world.rand.nextInt(10) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + (float) world.rand.nextGaussian() * 0.5F,
message.posY + (float) world.rand.nextGaussian() * 0.5F,
message.posZ + (float) world.rand.nextGaussian() * 0.5F,
world.rand.nextGaussian() * 0.02F,
world.rand.nextFloat() * 0.04F + 0.02F,
world.rand.nextGaussian() * 0.02F,
color, world.rand.nextFloat() + 1, world.rand.nextInt(20) + 20, 0, false, true);
for (int i = world.rand.nextInt(10) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnParticleStream(
message.posX + (float) world.rand.nextGaussian() * 0.5F,
message.posY + (float) world.rand.nextGaussian() * 0.5F,
message.posZ + (float) world.rand.nextGaussian() * 0.5F,
x + 0.5F, y + 0.5F, z + 0.5F, 0.2F, color, world.rand.nextFloat() + 1);
});
public final BiConsumer<PacketParticles, World> action;

View file

@ -142,7 +142,8 @@ public final class ModRegistry {
new BlockNetherGrass(),
new BlockLight(),
new BlockChorusGenerator(),
new BlockAuraTimer()
new BlockAuraTimer(),
new BlockSlimeSplitGenerator()
);
if (ModConfig.instance.rfConverter.get())