Skip to content

Commit

Permalink
Small Improvements to Craft/Convert-Interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Flo56958 committed May 19, 2023
1 parent 59121d2 commit bb8c1e3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public void onCraft(@NotNull final PrepareItemCraftEvent event) {
if (ToolType.isMaterialCompatible(lastItem.getType())) {
inv.setResult(lastItem);
modManager.convertItemStack(event.getInventory().getResult(), humanEntity);
inv.getResult().setAmount(1);

// Tools should always be a stack of one if not some other plugin does something,
// and we do not want to interfere
//inv.getResult().setAmount(1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public void onCraft(@NotNull final CraftItemEvent event) {

if (config.getBoolean("Sound.OnEveryCrafting")) {
player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_USE, 1.0F, 0.5F);

return;
}

Expand All @@ -39,6 +38,9 @@ public void onCraft(@NotNull final CraftItemEvent event) {
return;
}

//If the tools are stacked because of a different plugin we do not want to interfere with that plugin
//tool.setAmount(1);

if (config.getBoolean("Sound.OnCrafting")) {
player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_USE, 1.0F, 0.5F);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public void PrepareCraft(@NotNull final PrepareItemCraftEvent event) {

Player player = null;

for (HumanEntity humans : event.getViewers()) {
if (humans instanceof Player) {
player = (Player) humans;
for (HumanEntity human : event.getViewers()) {
if (human instanceof Player) {
player = (Player) human;
break;
}
}

Expand Down Expand Up @@ -88,8 +89,14 @@ public void PrepareCraft(@NotNull final PrepareItemCraftEvent event) {
}
}

// Check for converting as we do not do this here
if (totalItems == 1 && lastItem.getType() == currentItem.getType()) {
currentItem.setAmount(1);
return;
}

// Check for vanilla repairing in crafting grid, do not convert tool to MineTinker
if (totalItems == 2 && lastItem.getType() == currentItem.getType()) {
return;
}

modManager.convertItemStack(event.getInventory().getResult(), player);
Expand Down
48 changes: 22 additions & 26 deletions src/main/java/de/flo56958/minetinker/modifiers/ModManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -876,41 +876,37 @@ public boolean convertItemStack(final ItemStack is, @Nullable final Entity entit

final ItemMeta meta = is.getItemMeta();

if (meta != null) {
if (MineTinker.getPlugin().getConfig().getBoolean("ConvertEnchantsAndAttributes")) {

for (Map.Entry<Enchantment, Integer> entry : meta.getEnchants().entrySet()) {
final Modifier modifier = getModifierFromEnchantment(entry.getKey());

if (modifier == null) {
continue;
}
if (meta == null) return true;
if (!MineTinker.getPlugin().getConfig().getBoolean("ConvertEnchantsAndAttributes")) return true;

meta.removeEnchant(entry.getKey());
for (Map.Entry<Enchantment, Integer> entry : meta.getEnchants().entrySet()) {
final Modifier modifier = getModifierFromEnchantment(entry.getKey());

for (int i = 0; i < entry.getValue(); i++) { //possible to go over MaxLevel of the mod
addMod(is, modifier);
modifier.applyMod(null, is, true); //Player is only required with Extra-Modifier (not possible here)
}
}
if (modifier == null) {
continue;
}

if (meta.getAttributeModifiers() == null) {
return true;
}
meta.removeEnchant(entry.getKey());

for (Map.Entry<Attribute, Collection<AttributeModifier>> entry : meta.getAttributeModifiers().asMap().entrySet()) {
final Modifier modifier = getModifierFromAttribute(entry.getKey());
for (int i = 0; i < entry.getValue(); i++) { //possible to go over MaxLevel of the mod
addMod(is, modifier);
modifier.applyMod(null, is, true); //Player is only required with Extra-Modifier (not possible here)
}
}

if (modifier == null || modifier == Hardened.instance()) {
continue;
}
if (meta.getAttributeModifiers() == null) return true;

meta.removeAttributeModifier(entry.getKey());
for (Map.Entry<Attribute, Collection<AttributeModifier>> entry : meta.getAttributeModifiers().asMap().entrySet()) {
final Modifier modifier = getModifierFromAttribute(entry.getKey());

addMod(is, modifier);
}
if (modifier == null || modifier == Hardened.instance()) {
continue;
}

meta.removeAttributeModifier(entry.getKey());
addMod(is, modifier);
}

return true;
}

Expand Down

0 comments on commit bb8c1e3

Please sign in to comment.