make the ender crate use aura

This commit is contained in:
Ellpeck 2019-02-18 13:00:54 +01:00
parent 00b1141a08
commit 1502348da8
3 changed files with 62 additions and 5 deletions

View file

@ -6,7 +6,6 @@ import de.ellpeck.naturesaura.blocks.tiles.render.RenderEnderCrate;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer;
@ -16,7 +15,6 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -37,8 +35,10 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileEntityEnderCrate) {
TileEntityEnderCrate crate = (TileEntityEnderCrate) tile;
if (crate.canOpen())
if (crate.canOpen()) {
crate.drainAura(5000);
playerIn.openGui(NaturesAura.MOD_ID, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
}
}
return true;

View file

@ -1,20 +1,68 @@
package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.misc.IWorldData;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nonnull;
public class TileEntityEnderCrate extends TileEntityImpl {
private final IItemHandlerModifiable wrappedEnderStorage = new IItemHandlerModifiable() {
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
this.getStorage().setStackInSlot(slot, stack);
}
@Override
public int getSlots() {
return this.getStorage().getSlots();
}
@Nonnull
@Override
public ItemStack getStackInSlot(int slot) {
return this.getStorage().getStackInSlot(slot);
}
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
ItemStack remain = this.getStorage().insertItem(slot, stack, simulate);
if (!simulate)
TileEntityEnderCrate.this.drainAura((stack.getCount() - remain.getCount()) * 200);
return remain;
}
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
ItemStack extracted = this.getStorage().extractItem(slot, amount, simulate);
if (!simulate)
TileEntityEnderCrate.this.drainAura(extracted.getCount() * 200);
return extracted;
}
@Override
public int getSlotLimit(int slot) {
return this.getStorage().getSlotLimit(slot);
}
private IItemHandlerModifiable getStorage() {
return IWorldData.getOverworldData(TileEntityEnderCrate.this.world).getEnderStorage(TileEntityEnderCrate.this.name);
}
};
public String name;
@Override
public IItemHandlerModifiable getItemHandler(EnumFacing facing) {
if (this.canOpen())
return IWorldData.getOverworldData(this.world).getEnderStorage(this.name);
return this.wrappedEnderStorage;
return null;
}
@ -58,4 +106,11 @@ public class TileEntityEnderCrate extends TileEntityImpl {
this.name = compound.getString("name");
}
}
public void drainAura(int amount) {
if (amount > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos);
IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, amount);
}
}
}

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
@ -19,8 +20,9 @@ public class ItemEnderAccess extends ItemImpl {
return new ActionResult<>(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
ItemStack stack = playerIn.getHeldItemMainhand();
if (stack.hasDisplayName()) {
if (!worldIn.isRemote)
if (!worldIn.isRemote && NaturesAuraAPI.instance().extractAuraFromPlayer(playerIn, 5000, false)) {
playerIn.openGui(NaturesAura.MOD_ID, 1, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
return new ActionResult<>(EnumActionResult.FAIL, stack);