mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +01:00
animal gen functionality
This commit is contained in:
parent
de002bb01e
commit
2e156a8836
4 changed files with 143 additions and 0 deletions
|
@ -0,0 +1,68 @@
|
||||||
|
package de.ellpeck.naturesaura.blocks;
|
||||||
|
|
||||||
|
import de.ellpeck.naturesaura.Helper;
|
||||||
|
import de.ellpeck.naturesaura.NaturesAura;
|
||||||
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityAnimalGenerator;
|
||||||
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||||
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||||
|
import net.minecraft.block.SoundType;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.INpc;
|
||||||
|
import net.minecraft.entity.monster.IMob;
|
||||||
|
import net.minecraft.entity.passive.IAnimals;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||||
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
|
public class BlockAnimalGenerator extends BlockContainerImpl {
|
||||||
|
public BlockAnimalGenerator() {
|
||||||
|
super(Material.ROCK, "animal_generator", TileEntityAnimalGenerator.class, "animal_generator");
|
||||||
|
this.setSoundType(SoundType.WOOD);
|
||||||
|
this.setHardness(2F);
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onEntityDeath(LivingDeathEvent event) {
|
||||||
|
EntityLivingBase entity = event.getEntityLiving();
|
||||||
|
if (entity.world.isRemote || !(entity instanceof IAnimals) || entity instanceof IMob || entity instanceof INpc)
|
||||||
|
return;
|
||||||
|
BlockPos pos = entity.getPosition();
|
||||||
|
Helper.getTileEntitiesInArea(entity.world, pos, 5, tile -> {
|
||||||
|
if (!(tile instanceof TileEntityAnimalGenerator))
|
||||||
|
return false;
|
||||||
|
TileEntityAnimalGenerator gen = (TileEntityAnimalGenerator) tile;
|
||||||
|
entity.getEntityData().setBoolean(NaturesAura.MOD_ID + ":no_drops", true);
|
||||||
|
|
||||||
|
if (gen.isBusy())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
boolean child = entity.isChild();
|
||||||
|
int time = child ? 60 : 120;
|
||||||
|
int amount = child ? 45 : 70;
|
||||||
|
gen.setGenerationValues(time, amount);
|
||||||
|
|
||||||
|
BlockPos genPos = gen.getPos();
|
||||||
|
PacketHandler.sendToAllAround(entity.world, pos, 32, new PacketParticles(
|
||||||
|
(float) entity.posX, (float) entity.posY, (float) entity.posZ, 17,
|
||||||
|
child ? 1 : 0,
|
||||||
|
(int) (entity.getEyeHeight() * 10F),
|
||||||
|
genPos.getX(), genPos.getY(), genPos.getZ()));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onEntityDrops(LivingDropsEvent event) {
|
||||||
|
EntityLivingBase entity = event.getEntityLiving();
|
||||||
|
if (entity.world.isRemote)
|
||||||
|
return;
|
||||||
|
if (entity.getEntityData().getBoolean(NaturesAura.MOD_ID + ":no_drops")) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,4 +37,5 @@ public final class ModBlocks {
|
||||||
public static final Block OFFERING_TABLE = new BlockOfferingTable();
|
public static final Block OFFERING_TABLE = new BlockOfferingTable();
|
||||||
public static final Block PICKUP_STOPPER = new BlockPickupStopper();
|
public static final Block PICKUP_STOPPER = new BlockPickupStopper();
|
||||||
public static final Block SPAWN_LAMP = new BlockSpawnLamp();
|
public static final Block SPAWN_LAMP = new BlockSpawnLamp();
|
||||||
|
public static final Block ANIMAL_GENERATOR = new BlockAnimalGenerator();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package de.ellpeck.naturesaura.blocks.tiles;
|
||||||
|
|
||||||
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||||
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||||
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||||
|
import net.minecraft.util.ITickable;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class TileEntityAnimalGenerator extends TileEntityImpl implements ITickable {
|
||||||
|
|
||||||
|
private int timeRemaining;
|
||||||
|
private int amountToRelease;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
if (!this.world.isRemote) {
|
||||||
|
if (this.world.getTotalWorldTime() % 10 != 0)
|
||||||
|
return;
|
||||||
|
if (this.timeRemaining <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int remain = this.amountToRelease;
|
||||||
|
while (remain > 0) {
|
||||||
|
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
|
||||||
|
remain -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, remain);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.timeRemaining -= 10;
|
||||||
|
|
||||||
|
PacketHandler.sendToAllAround(this.world, this.pos, 32,
|
||||||
|
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), 16));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBusy() {
|
||||||
|
return this.timeRemaining > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGenerationValues(int time, int amount) {
|
||||||
|
this.timeRemaining = time;
|
||||||
|
this.amountToRelease = amount;
|
||||||
|
}
|
||||||
|
}
|
|
@ -271,6 +271,37 @@ public class PacketParticles implements IMessage {
|
||||||
0F, 0F, 0F,
|
0F, 0F, 0F,
|
||||||
0xf4a142, 1F, 30, 0F, false, true);
|
0xf4a142, 1F, 30, 0F, false, true);
|
||||||
break;
|
break;
|
||||||
|
case 16: // Animal generator aura creation
|
||||||
|
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,
|
||||||
|
0x5ccc30, 1F + world.rand.nextFloat() * 1.5F, 40, 0F, false, true);
|
||||||
|
break;
|
||||||
|
case 17: // Animal generator consuming
|
||||||
|
boolean child = message.data[0] > 0;
|
||||||
|
float height = message.data[1] / 10F;
|
||||||
|
genX = message.data[2];
|
||||||
|
genY = message.data[3];
|
||||||
|
genZ = message.data[4];
|
||||||
|
for (int i = (child ? world.rand.nextInt(10) + 10 : world.rand.nextInt(20) + 20); i >= 0; i--)
|
||||||
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
||||||
|
message.posX + world.rand.nextGaussian() * 0.25F,
|
||||||
|
message.posY + height * 0.75F + world.rand.nextGaussian() * 0.25F,
|
||||||
|
message.posZ + world.rand.nextGaussian() * 0.25F,
|
||||||
|
world.rand.nextGaussian() * 0.01F,
|
||||||
|
world.rand.nextFloat() * 0.01F,
|
||||||
|
world.rand.nextGaussian() * 0.01F,
|
||||||
|
0x42f4c8, world.rand.nextFloat() * (child ? 0.5F : 2F) + 1F, world.rand.nextInt(30) + 40, 0F, true, true);
|
||||||
|
NaturesAuraAPI.instance().spawnParticleStream(
|
||||||
|
message.posX, message.posY + height * 0.75F, message.posZ,
|
||||||
|
genX + 0.5F, genY + 0.5F, genZ + 0.5F,
|
||||||
|
0.15F, 0x41c4f4, child ? 1.5F : 3F);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue