-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
125 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
common/src/main/java/com/iafenvoy/sow/item/WallsOfTimeEditItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.iafenvoy.sow.item; | ||
|
||
import com.iafenvoy.sow.item.block.entity.WallsOfTimeBlockEntity; | ||
import com.iafenvoy.sow.registry.SowItemGroups; | ||
import net.minecraft.client.item.TooltipContext; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.ItemUsageContext; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.Rarity; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class WallsOfTimeEditItem extends Item { | ||
private static final String EDIT_TYPE_KEY = "edit_type"; | ||
|
||
public WallsOfTimeEditItem() { | ||
super(new Settings().rarity(Rarity.EPIC).maxCount(1).arch$tab(SowItemGroups.ITEMS)); | ||
} | ||
|
||
@Override | ||
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { | ||
super.inventoryTick(stack, world, entity, slot, selected); | ||
if (!stack.getOrCreateNbt().contains(EDIT_TYPE_KEY)) | ||
stack.getOrCreateNbt().putString(EDIT_TYPE_KEY, WallsOfTimeBlockEntity.EditType.OFFSET_X_PLUS.name()); | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { | ||
ItemStack stack = user.getStackInHand(hand); | ||
if (user.isSneaking() && stack.getOrCreateNbt().contains(EDIT_TYPE_KEY)) { | ||
WallsOfTimeBlockEntity.EditType next = WallsOfTimeBlockEntity.EditType.valueOf(stack.getOrCreateNbt().getString(EDIT_TYPE_KEY)).next(); | ||
stack.getOrCreateNbt().putString(EDIT_TYPE_KEY, next.name()); | ||
user.sendMessage(Text.translatable("item.sow.walls_of_time_edit.mode", next.name()), true); | ||
return TypedActionResult.success(stack); | ||
} | ||
return super.use(world, user, hand); | ||
} | ||
|
||
@Override | ||
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) { | ||
super.appendTooltip(stack, world, tooltip, context); | ||
tooltip.add(Text.translatable("item.sow.walls_of_time_edit.mode", stack.getOrCreateNbt().getString(EDIT_TYPE_KEY))); | ||
} | ||
|
||
@Override | ||
public ActionResult useOnBlock(ItemUsageContext context) { | ||
if (context.getWorld().getBlockEntity(context.getBlockPos()) instanceof WallsOfTimeBlockEntity blockEntity) { | ||
WallsOfTimeBlockEntity.EditType.valueOf(context.getStack().getOrCreateNbt().getString(EDIT_TYPE_KEY)).getProcess().accept(blockEntity.getContents()); | ||
blockEntity.sync(); | ||
return ActionResult.SUCCESS; | ||
} | ||
return super.useOnBlock(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/sow/models/item/walls_of_time_edit.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/handheld", | ||
"textures": { | ||
"layer0": "minecraft:item/stick" | ||
} | ||
} |