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;
}
}
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;
}
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;
}
}
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());
}
}
}
}
}
}
}
}
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;
}
Aggregations