Skip to content

Commit

Permalink
make drills place torches instead of any block next to it
Browse files Browse the repository at this point in the history
  • Loading branch information
botn365 committed Apr 30, 2024
1 parent 0221355 commit 6804375
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/main/java/gregtech/common/tools/GT_Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,32 @@ public static boolean placeSideBlock(ItemStack stack, World world, int x, int y,
return used;
}

public static boolean placeInventoryBlock(int index, World world, int x, int y, int z, int sidehit, EntityPlayer playerEntity, float hitX, float hitY, float hitZ) {
boolean used = false;
int hotBarSlot = playerEntity.inventory.currentItem;
ItemStack nearbyStack = playerEntity.inventory.getStackInSlot(index);
Item item = nearbyStack.getItem();
if (item instanceof ItemBlock) {
int posX = x;
int posY = y;
int posZ = z;

AxisAlignedBB blockBounds = AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1);
AxisAlignedBB playerBounds = playerEntity.boundingBox;
Block blockToPlace = ((ItemBlock) item).field_150939_a;
if(blockToPlace.getMaterial().blocksMovement())
{
if (playerBounds.intersectsWith(blockBounds))
return false;
}
used = item.onItemUse(nearbyStack, playerEntity, world, x, y, z, sidehit, hitX, hitY, hitZ);
if (nearbyStack.stackSize < 1) {
playerEntity.inventory.setInventorySlotContents(hotBarSlot + 1, null);
}
}
return used;
}

@Override
public void toolTip(List aList, ItemStack aStack, EntityPlayer aPlayer, IToolStats stats) {
}
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/gregtech/common/tools/GT_Tool_Drill_LV.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.util.GT_ToolHarvestHelper;
import gregtech.api.util.GT_Utility;
import lombok.val;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.stats.AchievementList;
import net.minecraft.util.*;
import net.minecraft.world.World;

import java.util.List;
import java.util.Locale;

public class GT_Tool_Drill_LV extends GT_Tool implements IAOETool {
@Override
Expand Down Expand Up @@ -211,7 +215,15 @@ public boolean onItemUse(ItemStack stack, World world, int x, int y, int z, int
if (playerEntity.isSneaking()) {
return false;
} else {
return placeSideBlock(stack, world, x, y, z, sidehit, playerEntity, hitX, hitY, hitZ);
//place torch
val inv = playerEntity.inventory;
for (int i = 0; i < inv.mainInventory.length; i++) {
if (inv.mainInventory[i] == null) continue;
if (inv.mainInventory[i].getItem().getUnlocalizedName().toLowerCase(Locale.ENGLISH).contains("torch")) {
return placeInventoryBlock(i, world, x, y, z, sidehit, playerEntity, hitX, hitY, hitZ);
}
}
return false;
}
}

Expand Down

0 comments on commit 6804375

Please sign in to comment.