From 0641cc78fd007c3fcace814c00554fe3ad639fe0 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Fri, 1 Nov 2019 14:04:16 -0500 Subject: [PATCH] New quark feature --- .../subtile/generating/SubTileSpectrolus.java | 57 +++++++++++++++---- .../resources/assets/botania/lang/en_us.json | 1 + .../generating_flowers/spectrolus.json | 4 ++ 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileSpectrolus.java b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileSpectrolus.java index 54d800bf6..dc2bbc6e5 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileSpectrolus.java +++ b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileSpectrolus.java @@ -14,13 +14,17 @@ import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.Entity; import net.minecraft.entity.item.ItemEntity; +import net.minecraft.entity.passive.SheepEntity; import net.minecraft.item.DyeColor; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.ItemParticleData; import net.minecraft.particles.ParticleTypes; import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.SoundEvents; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.text.ITextComponent; import net.minecraft.world.server.ServerWorld; @@ -35,12 +39,16 @@ import vazkii.botania.common.lib.LibMisc; import java.awt.*; import java.util.List; +import java.util.function.Predicate; public class SubTileSpectrolus extends TileEntityGeneratingFlower { @ObjectHolder(LibMisc.MOD_ID + ":spectrolus") public static TileEntityType TYPE; private static final String TAG_NEXT_COLOR = "nextColor"; + private static final int WOOL_GEN = 2400; + private static final int SHEEP_GEN = (int) (WOOL_GEN * 1.5); + private static final int BABY_SHEEP_GEN = 1; // you are a monster private static final int RANGE = 1; @@ -57,28 +65,53 @@ public class SubTileSpectrolus extends TileEntityGeneratingFlower { if (getWorld().isRemote) return; - List items = getWorld().getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(getPos().add(-RANGE, -RANGE, -RANGE), getPos().add(RANGE + 1, RANGE + 1, RANGE + 1))); + // sheep need to enter the actual block space + List targets = getWorld().getEntitiesWithinAABB(SheepEntity.class, new AxisAlignedBB(getPos()), Entity::isAlive); + + AxisAlignedBB itemAABB = new AxisAlignedBB(getPos().add(-RANGE, -RANGE, -RANGE), getPos().add(RANGE + 1, RANGE + 1, RANGE + 1)); int slowdown = getSlowdownFactor(); + Predicate selector = e -> (e instanceof ItemEntity && e.isAlive() && ((ItemEntity) e).age >= slowdown); + targets.addAll(getWorld().getEntitiesWithinAABB(Entity.class, itemAABB, selector)); - for(ItemEntity item : items) { - ItemStack stack = item.getItem(); + for(Entity target : targets) { + if (target instanceof SheepEntity) { + SheepEntity sheep = (SheepEntity) target; + if (!sheep.getSheared() && sheep.getFleeceColor() == nextColor) { + addManaAndCycle(sheep.isChild() ? BABY_SHEEP_GEN : SHEEP_GEN); + float pitch = sheep.isChild() ? (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F + 1.5F : (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F + 1.0F; + sheep.playSound(SoundEvents.ENTITY_SHEEP_DEATH, 0.9F, pitch); + sheep.playSound(SoundEvents.ENTITY_GENERIC_EAT, 1, 1); - if(!stack.isEmpty() && item.isAlive() && item.age >= slowdown) { - Block expected = ModBlocks.getWool(nextColor); + ItemStack morbid = new ItemStack(Items.MUTTON); + ((ServerWorld) getWorld()).spawnParticle(new ItemParticleData(ParticleTypes.ITEM, morbid), target.posX, target.posY + target.getEyeHeight(), target.posZ, 20, 0.1D, 0.1D, 0.1D, 0.05D); - if(expected.asItem() == stack.getItem()) { - mana = Math.min(getMaxMana(), mana + 2400); - nextColor = nextColor == DyeColor.BLACK ? DyeColor.WHITE : DyeColor.values()[nextColor.ordinal() + 1]; - sync(); - - ((ServerWorld) getWorld()).spawnParticle(new ItemParticleData(ParticleTypes.ITEM, stack), item.posX, item.posY, item.posZ, 20, 0.1D, 0.1D, 0.1D, 0.05D); + ItemStack wool = new ItemStack(ModBlocks.getWool(sheep.getFleeceColor())); + ((ServerWorld) getWorld()).spawnParticle(new ItemParticleData(ParticleTypes.ITEM, wool), target.posX, target.posY + target.getEyeHeight(), target.posZ, 20, 0.1D, 0.1D, 0.1D, 0.05D); } + sheep.setHealth(0); + } else if (target instanceof ItemEntity) { + ItemStack stack = ((ItemEntity) target).getItem(); - item.remove(); + if(!stack.isEmpty()) { + Block expected = ModBlocks.getWool(nextColor); + + if(expected.asItem() == stack.getItem()) { + addManaAndCycle(WOOL_GEN); + ((ServerWorld) getWorld()).spawnParticle(new ItemParticleData(ParticleTypes.ITEM, stack), target.posX, target.posY, target.posZ, 20, 0.1D, 0.1D, 0.1D, 0.05D); + } + + target.remove(); + } } } } + private void addManaAndCycle(int toAdd) { + mana = Math.min(getMaxMana(), mana + toAdd); + nextColor = nextColor == DyeColor.BLACK ? DyeColor.WHITE : DyeColor.values()[nextColor.ordinal() + 1]; + sync(); + } + @Override public RadiusDescriptor getRadius() { return new RadiusDescriptor.Square(getPos(), RANGE); diff --git a/src/main/resources/assets/botania/lang/en_us.json b/src/main/resources/assets/botania/lang/en_us.json index 96502d172..b95d18e20 100644 --- a/src/main/resources/assets/botania/lang/en_us.json +++ b/src/main/resources/assets/botania/lang/en_us.json @@ -2367,6 +2367,7 @@ "botania.tagline.spectrolus": "Mana from wool", "botania.page.spectrolus0": "The $(1)Spectrolus$(0) is a flower that's particularly fond of the various tones of $(1)Wool$(0). It'll absorb any and all $(1)Wool$(0) blocks dropped nearby and create $(4)Mana$(0) from them.$(p)There's a caveat though. It's picky as to what colors it wants. Starting at white, after it absorbs one piece of $(1)Wool$(0), it'll rotate to the next color in the spectrum.", "botania.page.spectrolus1": "While it consumes all $(1)Wool$(0) around, it'll only create any mana if its of the color it wants, so haphazardly tossing $(1)Wool$(0) at it is a wasteful strategy.$(p)The color it'll absorb properly next can be seen by hovering over the flower with a $(1)Wand of the Forest$(0).", + "botania.page.spectrolus1.5": "The flower is widely known to consume refined wool, but you wonder what would happen if you gave it wool straight \"from the source\"", "botania.page.spectrolus2": "$(o)Taste the Rainbow$().", "botania.entry.rafflowsia": "Rafflowsia", diff --git a/src/main/resources/data/botania/patchouli_books/lexicon/en_us/entries/generating_flowers/spectrolus.json b/src/main/resources/data/botania/patchouli_books/lexicon/en_us/entries/generating_flowers/spectrolus.json index 58e99d6c9..7a3328d96 100644 --- a/src/main/resources/data/botania/patchouli_books/lexicon/en_us/entries/generating_flowers/spectrolus.json +++ b/src/main/resources/data/botania/patchouli_books/lexicon/en_us/entries/generating_flowers/spectrolus.json @@ -13,6 +13,10 @@ "type": "text", "text": "botania.page.spectrolus1" }, + { + "type": "text", + "text": "botania.page.spectrolus1.5" + }, { "type": "petal_apothecary", "text": "botania.page.spectrolus2",