Search in sources :

Example 1 with Notice

use of pl.asie.charset.lib.notify.Notice in project Charset by CharsetMC.

the class TileShelf method onActivated.

protected boolean onActivated(float hitX, float hitY, float hitZ, ItemStack stack, EntityPlayer player) {
    int slotId = getSlotId(hitX, hitY, hitZ);
    if (slotId < 0)
        return false;
    if (stack.isEmpty()) {
        if (handler.getStackInSlot(slotId).isEmpty()) {
            slotId = toNonBookSlotId(slotId);
        }
        if (!handler.getStackInSlot(slotId).isEmpty()) {
            final int sentSlotId = slotId;
            new Notice(new Vec3d(pos).addVector(hitX, hitY, hitZ), msg -> msg.withItem(handler.getStackInSlot(sentSlotId)).setMessage(new TextComponentString("{ITEM_NAME}{ITEM_INFOS_NEWLINE}"))).sendTo(player);
            return true;
        } else {
            return false;
        }
    } else {
        if (!isBook(stack))
            slotId = toNonBookSlotId(slotId);
        if (isSlotTaken(slotId))
            return false;
        stack = stack.splitStack(1);
        handler.setStackInSlot(slotId, stack);
        markBlockForUpdate();
        return true;
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemUtils(pl.asie.charset.lib.utils.ItemUtils) Constants(net.minecraftforge.common.util.Constants) Properties(pl.asie.charset.lib.Properties) UnlistedPropertyGeneric(pl.asie.charset.lib.utils.UnlistedPropertyGeneric) EnumFacing(net.minecraft.util.EnumFacing) Capability(net.minecraftforge.common.capabilities.Capability) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) TileBase(pl.asie.charset.lib.block.TileBase) Vec3d(net.minecraft.util.math.Vec3d) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) INoticeUpdater(pl.asie.charset.lib.notify.INoticeUpdater) Notice(pl.asie.charset.lib.notify.Notice) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ItemMaterialRegistry(pl.asie.charset.lib.material.ItemMaterialRegistry) ItemHandlerCharset(pl.asie.charset.lib.ui.ItemHandlerCharset) Nullable(javax.annotation.Nullable) Notice(pl.asie.charset.lib.notify.Notice) Vec3d(net.minecraft.util.math.Vec3d) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with Notice

use of pl.asie.charset.lib.notify.Notice in project Charset by CharsetMC.

the class LockEventHandler method unlockOrRaiseError.

