add shearing to the aura field creator

This commit is contained in:
Ellpeck 2019-01-31 18:58:31 +01:00
parent 8aef58566c
commit cbe9b18757
3 changed files with 29 additions and 5 deletions

View file

@ -49,6 +49,7 @@ public class BlockFieldCreator extends BlockContainerImpl {
TileEntityFieldCreator otherCreator = (TileEntityFieldCreator) otherTile;
otherCreator.connectionOffset = pos.subtract(stored);
otherCreator.isMain = false;
otherCreator.sendToClients();
compound.removeTag(key);

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
@ -8,6 +9,8 @@ import de.ellpeck.naturesaura.packet.PacketParticleStream;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -17,6 +20,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
@ -24,6 +28,8 @@ import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fluids.IFluidBlock;
import java.util.List;
public class TileEntityFieldCreator extends TileEntityImpl implements ITickable {
public BlockPos connectionOffset;
@ -87,6 +93,7 @@ public class TileEntityFieldCreator extends TileEntityImpl implements ITickable
if (this.world.getTotalWorldTime() % 40 == 0)
chunk.drainAura(spot, 100);
boolean shears = this.shears() || creator.shears();
Vec3d dist = new Vec3d(
this.pos.getX() - connectedPos.getX(),
this.pos.getY() - connectedPos.getY(),
@ -112,15 +119,21 @@ public class TileEntityFieldCreator extends TileEntityImpl implements ITickable
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer) this.world);
if (!MinecraftForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.world, pos, state, fake))) {
NonNullList<ItemStack> drops = NonNullList.create();
block.getDrops(drops, this.world, pos, state, 0);
boolean shearBlock = shears && block instanceof IShearable;
List<ItemStack> drops;
if (shearBlock && ((IShearable) block).isShearable(ItemStack.EMPTY, this.world, pos))
drops = ((IShearable) block).onSheared(ItemStack.EMPTY, this.world, pos, 0);
else {
drops = NonNullList.create();
block.getDrops((NonNullList) drops, this.world, pos, state, 0);
}
float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.world, pos, state, 0, 1, false, fake);
if (chance > 0 && this.world.rand.nextFloat() <= chance) {
this.world.destroyBlock(pos, false);
for (ItemStack stack : drops)
Block.spawnAsEntity(this.world, pos, stack);
chunk.drainAura(spot, 300);
chunk.drainAura(spot, shearBlock ? 1000 : 300);
this.sendParticles();
}
}
@ -129,6 +142,16 @@ public class TileEntityFieldCreator extends TileEntityImpl implements ITickable
}
}
public boolean shears() {
List<EntityItemFrame> frames = Helper.getAttachedItemFrames(this.world, this.pos);
for (EntityItemFrame frame : frames) {
ItemStack stack = frame.getDisplayedItem();
if (!stack.isEmpty() && stack.getItem() instanceof ItemShears)
return true;
}
return false;
}
private void sendParticles() {
for (int j = 0; j < 2; j++) {
BlockPos p = j == 0 ? this.pos : this.getConnectedPos();

View file

@ -13,8 +13,8 @@
"text": "To set up a field like this, two $(item)Aura Field Creators$() need to be placed a couple of blocks apart. Then, interacting with one of them while sneaking and interacting with the other while not sneaking will cause a connection between the two to form.$(br)Once supplying one of them with a $(thing)redstone signal$(), and after a short channel time, the field will be created between the two, allowing any blocks being placed there to be broken and their items being dropped into the world."
},
{
"type":"text",
"text":"Of course, breaking blocks and especially the initial channel time will require a bit of $(aura) from the environment. Additionally, while the field is active, a small amount is consumed as a sort of upkeep cost."
"type": "text",
"text": "Of course, breaking blocks and especially the initial channel time will require a bit of $(aura) from the environment. Additionally, while the field is active, a small amount is consumed as a sort of upkeep cost.$(br)Any botanist that requires items gained from $(thing)shearing$() certain blocks doesn't have to worry: Placing an $(item)Item Frame$() with $(item)Shears$() on any of the two $(item)Aura Field Creators$() will cause all shearable blocks inbetween to be sheared with all others being harvested normally."
},
{
"type": "crafting",