Skip to content

Commit

Permalink
fix: photomask set creative-only shortcut working in survival
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTJP committed Dec 24, 2024
1 parent 3b32a6f commit 11d79ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,26 @@ public void appendHoverText(ItemStack stack, @Nullable Level p_77624_2_, List<Co

@Override
public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
// Allow creative mode players to directly obtain a Fabricated Gate
var player = context.getPlayer();
if (player == null || !player.isCreative()) {
return InteractionResult.PASS;
}

assert context.getPlayer() != null;
if (!context.getPlayer().isCreative()) return InteractionResult.PASS;
if (!canFabricate(stack.getTag())) {
return InteractionResult.PASS;
}

// Creative mode bypass: Convert blueprint directly to gate block
// Always prioritize placing blueprint on IC workbench
BlockState blockState = context.getLevel().getBlockState(context.getClickedPos());
if (blockState.getBlock() == FabricationBlocks.IC_WORKBENCH_BLOCK.get()) { return InteractionResult.PASS; }

if (!canFabricate(stack.getTag())) {
if (blockState.getBlock() == FabricationBlocks.IC_WORKBENCH_BLOCK.get()) {
return InteractionResult.PASS;
}

ItemStack gate = GateType.FABRICATED_GATE.makeStack();
gate.setTag(createFabricationCopy(Objects.requireNonNull(stack.getTag())));

context.getPlayer().addItem(gate);
player.addItem(gate);
return InteractionResult.SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mrtjp.projectred.fabrication.item;

import mrtjp.projectred.fabrication.init.FabricationBlocks;
import mrtjp.projectred.fabrication.init.FabricationItems;
import mrtjp.projectred.integration.GateType;
import net.minecraft.network.chat.Component;
Expand All @@ -9,11 +10,15 @@
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;

import static mrtjp.projectred.fabrication.editor.EditorDataUtils.canFabricate;
import static mrtjp.projectred.fabrication.editor.EditorDataUtils.createFabricationCopy;

public class PhotomaskSetItem extends Item {

public PhotomaskSetItem() {
Expand All @@ -28,16 +33,21 @@ public void appendHoverText(ItemStack stack, @Nullable Level p_77624_2_, List<Co

@Override
public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
// Allow creative mode players to directly obtain a Fabricated Gate
var player = context.getPlayer();
if (player == null || !player.isCreative()) {
return InteractionResult.PASS;
}

if (stack.getTag() != null && context.getPlayer() != null) {
ItemStack gate = GateType.FABRICATED_GATE.makeStack();
gate.setTag(stack.getTag());

context.getPlayer().addItem(gate);
return InteractionResult.SUCCESS;
if (!canFabricate(stack.getTag())) {
return InteractionResult.PASS;
}

return InteractionResult.PASS;
ItemStack gate = GateType.FABRICATED_GATE.makeStack();
gate.setTag(createFabricationCopy(Objects.requireNonNull(stack.getTag())));

player.addItem(gate);
return InteractionResult.SUCCESS;
}

public static ItemStack createDieStack(ItemStack photomask, int count) {
Expand Down

0 comments on commit 11d79ac

Please sign in to comment.