public static boolean unlockOrRaiseError(EntityPlayer player, TileEntity tile, Lockable lock) {
    if (player.getEntityWorld().isRemote) {
        return true;
    }
    boolean canUnlock = false;
    for (ItemStack stack : getPotentialKeys(player)) {
        if (!stack.isEmpty() && stack.getItem() instanceof IKeyItem) {
            IKeyItem key = (IKeyItem) stack.getItem();
            canUnlock = key.canUnlock(lock.getLock().getLockKey(), stack);
            if (canUnlock) {
                break;
            }
        }
    }
    if (!canUnlock) {
        ITextComponent displayName = tile.getDisplayName();
        if (displayName == null) {
            displayName = new TextComponentTranslation(tile.getBlockType().getUnlocalizedName() + ".name");
        }
        new Notice(tile, new TextComponentTranslation("container.isLocked", displayName)).sendTo(player);
        player.getEntityWorld().playSound(player, tile.getPos(), SoundEvents.BLOCK_CHEST_LOCKED, SoundCategory.BLOCKS, 1.0f, 1.0f);
    }
    return canUnlock;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Notice(pl.asie.charset.lib.notify.Notice) IKeyItem(pl.asie.charset.api.storage.IKeyItem) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Notice

use of pl.asie.charset.lib.notify.Notice in project Charset by CharsetMC.

the class CompressionShape method craftBegin.

public boolean craftBegin(TileCompressionCrafter sender, EnumFacing sourceDir) {
    if (craftingTickEnd >= world.getTotalWorldTime()) {
        return false;
    }
    Set<EnumFacing> validSides = checkRedstoneLevels(false);
    if (validSides.isEmpty()) {
        return false;
    }
    boolean isBackstuffed = false;
    for (TileCompressionCrafter crafter : compressionCrafters) {
        if (crafter.isBackstuffed()) {
            new Notice(crafter, new TextComponentTranslation("notice.charset.compression.backstuffed"));
            isBackstuffed = true;
        }
    }
    if (isBackstuffed) {
        return false;
    }
    craftingDirections = validSides;
    craftingSourcePos = sender.getPos();
    craftingSourceDir = sourceDir;
    Optional<String> error = craftEnd(true);
    if (!error.isPresent()) {
        craftingTickStart = world.getTotalWorldTime();
        craftingTickEnd = world.getTotalWorldTime() + 20;
        CharsetCraftingCompression.proxy.markShapeRender(sender, this);
        return true;
    } else {
        if (error.get().length() > 0) {
            new Notice(sender, new TextComponentTranslation(error.get())).sendToAll();
        }
        return false;
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Notice(pl.asie.charset.lib.notify.Notice) EnumFacing(net.minecraft.util.EnumFacing)

Example 4 with Notice

use of pl.asie.charset.lib.notify.Notice in project Charset by CharsetMC.

the class BlockCauldronCharset method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
    if (!worldIn.isRemote) {
        TileEntity tile = worldIn.getTileEntity(pos);
        if (tile instanceof TileCauldronCharset) {
            FluidStack stack = ((TileCauldronCharset) tile).getContents();
            float height = (float) pos.getY() + ((TileCauldronCharset) tile).getFluidHeight() / 16.0F;
            if (stack != null && stack.amount > 0 && entityIn.getEntityBoundingBox().minY <= height) {
                if (stack.getFluid() == FluidRegistry.LAVA) {
                    if (!entityIn.isBurning() && stack.amount >= 100 && !entityIn.isImmuneToFire()) {
                        entityIn.setFire(stack.amount / 100);
                        return;
                    }
                } else if (stack.getFluid() == FluidRegistry.WATER) {
                    if (entityIn.isBurning() && stack.amount >= 250) {
                        entityIn.extinguish();
                        ((TileCauldronCharset) tile).drain(250, true);
                        return;
                    }
                }
                if (entityIn instanceof EntityItem) {
                    EntityItem entityItem = (EntityItem) entityIn;
                    ItemStack heldItem = entityItem.getItem();
                    if (!heldItem.isEmpty()) {
                        ItemStack heldItemOne = heldItem.copy();
                        heldItemOne.setCount(1);
                        Optional<CauldronContents> contentsNew = Optional.empty();
                        Optional<ItemStack> fluidResult = FluidUtils.handleTank((IFluidHandler) tile, stack, worldIn, pos, heldItemOne, false, true, false);
                        if (fluidResult.isPresent()) {
                            contentsNew = Optional.of(new CauldronContents(((TileCauldronCharset) tile).getContents(), fluidResult.get()));
                        }
                        if (!contentsNew.isPresent()) {
                            contentsNew = CharsetCraftingCauldron.craft((ICauldron) tile, new CauldronContents(CauldronContents.Source.ENTITY, stack, heldItemOne));
                        }
                        if (contentsNew.isPresent()) {
                            CauldronContents cc = contentsNew.get();
                            if (cc.hasResponse()) {
                                new Notice(tile, cc.getResponse()).sendToAll();
                            } else {
                                if (cc.getHeldItem().isEmpty()) {
                                    heldItem.shrink(1);
                                } else if (cc.getHeldItem().getCount() == 1 && ItemUtils.canMerge(cc.getHeldItem(), heldItem)) {
                                // pass
                                } else {
                                    heldItem.shrink(1);
                                    ItemUtils.spawnItemEntity(worldIn, entityItem.getPositionVector(), cc.getHeldItem(), 0, 0, 0, 0);
                                }
                                ((TileCauldronCharset) tile).setContents(cc.getFluidStack());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Notice(pl.asie.charset.lib.notify.Notice) CauldronContents(pl.asie.charset.module.crafting.cauldron.api.CauldronContents) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) ICauldron(pl.asie.charset.module.crafting.cauldron.api.ICauldron) EntityItem(net.minecraft.entity.item.EntityItem)

Example 5 with Notice

use of pl.asie.charset.lib.notify.Notice in project Charset by CharsetMC.

the class BlockCauldronCharset method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    TileEntity tankEntity = worldIn.getTileEntity(pos);
    ItemStack heldItem = playerIn.getHeldItem(hand);
    if (heldItem.isEmpty()) {
        notice(worldIn, tankEntity, playerIn);
        return true;
    }
    if (isEmptyOrWater(worldIn, pos)) {
        if (super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ)) {
            return true;
        }
    }
    if (hand != EnumHand.MAIN_HAND) {
        return false;
    }
    if (tankEntity instanceof TileCauldronCharset) {
        if (FluidUtils.handleTank((IFluidHandler) tankEntity, ((TileCauldronCharset) tankEntity).getContents(), worldIn, pos, playerIn, hand)) {
            return true;
        }
        if (!heldItem.isEmpty()) {
            FluidStack stack = ((TileCauldronCharset) tankEntity).getContents();
            ItemStack heldItemOne = heldItem.copy();
            heldItemOne.setCount(1);
            Optional<CauldronContents> contentsNew = CharsetCraftingCauldron.craft((ICauldron) tankEntity, new CauldronContents(CauldronContents.Source.HAND, stack, heldItemOne));
            if (contentsNew.isPresent()) {
                if (!worldIn.isRemote) {
                    boolean success = false;
                    CauldronContents cc = contentsNew.get();
                    if (cc.hasResponse()) {
                        new Notice(tankEntity, cc.getResponse()).sendTo(playerIn);
                    } else {
                        if (cc.getHeldItem().isEmpty()) {
                            if (!playerIn.isCreative()) {
                                heldItem.shrink(1);
                            }
                            success = true;
                        } else if (cc.getHeldItem().getCount() == 1 && ItemUtils.canMerge(cc.getHeldItem(), heldItem)) {
                            success = true;
                        } else if (heldItem.getCount() > 1) {
                            if (playerIn.inventory.addItemStackToInventory(cc.getHeldItem())) {
                                heldItem.shrink(1);
                                success = true;
                            }
                        } else if (heldItem.getCount() == 1) {
                            playerIn.setHeldItem(hand, cc.getHeldItem());
                            success = true;
                        }
                        if (success) {
                            ((TileCauldronCharset) tankEntity).setContents(cc.getFluidStack());
                        }
                    }
                }
                return true;
            }
        }
    }
    if (!playerIn.isSneaking()) {
        notice(worldIn, tankEntity, playerIn);
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Notice(pl.asie.charset.lib.notify.Notice) CauldronContents(pl.asie.charset.module.crafting.cauldron.api.CauldronContents) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Notice (pl.asie.charset.lib.notify.Notice)6 ItemStack (net.minecraft.item.ItemStack)5 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)3 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 CauldronContents (pl.asie.charset.module.crafting.cauldron.api.CauldronContents)2 Nullable (javax.annotation.Nullable)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 Vec3d (net.minecraft.util.math.Vec3d)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 Capability (net.minecraftforge.common.capabilities.Capability)1 Constants (net.minecraftforge.common.util.Constants)1 CapabilityItemHandler (net.minecraftforge.items.CapabilityItemHandler)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1