-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
1 parent
dc0224f
commit 60c0863
Showing
16 changed files
with
224 additions
and
0 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
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
117 changes: 117 additions & 0 deletions
117
...main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkCardItem.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,117 @@ | ||
package com.refinedmods.refinedstorage2.platform.common.networking; | ||
|
||
import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.InteractionResultHolder; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.TooltipFlag; | ||
import net.minecraft.world.item.context.UseOnContext; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; | ||
|
||
// TODO: better active texture. | ||
public class NetworkCardItem extends Item { | ||
private static final MutableComponent UNBOUND_HELP = createTranslation("item", "network_card.unbound_help"); | ||
private static final MutableComponent BOUND_HELP = createTranslation("item", "network_card.bound_help"); | ||
|
||
private static final MutableComponent UNBOUND = createTranslation("item", "network_card.unbound") | ||
.withStyle(ChatFormatting.RED); | ||
|
||
private static final String TAG_POS = "pos"; | ||
private static final String TAG_DIMENSION = "dim"; | ||
|
||
public NetworkCardItem() { | ||
super(new Item.Properties().stacksTo(1)); | ||
} | ||
|
||
@Override | ||
public InteractionResult useOn(final UseOnContext ctx) { | ||
if (ctx.getLevel().isClientSide() || ctx.getPlayer() == null) { | ||
return InteractionResult.CONSUME; | ||
} | ||
final BlockPos pos = ctx.getClickedPos(); | ||
final BlockState blockState = ctx.getLevel().getBlockState(pos); | ||
if (!(blockState.getBlock() instanceof NetworkReceiverBlock)) { | ||
return InteractionResult.CONSUME; | ||
} | ||
final CompoundTag tag = new CompoundTag(); | ||
tag.putLong(TAG_POS, pos.asLong()); | ||
tag.putString(TAG_DIMENSION, ctx.getLevel().dimension().location().toString()); | ||
ctx.getItemInHand().setTag(tag); | ||
ctx.getPlayer().sendSystemMessage(createTranslation( | ||
"item", | ||
"network_card.bound", | ||
pos.getX(), | ||
pos.getY(), | ||
pos.getZ() | ||
)); | ||
return InteractionResult.SUCCESS; | ||
} | ||
|
||
@Override | ||
public InteractionResultHolder<ItemStack> use(final Level level, final Player player, final InteractionHand hand) { | ||
if (player.isCrouching()) { | ||
if (!level.isClientSide()) { | ||
player.sendSystemMessage(createTranslation("item", "network_card.unbound")); | ||
} | ||
return new InteractionResultHolder<>(InteractionResult.CONSUME, new ItemStack(this)); | ||
} | ||
return super.use(level, player, hand); | ||
} | ||
|
||
@Override | ||
public void appendHoverText(final ItemStack stack, | ||
@Nullable final Level level, | ||
final List<Component> lines, | ||
final TooltipFlag flag) { | ||
super.appendHoverText(stack, level, lines, flag); | ||
if (!isActive(stack)) { | ||
lines.add(UNBOUND); | ||
return; | ||
} | ||
final BlockPos pos = getPosition(stack); | ||
if (pos == null) { | ||
return; | ||
} | ||
lines.add(createTranslation( | ||
"item", | ||
"network_card.bound", | ||
pos.getX(), | ||
pos.getY(), | ||
pos.getZ() | ||
).withStyle(ChatFormatting.GRAY)); | ||
} | ||
|
||
@Nullable | ||
public BlockPos getPosition(final ItemStack stack) { | ||
if (stack.getTag() == null) { | ||
return null; | ||
} | ||
return BlockPos.of(stack.getTag().getLong(TAG_POS)); | ||
} | ||
|
||
@Override | ||
public Optional<TooltipComponent> getTooltipImage(final ItemStack stack) { | ||
return Optional.of(new HelpTooltipComponent(isActive(stack) ? BOUND_HELP : UNBOUND_HELP)); | ||
} | ||
|
||
public boolean isActive(final ItemStack stack) { | ||
return stack.getTag() != null && stack.getTag().contains(TAG_POS) && stack.getTag().contains(TAG_DIMENSION); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...finedmods/refinedstorage2/platform/common/networking/NetworkCardItemPropertyFunction.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,24 @@ | ||
package com.refinedmods.refinedstorage2.platform.common.networking; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public class NetworkCardItemPropertyFunction implements ClampedItemPropertyFunction { | ||
public static final ResourceLocation NAME = new ResourceLocation("active"); | ||
|
||
@Override | ||
public float unclampedCall(final ItemStack itemStack, | ||
@Nullable final ClientLevel clientLevel, | ||
@Nullable final LivingEntity livingEntity, | ||
final int i) { | ||
if (itemStack.getItem() instanceof NetworkCardItem cardItem) { | ||
return cardItem.isActive(itemStack) ? 1 : 0; | ||
} | ||
return 0; | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...2-platform-common/src/main/resources/assets/refinedstorage2/models/item/network_card.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,17 @@ | ||
{ | ||
"parent": "item/generated", | ||
"overrides": [ | ||
{ | ||
"predicate": { | ||
"active": 0 | ||
}, | ||
"model": "refinedstorage2:item/network_card/inactive" | ||
}, | ||
{ | ||
"predicate": { | ||
"active": 1 | ||
}, | ||
"model": "refinedstorage2:item/network_card/active" | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
...orm-common/src/main/resources/assets/refinedstorage2/models/item/network_card/active.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": "item/generated", | ||
"textures": { | ||
"layer0": "refinedstorage2:item/network_card/active" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...m-common/src/main/resources/assets/refinedstorage2/models/item/network_card/inactive.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": "item/generated", | ||
"textures": { | ||
"layer0": "refinedstorage2:item/network_card/inactive" | ||
} | ||
} |
Binary file added
BIN
+998 Bytes
...src/main/resources/assets/refinedstorage2/textures/item/network_card/active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.74 KB
...c/main/resources/assets/refinedstorage2/textures/item/network_card/inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
...torage2-platform-common/src/main/resources/data/refinedstorage2/recipes/network_card.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,22 @@ | ||
{ | ||
"type": "minecraft:crafting_shaped", | ||
"pattern": [ | ||
"EEE", | ||
"PAP", | ||
"EEE" | ||
], | ||
"key": { | ||
"E": { | ||
"item": "refinedstorage2:quartz_enriched_iron" | ||
}, | ||
"P": { | ||
"item": "minecraft:paper" | ||
}, | ||
"A": { | ||
"item": "refinedstorage2:advanced_processor" | ||
} | ||
}, | ||
"result": { | ||
"item": "refinedstorage2:network_card" | ||
} | ||
} |
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