use of com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem in project AgriCraft by AgriCraft.
the class SeedAnalyzerContainer method transferStackInSlot.
@Nonnull
@Override
public ItemStack transferStackInSlot(@Nonnull PlayerEntity playerIn, int index) {
ItemStack itemStack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack()) {
ItemStack slotStack = slot.getStack();
itemStack = slotStack.copy();
if (index <= 1) {
// shift-click in seed/journal slot
if (!this.mergeItemStack(slotStack, 2, 38, true)) {
return ItemStack.EMPTY;
}
} else if (index <= 38) {
// shift-click in inventory slots
if (slotStack.getItem() instanceof IAgriSeedItem) {
if (!this.mergeItemStack(slotStack, 0, 1, false)) {
return ItemStack.EMPTY;
}
} else if (slotStack.getItem() instanceof IAgriJournalItem) {
if (!this.mergeItemStack(slotStack, 1, 2, false)) {
return ItemStack.EMPTY;
}
}
}
if (slotStack.isEmpty()) {
slot.putStack(ItemStack.EMPTY);
} else {
slot.onSlotChanged();
}
if (slotStack.getCount() == itemStack.getCount()) {
return ItemStack.EMPTY;
}
slot.onTake(playerIn, slotStack);
}
return itemStack;
}
use of com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem in project AgriCraft by AgriCraft.
the class BlockSeedAnalyzer method onBlockActivated.
@Override
@Deprecated
@SuppressWarnings("deprecation")
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
if (hand == Hand.OFF_HAND) {
return ActionResultType.FAIL;
}
TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof TileEntitySeedAnalyzer)) {
return ActionResultType.FAIL;
}
TileEntitySeedAnalyzer analyzer = (TileEntitySeedAnalyzer) tile;
ItemStack heldItem = player.getHeldItem(hand);
// debugging
if (heldItem.getItem() instanceof ItemDebugger) {
return ActionResultType.PASS;
}
// Player is sneaking: insertion / extraction logic
if (player.isSneaking()) {
// No sneak-action on the client
if (world.isRemote()) {
return ActionResultType.PASS;
}
// Try extracting the seed
if (analyzer.hasSeed()) {
this.extractSeed(analyzer, player);
return ActionResultType.CONSUME;
}
// Try inserting a seed
if (heldItem.getItem() instanceof IAgriSeedItem) {
player.getHeldItem(hand).setCount(analyzer.insertSeed(heldItem).getCount());
return ActionResultType.CONSUME;
}
// Try extracting the journal
if (analyzer.hasJournal()) {
// Only allow extraction of journal with empty hand
if (heldItem.isEmpty()) {
this.extractJournal(analyzer, player);
return ActionResultType.CONSUME;
}
return ActionResultType.FAIL;
}
// Try inserting a journal
if (heldItem.getItem() instanceof IAgriJournalItem) {
if (analyzer.insertJournal(heldItem).isEmpty()) {
heldItem.shrink(1);
}
return ActionResultType.CONSUME;
}
return ActionResultType.FAIL;
} else {
// On the client, inspect the genome
if (world.isRemote()) {
if (!analyzer.isObserved()) {
if (this.isViewBlocked(world, pos, ORIENTATION.fetch(state))) {
player.sendMessage(AgriToolTips.MSG_ANALYZER_VIEW_BLOCKED, Util.DUMMY_UUID);
} else {
analyzer.setObserving(true);
}
}
}
return ActionResultType.CONSUME;
}
}
use of com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem in project AgriCraft by AgriCraft.
the class MysticalAgricultureCompatClient method registerItemColors.
// Registers the item colors for recoloring dynamically colored MA seeds
private static void registerItemColors() {
Minecraft.getInstance().getItemColors().register((stack, tintIndex) -> {
if (stack.getItem() instanceof IAgriSeedItem) {
IAgriSeedItem seedItem = (IAgriSeedItem) stack.getItem();
String id = seedItem.getPlant(stack).getId();
int color = colorForFlower(id);
return color == -1 ? -1 : (0xFF << 24) + color;
}
return -1;
}, AgriItemRegistry.getInstance().seed);
}
Aggregations