-
-
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.
Browse files
Browse the repository at this point in the history
…-item refactor: remove duplication around energy item / block item
- Loading branch information
Showing
23 changed files
with
394 additions
and
261 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); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/EnergyItemHelper.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,25 @@ | ||
package com.refinedmods.refinedstorage2.platform.api.item; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") | ||
public interface EnergyItemHelper { | ||
void addTooltip(ItemStack stack, List<Component> lines); | ||
|
||
boolean isBarVisible(ItemStack stack); | ||
|
||
int getBarWidth(ItemStack stack); | ||
|
||
int getBarColor(ItemStack stack); | ||
|
||
ItemStack createAtEnergyCapacity(Item item); | ||
|
||
void passEnergyToBlockEntity(BlockPos pos, Level level, ItemStack 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); | ||
} |
Oops, something went wrong.