-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: api for network bound items
- Loading branch information
1 parent
707b878
commit 2cd3946
Showing
17 changed files
with
230 additions
and
148 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
49 changes: 49 additions & 0 deletions
49
...ava/com/refinedmods/refinedstorage2/platform/api/item/AbstractNetworkBoundEnergyItem.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,49 @@ | ||
package com.refinedmods.refinedstorage2.platform.api.item; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
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 org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") | ||
public abstract class AbstractNetworkBoundEnergyItem extends AbstractEnergyItem { | ||
protected final NetworkBoundItemHelper networkBoundItemHelper; | ||
|
||
protected AbstractNetworkBoundEnergyItem(final Properties properties, | ||
final EnergyItemHelper energyItemHelper, | ||
final NetworkBoundItemHelper networkBoundItemHelper) { | ||
super(properties, energyItemHelper); | ||
this.networkBoundItemHelper = networkBoundItemHelper; | ||
} | ||
|
||
@Override | ||
public InteractionResult useOn(final UseOnContext ctx) { | ||
return networkBoundItemHelper.bind(ctx); | ||
} | ||
|
||
@Override | ||
public Optional<TooltipComponent> getTooltipImage(final ItemStack stack) { | ||
return networkBoundItemHelper.getTooltipImage(stack); | ||
} | ||
|
||
@Override | ||
public void appendHoverText(final ItemStack stack, | ||
@Nullable final Level level, | ||
final List<Component> tooltip, | ||
final TooltipFlag flag) { | ||
super.appendHoverText(stack, level, tooltip, flag); | ||
networkBoundItemHelper.addTooltip(stack, tooltip); | ||
} | ||
|
||
public boolean isBound(final ItemStack stack) { | ||
return networkBoundItemHelper.isBound(stack); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...c/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemHelper.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,26 @@ | ||
package com.refinedmods.refinedstorage2.platform.api.item; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.context.UseOnContext; | ||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") | ||
public interface NetworkBoundItemHelper { | ||
void addTooltip(ItemStack stack, List<Component> lines); | ||
|
||
InteractionResult bind(UseOnContext ctx); | ||
|
||
Optional<TooltipComponent> getTooltipImage(ItemStack stack); | ||
|
||
NetworkBoundItemSession openSession(ItemStack stack, ServerPlayer player, InteractionHand hand); | ||
|
||
boolean isBound(ItemStack stack); | ||
} |
16 changes: 16 additions & 0 deletions
16
.../main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemSession.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,16 @@ | ||
package com.refinedmods.refinedstorage2.platform.api.item; | ||
|
||
import com.refinedmods.refinedstorage2.api.network.Network; | ||
|
||
import java.util.Optional; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") | ||
public interface NetworkBoundItemSession { | ||
Optional<Network> resolveNetwork(); | ||
|
||
boolean isActive(); | ||
|
||
void drainEnergy(long amount); | ||
} |
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
Oops, something went wrong.