Skip to content

Commit

Permalink
feat: make it possible to sneak click Vial Holders to bulk insert or …
Browse files Browse the repository at this point in the history
…extract vials
  • Loading branch information
Elenterius committed Nov 1, 2024
1 parent e06ee55 commit 51719b4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,15 +618,15 @@ private void addBlockTranslations() {
addBlock(ModBlocks.FULL_FLESH_DOOR, "Wide Flesh Door", "A wide sliding door made of flesh...");
addBlock(ModBlocks.FLESH_SPIKE, "Flesh Spike", """
A deadly trap fashioned from the amalgamation of reinforced bone and sinew. Approach with caution, for any contact will inflict considerable harm.
Multiple spikes can be meticulously placed within a single location, intensifying their lethality.""");
addBlock(ModBlocks.FLESH_LADDER, "Flesh Ladder", "Ladder mainly made of bones and a little bit of flesh...");
addBlock(ModBlocks.YELLOW_BIO_LANTERN, "Yellow Bio-Lantern", "A bioluminescent light source that is energy-efficient and environmentally friendly.");
addBlock(ModBlocks.BLUE_BIO_LANTERN, "Blue Bio-Lantern", "A bioluminescent light source. This one is blue!");
addBlock(ModBlocks.PRIMORDIAL_BIO_LANTERN, "Bloom-Lantern", "A magenta light source made from a bioluminescent berry.");
addBlock(ModBlocks.BLOOMLIGHT, "Bloomlight", "A malignant light source. This one is magenta as well!");
addBlock(ModBlocks.TENDON_CHAIN, "Tendon Chain", "A chain made of tendons.");
addBlock(ModBlocks.VIAL_HOLDER, "Vial Holder", "Display and organize your serums.");
addBlock(ModBlocks.VIAL_HOLDER, "Vial Holder", "Display and organize your serums.\nSneak click to bulk insert or extract vials.");
addBlock(ModBlocks.IMPERMEABLE_MEMBRANE, "Impermeable Membrane", "Gelatinous-like membrane reinforced with elastic fibers.");
addBlock(ModBlocks.IMPERMEABLE_MEMBRANE_PANE, "Impermeable Membrane Pane", "Gelatinous-like membrane reinforced with elastic fibers.");
addBlock(ModBlocks.BABY_PERMEABLE_MEMBRANE, "Baby-Permeable Membrane", "Gelatinous-like membrane reinforced with elastic fibers.\n\nBaby mobs can diffuse through the membrane.");
Expand All @@ -647,10 +647,10 @@ private void addBlockTranslations() {

addBlock(ModBlocks.MODULAR_LARYNX, "Modular Larynx", """
Similar to a Jukebox but made of an adaptive larynx. Capable of reproducing the sounds of a mob via the insertion of essence and redstone power.
Right-Click with Mob Essence in hand to insert it.
Or Shift Right-Click with empty hand to extract Mob Essence.
You can also use automation like Hoppers to insert and extract the Mob Essence.
""");
add(TextComponentUtil.getItemTooltipKey(ModBlocks.MODULAR_LARYNX.get()) + ".1", "When Placed on Soul Sand or Soil:");
Expand Down
2 changes: 1 addition & 1 deletion src/generated/resources/assets/biomancy/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"block.biomancy.tendon_chain": "Tendon Chain",
"block.biomancy.tendon_chain.tooltip": "A chain made of tendons.",
"block.biomancy.vial_holder": "Vial Holder",
"block.biomancy.vial_holder.tooltip": "Display and organize your serums.",
"block.biomancy.vial_holder.tooltip": "Display and organize your serums.\nSneak click to bulk insert or extract vials.",
"block.biomancy.impermeable_membrane": "Impermeable Membrane",
"block.biomancy.impermeable_membrane.tooltip": "Gelatinous-like membrane reinforced with elastic fibers.",
"block.biomancy.impermeable_membrane_pane": "Impermeable Membrane Pane",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {

if (level.getBlockEntity(pos) instanceof VialHolderBlockEntity vialHolder) {
ItemStack stackInHand = player.getItemInHand(hand);
boolean isHandEmpty = stackInHand.isEmpty();

if (player.isSecondaryUseActive()) {
if (!level.isClientSide) {
if (isHandEmpty) {
vialHolder.extractAllVials(player);
}
else {
ItemStack remainder = vialHolder.insertAllVials(stackInHand);
player.setItemInHand(hand, remainder);
}
}
return InteractionResult.sidedSuccess(level.isClientSide);
}

Direction facing = getFacing(state);
Vec3 hitLocation = hit.getLocation();

Expand All @@ -147,14 +163,11 @@ else if (v > min) {
if (!vialHolder.isValidSlotIndex(index)) return InteractionResult.FAIL;

boolean isVialSlotEmpty = !vialHolder.hasVial(index);
ItemStack stackInHand = player.getItemInHand(hand);
boolean isHandEmpty = stackInHand.isEmpty();

if (isHandEmpty) {
if (isVialSlotEmpty) return InteractionResult.FAIL;

if (!level.isClientSide) vialHolder.extractVial(player, index);

}
else {
if (!isVialSlotEmpty) return InteractionResult.FAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,35 @@ public void extractVial(Player player, int slot) {
}
}

public void extractAllVials(Player player) {
for (int slot = 0; slot < inventory.getSlots(); slot++) {
ItemStack stack = inventory.extractItem(slot, inventory.getSlotLimit(slot), false);
if (!stack.isEmpty() && !player.addItem(stack)) {
player.drop(stack, false);
}
}
}

public ItemStack insertVial(ItemStack stack, int slot) {
if (slot < 0 || slot >= inventory.getSlots()) return stack;
return inventory.insertItem(slot, stack, false);
}

public ItemStack insertAllVials(ItemStack stack) {
for (int slot = 0; slot < inventory.getSlots(); slot++) {
if (stack.isEmpty()) return stack;
stack = inventory.insertItem(slot, stack, false);
}
return stack;
}

public boolean hasVials() {
for (int slot = 0; slot < inventory.getSlots(); slot++) {
if (inventory.getStackInSlot(slot).getItem() instanceof SerumContainer) return true;
}
return false;
}

public boolean hasVial(int slot) {
if (slot < 0 || slot >= inventory.getSlots()) return false;
return inventory.getStackInSlot(slot).getItem() instanceof SerumContainer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.elenterius.biomancy.event;

import com.github.elenterius.biomancy.BiomancyMod;
import com.github.elenterius.biomancy.api.serum.SerumContainer;
import com.github.elenterius.biomancy.block.vialholder.VialHolderBlock;
import com.github.elenterius.biomancy.item.ChrysalisBlockItem;
import com.github.elenterius.biomancy.item.extractor.ExtractorItem;
import com.github.elenterius.biomancy.item.injector.InjectorItem;
Expand All @@ -11,6 +13,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.entity.PartEntity;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

Expand All @@ -36,6 +39,13 @@ else if (target instanceof LivingEntity livingEntity) {
}
}

@SubscribeEvent
public static void onPlayerInteractWithBlock(final PlayerInteractEvent.RightClickBlock event) {
if (event.getItemStack().getItem() instanceof SerumContainer && event.getLevel().getBlockState(event.getPos()).getBlock() instanceof VialHolderBlock) {
event.setUseBlock(Event.Result.ALLOW);
}
}

private static void interactWithParent(PlayerInteractEvent.EntityInteract event, ItemStack stack, Item item, PartEntity<?> partEntity) {
Entity parent = getParent(partEntity);
if (parent instanceof LivingEntity livingEntity) {
Expand Down

0 comments on commit 51719b4

Please sign in to comment.