implement wand durability & repair amulet
25
src/main/java/com/jenny/magic/items/AmuletRepair.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package com.jenny.magic.items;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class AmuletRepair extends BaseItem {
|
||||||
|
public AmuletRepair(@NotNull Properties pProperties) {
|
||||||
|
super(pProperties.stacksTo(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inventoryTick(@NotNull ItemStack pStack, @NotNull Level pLevel, @NotNull Entity pEntity, int pSlotId, boolean pIsSelected) {
|
||||||
|
if (!pLevel.isClientSide && pLevel.getRandom().nextInt(10) == 0 && pEntity instanceof Player pPlayer) {
|
||||||
|
int rand = pLevel.getRandom().nextInt(0, 9);
|
||||||
|
ItemStack itemStack = pPlayer.getInventory().items.get(rand);
|
||||||
|
System.out.println(itemStack.getItem().toString());
|
||||||
|
if (itemStack.isDamaged()) {
|
||||||
|
itemStack.setDamageValue(itemStack.getDamageValue() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,9 @@ public abstract class BaseWand extends QualityItem {
|
|||||||
BaseWandProjectile projectile = newProjectile(pLevel);
|
BaseWandProjectile projectile = newProjectile(pLevel);
|
||||||
projectile.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 2.0F);
|
projectile.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 2.0F);
|
||||||
pLevel.addFreshEntity(projectile);
|
pLevel.addFreshEntity(projectile);
|
||||||
setDamage(itemstack, getDamage(itemstack) + damageItem(itemstack, 1, pPlayer, (player) -> onItemDestroyed(player)));
|
itemstack.hurtAndBreak(1, pPlayer, (player) -> {
|
||||||
|
player.broadcastBreakEvent(pPlayer.getUsedItemHand());
|
||||||
|
});
|
||||||
return InteractionResultHolder.success(itemstack);
|
return InteractionResultHolder.success(itemstack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +36,6 @@ public abstract class BaseWand extends QualityItem {
|
|||||||
while (pRepairCandidate.getCount() >= 1 && pStack.isDamaged()) {
|
while (pRepairCandidate.getCount() >= 1 && pStack.isDamaged()) {
|
||||||
pRepairCandidate.shrink(1);
|
pRepairCandidate.shrink(1);
|
||||||
pStack.setDamageValue(pStack.getDamageValue() - 20);
|
pStack.setDamageValue(pStack.getDamageValue() - 20);
|
||||||
System.out.println("test");
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,7 +13,7 @@ import static com.jenny.magic.Magic.MODID;
|
|||||||
public class items {
|
public class items {
|
||||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||||
public static final RegistryObject<Item> WAND_HURTFUL = ITEMS.register("wand_hurtful", () -> new WandHurtful(new Item.Properties()));
|
public static final RegistryObject<Item> WAND_HURTFUL = ITEMS.register("wand_hurtful", () -> new WandHurtful(new Item.Properties()));
|
||||||
public static final RegistryObject<Item> WAND_VAUUM = ITEMS.register("wand_vacuum", () -> new WandVacuum(new Item.Properties()));
|
public static final RegistryObject<Item> WAND_VAUUM = ITEMS.register("wand_vacuum", () -> new WandVacuum(new Item.Properties().stacksTo(1)));
|
||||||
public static final RegistryObject<Item> SCROLL_TELEPORT = ITEMS.register("scroll_teleport", () -> new TeleportScrollPersistent(new Item.Properties().stacksTo(1)));
|
public static final RegistryObject<Item> SCROLL_TELEPORT = ITEMS.register("scroll_teleport", () -> new TeleportScrollPersistent(new Item.Properties().stacksTo(1)));
|
||||||
public static final RegistryObject<Item> SCROLL_TELEPORT_BRITTLE = ITEMS.register("scroll_teleport_brittle", () -> new TeleportScrollConsumable(new Item.Properties().stacksTo(16)));
|
public static final RegistryObject<Item> SCROLL_TELEPORT_BRITTLE = ITEMS.register("scroll_teleport_brittle", () -> new TeleportScrollConsumable(new Item.Properties().stacksTo(16)));
|
||||||
public static final RegistryObject<Item> SCROLL_TELEPORT_RANDOM = ITEMS.register("scroll_teleport_random", () -> new TeleportScrollRandom(new Item.Properties().stacksTo(1)));
|
public static final RegistryObject<Item> SCROLL_TELEPORT_RANDOM = ITEMS.register("scroll_teleport_random", () -> new TeleportScrollRandom(new Item.Properties().stacksTo(1)));
|
||||||
@ -21,6 +21,7 @@ public class items {
|
|||||||
public static final RegistryObject<Item> SCROLL_HEALTH = ITEMS.register("scroll_health", () -> new HealthScroll(new Item.Properties().stacksTo(16)));
|
public static final RegistryObject<Item> SCROLL_HEALTH = ITEMS.register("scroll_health", () -> new HealthScroll(new Item.Properties().stacksTo(16)));
|
||||||
public static final RegistryObject<Item> SCROLL_REPEL = ITEMS.register("scroll_repel", () -> new RepelScroll(new Item.Properties().stacksTo(16)));
|
public static final RegistryObject<Item> SCROLL_REPEL = ITEMS.register("scroll_repel", () -> new RepelScroll(new Item.Properties().stacksTo(16)));
|
||||||
public static final RegistryObject<Item> SCROLL_BONEMEAL = ITEMS.register("scroll_bonemeal", () -> new BonemealScroll(new Item.Properties().stacksTo(16)));
|
public static final RegistryObject<Item> SCROLL_BONEMEAL = ITEMS.register("scroll_bonemeal", () -> new BonemealScroll(new Item.Properties().stacksTo(16)));
|
||||||
|
public static final RegistryObject<Item> AMULET_REPAIR = ITEMS.register("amulet_repair", () -> new AmuletRepair(new Item.Properties()));
|
||||||
public static final RegistryObject<Item> DRAGON_HEART = ITEMS.register("dragon_heart", () -> new QualityItem(new Item.Properties()));
|
public static final RegistryObject<Item> DRAGON_HEART = ITEMS.register("dragon_heart", () -> new QualityItem(new Item.Properties()));
|
||||||
|
|
||||||
public static void register(IEventBus bus) {
|
public static void register(IEventBus bus) {
|
||||||
|
BIN
src/main/resources/assets/magic/textures/item/amulet_repair.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
src/main/resources/assets/magic/textures/item/dragon_heart.png
Normal file
After Width: | Height: | Size: 97 B |
After Width: | Height: | Size: 154 B |
BIN
src/main/resources/assets/magic/textures/item/scroll_health.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
src/main/resources/assets/magic/textures/item/scroll_repel.png
Normal file
After Width: | Height: | Size: 158 B |
After Width: | Height: | Size: 97 B |
Before Width: | Height: | Size: 97 B After Width: | Height: | Size: 205 B |
BIN
src/main/resources/assets/magic/textures/item/wand_vacuum.png
Normal file
After Width: | Height: | Size: 216 B |