/** * This class was created by <Pokefenn>. It's distributed as * part of the Botania Mod. Get the Source Code in github: * https://github.com/Vazkii/Botania * * Botania is Open Source and distributed under the * Botania License: http://botaniamod.net/license.php * * File Created @ [? (GMT)] */ package vazkii.botania.common.block.subtile.generating; import java.util.Arrays; import java.util.Collections; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fluids.BlockFluidBase; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileGenerating; import vazkii.botania.common.Botania; import vazkii.botania.common.core.helper.ItemNBTHelper; import vazkii.botania.common.lexicon.LexiconData; public class SubTileHydroangeas extends SubTileGenerating { private static final String TAG_BURN_TIME = "burnTime"; private static final String TAG_COOLDOWN = "cooldown"; private static final BlockPos[] OFFSETS = { new BlockPos(0, 0, 1), new BlockPos(0, 0, -1), new BlockPos(1, 0, 0), new BlockPos(-1, 0, 0), new BlockPos(-1, 0, 1), new BlockPos(-1, 0, -1), new BlockPos(1, 0, 1), new BlockPos(1, 0, -1) }; int burnTime, cooldown; @Override public void onUpdate() { super.onUpdate(); if(cooldown > 0) { cooldown--; for(int i = 0; i < 3; i++) Botania.proxy.wispFX(supertile.getPos().getX() + 0.5 + Math.random() * 0.2 - 0.1, supertile.getPos().getY() + 0.5 + Math.random() * 0.2 - 0.1, supertile.getPos().getZ() + 0.5 + Math.random() * 0.2 - 0.1, 0.1F, 0.1F, 0.1F, (float) Math.random() / 6, (float) -Math.random() / 30); return; } if(burnTime == 0) { if(mana < getMaxMana() && !supertile.getWorld().isRemote) { List<BlockPos> offsets = Arrays.asList(OFFSETS); Collections.shuffle(offsets); for(BlockPos offset : offsets) { BlockPos pos = supertile.getPos().add(offset); Material search = getMaterialToSearchFor(); PropertyInteger prop = supertile.getWorld().getBlockState(pos).getBlock() instanceof BlockLiquid ? BlockLiquid.LEVEL : supertile.getWorld().getBlockState(pos).getBlock() instanceof BlockFluidBase ? BlockFluidBase.LEVEL : null; if(supertile.getWorld().getBlockState(pos).getMaterial() == search && (getBlockToSearchBelow() == null || supertile.getWorld().getBlockState(pos.down()).getBlock() == getBlockToSearchBelow()) && (prop == null || supertile.getWorld().getBlockState(pos).getValue(prop) == 0)) { if(search != Material.WATER) supertile.getWorld().setBlockToAir(pos); else { int waterAround = 0; for(EnumFacing dir : EnumFacing.HORIZONTALS) if(supertile.getWorld().getBlockState(pos.offset(dir)).getMaterial() == search) waterAround++; if(waterAround < 2) supertile.getWorld().setBlockToAir(pos); } if(cooldown == 0) burnTime += getBurnTime(); else cooldown = getCooldown(); sync(); playSound(); break; } } } } else { if(supertile.getWorld().rand.nextInt(8) == 0) doBurnParticles(); burnTime--; if(burnTime == 0) { cooldown = getCooldown(); sync(); } } } public void doBurnParticles() { Botania.proxy.wispFX(supertile.getPos().getX() + 0.55 + Math.random() * 0.2 - 0.1, supertile.getPos().getY() + 0.55 + Math.random() * 0.2 - 0.1, supertile.getPos().getZ() + 0.5, 0.05F, 0.05F, 0.7F, (float) Math.random() / 6, (float) -Math.random() / 60); } public Material getMaterialToSearchFor() { return Material.WATER; } public Block getBlockToSearchBelow() { return null; } public void playSound() { supertile.getWorld().playSound(null, supertile.getPos(), SoundEvents.ENTITY_GENERIC_DRINK, SoundCategory.BLOCKS, 0.01F, 0.5F + (float) Math.random() * 0.5F); } public int getBurnTime() { return 40; } @Override public RadiusDescriptor getRadius() { return new RadiusDescriptor.Square(toBlockPos(), 1); } @Override public int getMaxMana() { return 150; } @Override public int getColor() { return 0x532FE0; } @Override public LexiconEntry getEntry() { return LexiconData.hydroangeas; } @Override public void writeToPacketNBT(NBTTagCompound cmp) { super.writeToPacketNBT(cmp); cmp.setInteger(TAG_BURN_TIME, burnTime); cmp.setInteger(TAG_COOLDOWN, cooldown); } @Override public void readFromPacketNBT(NBTTagCompound cmp) { super.readFromPacketNBT(cmp); burnTime = cmp.getInteger(TAG_BURN_TIME); cooldown = cmp.getInteger(TAG_COOLDOWN); } @Override public void populateDropStackNBTs(List<ItemStack> drops) { super.populateDropStackNBTs(drops); int cooldown = this.cooldown; if(burnTime > 0) cooldown = getCooldown(); if(cooldown > 0) ItemNBTHelper.setInt(drops.get(0), TAG_COOLDOWN, getCooldown()); } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) { super.onBlockPlacedBy(world, pos, state, entity, stack); cooldown = ItemNBTHelper.getInt(stack, TAG_COOLDOWN, 0); } @Override public boolean canGeneratePassively() { return burnTime > 0; } @Override public int getDelayBetweenPassiveGeneration() { boolean rain = supertile.getWorld().getBiome(supertile.getPos()).getRainfall() > 0 && (supertile.getWorld().isRaining() || supertile.getWorld().isThundering()); return rain ? 2 : 3; } public int getCooldown() { return 0; } @Override public boolean isPassiveFlower() { return true; } }