Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 3 additions & 4 deletions src/main/java/gregtech/api/items/toolitem/IToolStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ default Set<String> getToolClasses(ItemStack stack) {
return Collections.emptySet();
}

default void onCraftingUse(ItemStack stack) {
if (ConfigHolder.client.toolCraftingSounds && ForgeHooks.getCraftingPlayer() != null && stack.getItem() instanceof ToolMetaItem<?>) {
EntityPlayer player = ForgeHooks.getCraftingPlayer();
player.getEntityWorld().playSound(player, player.getPosition(), ((ToolMetaItem<?>) stack.getItem()).getItem(stack).getSound(), SoundCategory.PLAYERS, 1, 1);
default void onCraftingUse(ItemStack stack, EntityPlayer player) {
if (ConfigHolder.client.toolCraftingSounds && player != null && stack.getItem() instanceof ToolMetaItem<?>) {
player.getEntityWorld().playSound(null, player.getPosition(), ((ToolMetaItem<?>) stack.getItem()).getItem(stack).getSound(), SoundCategory.PLAYERS, 1, 1);
Comment thread
bruberu marked this conversation as resolved.
Outdated
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public ItemStack getContainerItem(ItemStack stack) {
if (metaToolValueItem.toolStats != null) {
IToolStats toolStats = metaToolValueItem.toolStats;
int toolDamagePerCraft = toolStats.getToolDamagePerContainerCraft(stack);
toolStats.onCraftingUse(stack);
toolStats.onCraftingUse(stack, ForgeHooks.getCraftingPlayer());
boolean canApplyDamage = damageItem(stack, ForgeHooks.getCraftingPlayer(), toolDamagePerCraft, false);
if (!canApplyDamage) return stack;
}
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import gregtech.api.items.IToolItem;
import gregtech.api.items.metaitem.MetaItem;
import gregtech.api.items.metaitem.stats.IItemBehaviour;
import gregtech.api.items.toolitem.ToolMetaItem;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.metatileentity.WorkableTieredMetaTileEntity;
Expand Down Expand Up @@ -87,10 +88,19 @@ public static Stream<Object> flatten(Object[] array) {
return Arrays.stream(array).flatMap(o -> o instanceof Object[] ? flatten((Object[]) o) : Stream.of(o));
}

public static void copyInventoryItems(IItemHandler src, IItemHandlerModifiable dest) {
public static void copyInventoryItems(IItemHandler src, IItemHandlerModifiable dest, boolean fixTools) {
for (int i = 0; i < src.getSlots(); i++) {
ItemStack itemStack = src.getStackInSlot(i);
dest.setStackInSlot(i, itemStack.isEmpty() ? ItemStack.EMPTY : itemStack.copy());
if (itemStack.getItem() instanceof ToolMetaItem) {
ItemStack toolStack = itemStack.copy();
NBTTagCompound toolStats = toolStack.getTagCompound().getCompoundTag("GT.ToolStats");
toolStats.setInteger("Dmg", 0);
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setTag("GT.ToolStats", toolStats);
toolStack.setTagCompound(itemTag);
dest.setStackInSlot(i, toolStack);
} else
dest.setStackInSlot(i, itemStack.isEmpty() ? ItemStack.EMPTY : itemStack.copy());
}
}

Expand Down Expand Up @@ -891,7 +901,7 @@ public static boolean isOre(Block block) {
* @return the mean value
*/
public static long mean(@Nonnull long[] values) {
if(values.length == 0L)
if (values.length == 0L)
return 0L;

long sum = 0L;
Expand All @@ -901,7 +911,6 @@ public static long mean(@Nonnull long[] values) {
}

/**
*
* @param world the {@link World} to get the average tick time of
* @return the mean tick time
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package gregtech.common.gui.widget.craftingstation;

import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.IRenderContext;
import gregtech.api.gui.widgets.SlotWidget;
import gregtech.api.util.Position;
import gregtech.common.metatileentities.storage.CraftingRecipeMemory;
import gregtech.common.metatileentities.storage.CraftingRecipeMemory.MemorizedRecipe;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;

import java.util.Collections;
import java.util.List;

public class MemorizedRecipeWidget extends SlotWidget {

private final CraftingRecipeMemory recipeMemory;
Expand All @@ -21,7 +27,7 @@ public class MemorizedRecipeWidget extends SlotWidget {
private final IItemHandlerModifiable craftingGrid;

public MemorizedRecipeWidget(CraftingRecipeMemory recipeMemory, int index, IItemHandlerModifiable craftingGrid, int xPosition, int yPosition) {
super(new ItemStackHandler(1), 0, xPosition, yPosition, false, false);
super(new ItemStackHandler(1), 0, xPosition, yPosition, true, false);
this.recipeMemory = recipeMemory;
this.recipeIndex = index;
this.craftingGrid = craftingGrid;
Expand All @@ -46,11 +52,27 @@ public void detectAndSendChanges() {
@Override
public void drawInForeground(int mouseX, int mouseY) {
super.drawInForeground(mouseX, mouseY);
if (isMouseOverElement(mouseX, mouseY) && slotReference.getHasStack()) {
((ISlotWidget) slotReference).setHover(false);
GlStateManager.disableDepth();
List<String> tooltip = getItemToolTip(slotReference.getStack());
tooltip.add(I18n.format("gregtech.recipe_memory_widget.tooltip.1"));
tooltip.add(I18n.format("gregtech.recipe_memory_widget.tooltip.2"));
drawHoveringText(slotReference.getStack(), tooltip, -1, mouseX, mouseY);
GlStateManager.enableDepth();
}
}

@Override
public void drawInBackground(int mouseX, int mouseY, float partialTicks, IRenderContext context) {
super.drawInBackground(mouseX, mouseY, partialTicks, context);
if (recipeLocked) {
GlStateManager.translate(0, 0, 160);
Position pos = getPosition();
GlStateManager.disableDepth();
GuiTextures.LOCK.draw(pos.x, pos.y + 10, 8, 8);
GlStateManager.enableDepth();
GlStateManager.translate(0, 0, -160);
}
}

Expand All @@ -75,4 +97,5 @@ public ItemStack slotClick(int dragType, ClickType clickTypeIn, EntityPlayer pla
}
return ItemStack.EMPTY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public int getMemorySize() {
public void loadRecipe(int index, IItemHandlerModifiable craftingGrid) {
MemorizedRecipe recipe = memorizedRecipes[index];
if (recipe != null) {
copyInventoryItems(recipe.craftingMatrix, craftingGrid);
copyInventoryItems(recipe.craftingMatrix, craftingGrid, true);
}
}

Expand Down Expand Up @@ -138,7 +138,7 @@ private static MemorizedRecipe deserializeNBT(NBTTagCompound tagCompound) {
private void updateCraftingMatrix(IItemHandler craftingGrid) {
//do not modify crafting grid for locked recipes
if (!recipeLocked) {
copyInventoryItems(craftingGrid, craftingMatrix);
copyInventoryItems(craftingGrid, craftingMatrix, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package gregtech.common.metatileentities.storage;

import com.google.common.collect.Lists;
import gregtech.api.items.toolitem.ToolMetaItem;
import gregtech.api.util.DummyContainer;
import gregtech.common.inventory.itemsource.ItemSourceList;
import gregtech.common.inventory.itemsource.sources.TileItemSource;
import gregtech.common.items.MetaTool;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
Expand Down Expand Up @@ -89,9 +91,9 @@ public void performRecipe(EntityPlayer player) {
cachedRecipeData.performRecipe(player);
//update items in the crafting grid to the actual equivalents used in crafting
InvWrapper invWrapper = new InvWrapper(this.cachedRecipeData.inventory);
copyInventoryItems(invWrapper, craftingGrid);
copyInventoryItems(invWrapper, craftingGrid, true);
//also update items in inventory crafting to avoid useless recipe re-caching
copyInventoryItems(invWrapper, new InvWrapper(inventoryCrafting));
copyInventoryItems(invWrapper, new InvWrapper(inventoryCrafting), false);
itemSourceList.enableCallback();
}
}
Expand All @@ -100,8 +102,16 @@ public void handleItemCraft(ItemStack itemStack, EntityPlayer player, boolean si
itemStack.onCrafting(world, player, 1);
itemStack.getItem().onCreated(itemStack, world, player);
if (!simulate) {
//if we're not simulated, fire the event, unlock recipe and add crafted items
//if we're not simulated, fire the event, unlock recipe and add crafted items, and play sounds
FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemStack, inventoryCrafting);

for (int i = 0; i < inventoryCrafting.getSizeInventory(); i++) {
if (inventoryCrafting.getStackInSlot(i).getItem() instanceof ToolMetaItem) {
ToolMetaItem.MetaToolValueItem toolStack = ((ToolMetaItem<?>) inventoryCrafting.getStackInSlot(i).getItem()).getItem(inventoryCrafting.getStackInSlot(i));
toolStack.getToolStats().onCraftingUse(inventoryCrafting.getStackInSlot(i), player);
}
}

if (cachedRecipe != null && !cachedRecipe.isDynamic()) {
player.unlockRecipes(Lists.newArrayList(cachedRecipe));
}
Expand All @@ -127,7 +137,7 @@ public boolean checkRecipeValid() {

private void notifyStoredItemsChanged() {
if (cachedRecipeData != null) {
copyInventoryItems(craftingGrid, new InvWrapper(this.cachedRecipeData.inventory));
copyInventoryItems(craftingGrid, new InvWrapper(this.cachedRecipeData.inventory), true);
cachedRecipeData.attemptMatchRecipe();
}
}
Expand All @@ -140,7 +150,7 @@ private void updateCurrentRecipe() {
ItemStack resultStack = newRecipe.getCraftingResult(inventoryCrafting).copy();
this.craftingResultInventory.setInventorySlotContents(0, resultStack.copy());
this.cachedRecipeData = new CachedRecipeData(itemSourceList, newRecipe, resultStack.copy());
copyInventoryItems(craftingGrid, new InvWrapper(this.cachedRecipeData.inventory));
copyInventoryItems(craftingGrid, new InvWrapper(this.cachedRecipeData.inventory), true);
this.cachedRecipeData.attemptMatchRecipe();
} else {
this.craftingResultInventory.setInventorySlotContents(0, ItemStack.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ private AbstractWidgetGroup createItemListTab() {
widgetGroup.addWidget(new LabelWidget(5, 30, "gregtech.machine.workbench.storage_note_2"));
CraftingRecipeResolver recipeResolver = getRecipeResolver();
IItemList itemList = recipeResolver == null ? null : recipeResolver.getItemSourceList();
widgetGroup.addWidget(new ItemListGridWidget(2, 45, 9, 5, itemList));
widgetGroup.addWidget(new ItemListGridWidget(11, 45, 8, 5, itemList));
return widgetGroup;
}

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
Builder builder = ModularUI.builder(GuiTextures.BORDERED_BACKGROUND, 176, 221)
Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 221)
.bindPlayerInventory(entityPlayer.inventory, 138);
builder.label(5, 5, getMetaFullName());

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 @@ -986,6 +986,9 @@ metaitem.record.sus.tooltip=§7Leonz - Among Us Drip

gui.widget.incrementButton.default_tooltip=Hold Shift, Ctrl or both to change the amount

gregtech.recipe_memory_widget.tooltip.1=§7Left click to automatically input this recipe into the crafting grid
gregtech.recipe_memory_widget.tooltip.2=§7Shift click to lock/unlock this recipe

cover.filter.blacklist.disabled=Whitelist
cover.filter.blacklist.enabled=Blacklist

Expand Down