Added item repair using crafting tables
parent
32c529e391
commit
f22e87ce8b
|
@ -107,6 +107,14 @@ public class WyHelper {
|
|||
// animal.setPositionAndAngles(player.x + 2, player.y, player.z, 0.0f, 0.0f);
|
||||
// player.level.spawnEntity(animal);
|
||||
|
||||
// player.dropItem(new ItemInstance(Tile.WORKBENCH, 1));
|
||||
// player.dropItem(new ItemInstance(ItemType.chestplateDiamond, 3));
|
||||
|
||||
// ItemInstance item = player.inventory.getHeldItem();
|
||||
// if (item != null) {
|
||||
// item.setDamage(item.method_723() - 200);
|
||||
// }
|
||||
|
||||
player.level.setLevelTime(0);
|
||||
player.level.getProperties().setRaining(false);
|
||||
player.level.getProperties().setRainTime(0);
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package xyz.pixelatedw.finalbeta.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.container.CraftingContainer;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemInstance;
|
||||
|
||||
@Mixin(CraftingContainer.class)
|
||||
public class CraftingContainerMixin {
|
||||
|
||||
@Inject(method = "onContentsChanged", at = @At("HEAD"), cancellable = true)
|
||||
public void onContentsChanged(Inventory inventory, CallbackInfo ci) {
|
||||
CraftingContainer container = ((CraftingContainer)(Object)this);
|
||||
|
||||
ItemInstance resultItem = null;
|
||||
int defaultDamage = 0;
|
||||
int damage = 0;
|
||||
|
||||
for (int i = 0; i < inventory.getInvSize(); i++) {
|
||||
ItemInstance item = inventory.getInvItem(i);
|
||||
if (item != null && item.method_723() > 0) {
|
||||
if (resultItem == null) {
|
||||
resultItem = new ItemInstance(item.itemId, 1, item.getDamage());
|
||||
defaultDamage = item.method_723() - item.getDamage();
|
||||
} else if (item.itemId == resultItem.itemId) {
|
||||
damage += item.method_723() - item.getDamage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resultItem != null && damage > 0) {
|
||||
int newDurability = (int) (defaultDamage + damage + Math.floor(resultItem.method_723() / 20));
|
||||
newDurability = Math.min(newDurability, resultItem.method_723());
|
||||
|
||||
if (newDurability != defaultDamage) {
|
||||
resultItem.setDamage(resultItem.method_723() - newDurability);
|
||||
container.result.setInvItem(0, resultItem);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,8 @@
|
|||
"BoatMixin",
|
||||
"LevelPropertiesMixin",
|
||||
"LevelMixin",
|
||||
"DoorTileMixin"
|
||||
"DoorTileMixin",
|
||||
"CraftingContainerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": -1
|
||||
|
|
Loading…
Reference in New Issue