Skip to content

Commit

Permalink
fix builder's glove and redstone pouch crashing in jars
Browse files Browse the repository at this point in the history
  • Loading branch information
nexonerr committed Aug 14, 2023
1 parent c681791 commit 656c147
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) {
this.minecraft.player.closeContainer();
}

return !this.text.keyPressed(pKeyCode, pScanCode, pModifiers) && !this.text.canConsumeInput() ? super.keyPressed(pKeyCode, pScanCode, pModifiers) : true;
return this.text.keyPressed(pKeyCode, pScanCode, pModifiers) || this.text.canConsumeInput() || super.keyPressed(pKeyCode, pScanCode, pModifiers);
}

public void renderFg(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public InteractionResult useOn(UseOnContext pContext) {
int toPlace = (int) (Math.random() * (slotList.size()));
BlockHitResult hitResult = null;
try {
hitResult = (BlockHitResult) ObfuscationReflectionHelper.findMethod(pContext.getClass(), "getHitResult").invoke(pContext);
} catch (IllegalAccessException | InvocationTargetException e) {
hitResult = ObfuscationReflectionHelper.getPrivateValue(UseOnContext.class,pContext,"f_43705_");
} catch (Exception e) {
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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.Block;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
Expand All @@ -39,6 +40,8 @@ public RedstonePouchItem(Properties properties) {
@Override
public InteractionResult useOn(UseOnContext pContext) {

if ((pContext.getLevel().isClientSide)) return InteractionResult.sidedSuccess(true);

AtomicReference<InteractionResult> result = new AtomicReference<>(InteractionResult.FAIL);

//Block Place Function - from builder's glove
Expand All @@ -48,8 +51,8 @@ public InteractionResult useOn(UseOnContext pContext) {

BlockHitResult hitResult = null;
try {
hitResult = (BlockHitResult) ObfuscationReflectionHelper.findMethod(pContext.getClass(),"getHitResult").invoke(pContext);
} catch (IllegalAccessException | InvocationTargetException e) {
hitResult = ObfuscationReflectionHelper.getPrivateValue(UseOnContext.class,pContext,"f_43705_");
} catch (Exception e) {
e.printStackTrace();
}

Expand All @@ -58,7 +61,10 @@ public InteractionResult useOn(UseOnContext pContext) {
UseOnContext customContext = new UseOnContext(pContext.getLevel(), pContext.getPlayer(), pContext.getHand(), blockStack, hitResult);
result.set(blockStack.getItem().useOn(customContext));

if (result.get() != InteractionResult.FAIL) handler.extractItem(RedstonePouchCapabilityProvider.getFirstNonEmptySlot(handler),1,false);
/*if (result.get() != InteractionResult.FAIL) {
handler.extractItem(RedstonePouchCapabilityProvider.getFirstNonEmptySlot(handler),1,false);
System.out.println("he");
}*/

pouchItem.getOrCreateTag().put("inventory", ((ItemStackHandler) handler).serializeNBT());
} else {
Expand Down

0 comments on commit 656c147

Please sign in to comment.