mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Allow items to control the rate of repair from mending (#5102)
This commit is contained in:
1 parent
a0a3f9dbfb
commit
fa708f93ee
3 files changed
+124
-1
No files matched your search
@@ -18,7 +18,7 @@
|
||||
if (this.func_180431_b(p_70097_1_)) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -178,6 +180,7 @@
|
||||
@@ -178,12 +180,14 @@
|
||||
public void func_70100_b_(EntityPlayer p_70100_1_) {
|
||||
if (!this.field_70170_p.field_72995_K) {
|
||||
if (this.field_70532_c == 0 && p_70100_1_.field_71090_bL == 0) {
|
||||
@@ -26,3 +26,22 @@
|
||||
p_70100_1_.field_71090_bL = 2;
|
||||
p_70100_1_.func_71001_a(this, 1);
|
||||
ItemStack itemstack = EnchantmentHelper.func_92099_a(Enchantments.field_185296_A, p_70100_1_);
|
||||
if (!itemstack.func_190926_b() && itemstack.func_77951_h()) {
|
||||
- int i = Math.min(this.func_184514_c(this.field_70530_e), itemstack.func_77952_i());
|
||||
- this.field_70530_e -= this.func_184515_b(i);
|
||||
+ float ratio = itemstack.func_77973_b().getXpRepairRatio(itemstack);
|
||||
+ int i = Math.min(roundAverage(this.field_70530_e * ratio), itemstack.func_77952_i());
|
||||
+ this.field_70530_e -= roundAverage(i / ratio);
|
||||
itemstack.func_196085_b(itemstack.func_77952_i() - i);
|
||||
}
|
||||
|
||||
@@ -261,4 +265,9 @@
|
||||
public boolean func_70075_an() {
|
||||
return false;
|
||||
}
|
||||
+
|
||||
+ private static int roundAverage(float value) {
|
||||
+ double floor = Math.floor(value);
|
||||
+ return (int) floor + (Math.random() < value - floor ? 1 : 0);
|
||||
+ }
|
||||
}
|
||||
@@ -113,6 +113,15 @@ public interface IForgeItem
|
||||
* @return True if reparable
|
||||
*/
|
||||
boolean isRepairable();
|
||||
|
||||
/**
|
||||
* Determines the amount of durability the mending enchantment
|
||||
* will repair, on average, per point of experience.
|
||||
*/
|
||||
default float getXpRepairRatio(ItemStack stack)
|
||||
{
|
||||
return 2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to change the NBT data being sent to the client. You
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.item;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Enchantments;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
@Mod(modid = MendingRepairTest.MOD_ID, name = "Mending repair amount test mod", version = "1.0")
|
||||
public class MendingRepairTest
|
||||
{
|
||||
static final boolean ENABLED = true;
|
||||
static final String MOD_ID = "mending_repair_test";
|
||||
|
||||
@GameRegistry.ObjectHolder(MOD_ID + ":test_item")
|
||||
public static final Item TEST_ITEM = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
if (!ENABLED) return;
|
||||
event.getRegistry().register(
|
||||
new TestItem()
|
||||
.setRegistryName(MOD_ID, "test_item")
|
||||
.setUnlocalizedName(MOD_ID + ".test_item")
|
||||
);
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MOD_ID, value = Side.CLIENT)
|
||||
public static final class ClientEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
if (!ENABLED) return;
|
||||
ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation("minecraft:blaze_rod", "inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TestItem extends Item
|
||||
{
|
||||
TestItem()
|
||||
{
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(10);
|
||||
setCreativeTab(CreativeTabs.TOOLS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
ItemStack stack = new ItemStack(this);
|
||||
stack.addEnchantment(Enchantments.MENDING, 1);
|
||||
stack.setItemDamage(stack.getMaxDamage());
|
||||
items.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getXpRepairRatio(ItemStack stack)
|
||||
{
|
||||
return 0.1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user