Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new tool: Decorator's Trowel #3963

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adds new tool: Trowel
  • Loading branch information
querns committed Feb 17, 2025
commit f433c0f3635ce40d11f1f1dcfd2ed0bfebf34da7
4 changes: 3 additions & 1 deletion src/main/java/gregtech/api/enums/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,9 @@ public enum ItemIcons implements IIconContainer, Runnable {
POCKET_MULTITOOL_SCREWDRIVER,
POCKET_MULTITOOL_WIRECUTTER,
HALO,
HALO_FUZZY;
HALO_FUZZY,
TROWEL,
HANDLE_TROWEL;

public static final IIconContainer[] DURABILITY_BAR = { DURABILITY_BAR_0, DURABILITY_BAR_1, DURABILITY_BAR_2,
DURABILITY_BAR_3, DURABILITY_BAR_4, DURABILITY_BAR_5, DURABILITY_BAR_6, DURABILITY_BAR_7,
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/common/items/IDMetaTool01.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public enum IDMetaTool01 {
POCKET_KNIFE(186),
POCKET_SAW(188),
POCKET_SCREWDRIVER(190),
POCKET_WIRECUTTER(192);
POCKET_WIRECUTTER(192),
TROWEL(194);

public final int ID;

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/gregtech/common/items/MetaGeneratedTool01.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static gregtech.common.items.IDMetaTool01.SOLDERING_IRON_HV;
import static gregtech.common.items.IDMetaTool01.SOLDERING_IRON_LV;
import static gregtech.common.items.IDMetaTool01.SOLDERING_IRON_MV;
import static gregtech.common.items.IDMetaTool01.TROWEL;
import static gregtech.common.items.IDMetaTool01.TURBINE;
import static gregtech.common.items.IDMetaTool01.TURBINE_HUGE;
import static gregtech.common.items.IDMetaTool01.TURBINE_LARGE;
Expand Down Expand Up @@ -81,6 +82,7 @@
import gregtech.common.tools.ToolScrewdriverLV;
import gregtech.common.tools.ToolSoftHammer;
import gregtech.common.tools.ToolSolderingIron;
import gregtech.common.tools.ToolTrowel;
import gregtech.common.tools.ToolTurbineHuge;
import gregtech.common.tools.ToolTurbineLarge;
import gregtech.common.tools.ToolTurbineNormal;
Expand Down Expand Up @@ -512,6 +514,14 @@ public MetaGeneratedTool01() {
new TCAspects.TC_AspectStack(TCAspects.INSTRUMENTUM, 6),
new TCAspects.TC_AspectStack(TCAspects.FABRICO, 3),
new TCAspects.TC_AspectStack(TCAspects.ORDO, 3));
addTool(
TROWEL.ID,
"Decorator's Trowel",
"",
new ToolTrowel(),
new TCAspects.TC_AspectStack(TCAspects.INSTRUMENTUM, 8),
new TCAspects.TC_AspectStack(TCAspects.SENSUS, 4),
new TCAspects.TC_AspectStack(TCAspects.PERDITIO, 2));
initCraftingShapedRecipes();
initCraftingShapelessRecipes();
}
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/gregtech/common/items/behaviors/BehaviorTrowel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package gregtech.common.items.behaviors;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import com.google.common.collect.ImmutableList;

import gregtech.api.items.MetaBaseItem;
import gregtech.api.items.MetaGeneratedTool;

public class BehaviorTrowel extends BehaviourNone {

@Override
public List<String> getAdditionalToolTips(final MetaBaseItem aItem, final List<String> aList,
final ItemStack aStack) {
aList.add(StatCollector.translateToLocal("gt.behaviour.trowel.tooltip1"));
aList.add(StatCollector.translateToLocal("gt.behaviour.trowel.tooltip2"));
return aList;
}

@Override
public boolean onItemUse(final MetaBaseItem aItem, final ItemStack aStack, final EntityPlayer aPlayer, final World aWorld, final int aX, final int aY, final int aZ, final int ordinalSide, final float hitX, final float hitY, final float hitZ) {
if (aWorld.isRemote) {
return false;
}
final ForgeDirection side = ForgeDirection.getOrientation(ordinalSide);
if (null == aPlayer) {
return false;
}
if (!(aItem instanceof MetaGeneratedTool)) {
return false;
}

final ImmutableList.Builder<Integer> builder = ImmutableList.builder();
for (int i = 0; i < 9; i++) {
if (i == aPlayer.inventory.currentItem) {
continue;
}

final ItemStack candidate = aPlayer.inventory.getStackInSlot(i);
if (isValidBlock(candidate)) {
builder.add(i);
}
}
final ImmutableList<Integer> candidates = builder.build();
if (candidates.isEmpty()) {
return false;
}

final int count = candidates.size();
int chosenSlot;
if (count == 1) {
chosenSlot = candidates.get(0);
} else {
chosenSlot = candidates.get(java.util.concurrent.ThreadLocalRandom.current().nextInt(count));
}

final ItemStack itemToPlace = aPlayer.inventory.getStackInSlot(chosenSlot);
if (itemToPlace.getItem() instanceof final ItemBlock blockItem) {
final Block blockToPlace = blockItem.field_150939_a;
if (blockToPlace != null && blockToPlace.getMaterial().blocksMovement()) {
final int newX = aX + side.offsetX;
final int newY = aY + side.offsetY;
final int newZ = aZ + side.offsetZ;
final AxisAlignedBB blockBounds = AxisAlignedBB.getBoundingBox(newX, newY, newZ, newX + 1, newY + 1, newZ + 1);
if (aPlayer.boundingBox.intersectsWith(blockBounds)) {
return false;
}
}
}

final int damage = itemToPlace.getItemDamage();
final int stackSize = itemToPlace.stackSize;

if (aPlayer.capabilities.isCreativeMode || ((MetaGeneratedTool) aItem).doDamage(aStack, 100)) {
// We can guarantee getItem() is non-null here because of the isValidBlock check done previously.
//noinspection DataFlowIssue
final boolean success = itemToPlace.getItem().onItemUse(itemToPlace, aPlayer, aWorld, aX, aY, aZ, side.ordinal(), hitX, hitY, hitZ);

if (aPlayer.capabilities.isCreativeMode) {
itemToPlace.setItemDamage(damage);
itemToPlace.stackSize = stackSize;
}

if (itemToPlace.stackSize < 1) {
aPlayer.inventory.setInventorySlotContents(chosenSlot, null);
}

return success;
}

return false;
}

protected boolean isValidBlock(ItemStack aStack) {
return aStack != null && aStack.getItem() instanceof ItemBlock && aStack.stackSize > 0;
}
}
60 changes: 60 additions & 0 deletions src/main/java/gregtech/common/tools/ToolTrowel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package gregtech.common.tools;

import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;

import gregtech.api.enums.Textures;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.items.MetaGeneratedTool;
import gregtech.common.items.behaviors.BehaviorTrowel;

public class ToolTrowel extends GTTool {

private static final String TYPE_NAME = "trowel";

@Override
public float getBaseDamage() {
return 0;
}

@Override
public boolean isMinableBlock(final Block aBlock, final int aMetaData) {
return false;
}

@Override
public IIconContainer getIcon(final boolean aIsToolHead, final ItemStack aStack) {
return aIsToolHead ? Textures.ItemIcons.TROWEL : Textures.ItemIcons.HANDLE_TROWEL;
}

@Override
public short[] getRGBa(final boolean aIsToolHead, final ItemStack aStack) {
return aIsToolHead ? MetaGeneratedTool.getPrimaryMaterial(aStack).mRGBa
: MetaGeneratedTool.getSecondaryMaterial(aStack).mRGBa;
}

@Override
public String getToolTypeName() {
return TYPE_NAME;
}

@Override
public void onStatsAddedToTool(final MetaGeneratedTool aItem, final int aID) {
aItem.addItemBehavior(aID, new BehaviorTrowel());
}

@Override
public IChatComponent getDeathMessage(final EntityLivingBase aPlayer, final EntityLivingBase aEntity) {
return new ChatComponentText(
EnumChatFormatting.RED + aEntity.getCommandSenderName()
+ EnumChatFormatting.WHITE
+ " was taken to trowel town by "
+ EnumChatFormatting.GREEN
+ aPlayer.getCommandSenderName()
+ EnumChatFormatting.WHITE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ public void registerOre(OrePrefixes aPrefix, Materials aMaterial, String aOreDic
OrePrefixes.toolHeadFile.get(aMaterial), 'E', OrePrefixes.plate.get(aMaterial), 'F',
OrePrefixes.spring.get(aMaterial), 'G', Dyes.dyeBlue });

GTModHandler.addCraftingRecipe(
MetaGeneratedTool01.INSTANCE
.getToolWithStats(IDMetaTool01.TROWEL.ID, 1, aMaterial, aMaterial.mHandleMaterial, null),
GTModHandler.RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS | GTModHandler.RecipeBits.BUFFERED,
new Object[] { " d", "SSC", "fPP", 'S', OrePrefixes.stick.get(aMaterial.mHandleMaterial), 'C',
OrePrefixes.screw.get(aMaterial), 'P', OrePrefixes.plate.get(aMaterial) });

}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ gt.behaviour.paintspray.infinite.tooltip.prevent_shake=%s-Middle Click: Allow/pr
gt.behaviour.paintspray.infinite.tooltip.ctrl_pc=Ctrl
gt.behaviour.paintspray.infinite.tooltip.ctrl_mac=Command

gt.behaviour.trowel.tooltip1=Places a random block from your hotbar
gt.behaviour.trowel.tooltip2=§o"Don't forget to bring a trowel!"§r -§cQuerns§r

GT5U.hatch.disableFilter.true=Input Filter §cOff§r
GT5U.hatch.disableFilter.false=Input Filter §aOn§r
GT5U.hatch.disableMultiStack.true=Multi Stack Input §cOff§r
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading