-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: TheMCCrazyMan <themccrazyman@mail.ch>
- Loading branch information
1 parent
5167942
commit c4d5364
Showing
13 changed files
with
188 additions
and
19 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
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
119 changes: 119 additions & 0 deletions
119
src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineProvider.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,119 @@ | ||
package net.themcbrothers.usefulmachinery.compat.jade; | ||
|
||
import net.minecraft.core.NonNullList; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.ListTag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.phys.Vec2; | ||
import net.themcbrothers.usefulmachinery.UsefulMachinery; | ||
import net.themcbrothers.usefulmachinery.block.entity.AbstractMachineBlockEntity; | ||
import net.themcbrothers.usefulmachinery.core.MachineryItems; | ||
import net.themcbrothers.usefulmachinery.machine.MachineTier; | ||
import snownee.jade.api.BlockAccessor; | ||
import snownee.jade.api.IBlockComponentProvider; | ||
import snownee.jade.api.IServerDataProvider; | ||
import snownee.jade.api.ITooltip; | ||
import snownee.jade.api.config.IPluginConfig; | ||
import snownee.jade.api.ui.IElementHelper; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import java.util.stream.IntStream; | ||
|
||
/** | ||
* Adds the machine's progress and tier information | ||
*/ | ||
public enum MachineProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> { | ||
INSTANCE; | ||
|
||
private static final ResourceLocation UID = UsefulMachinery.rl("machine"); | ||
|
||
@Override | ||
public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfig pluginConfig) { | ||
CompoundTag data = accessor.getServerData(); | ||
IElementHelper helper = IElementHelper.get(); | ||
|
||
if (data.contains("progress")) { | ||
ListTag machineItems = data.getList("machine", ListTag.TAG_COMPOUND); | ||
NonNullList<ItemStack> inventory = NonNullList.withSize(data.getInt("size"), ItemStack.EMPTY); | ||
|
||
for (int i = 0; i < machineItems.size(); ++i) { | ||
inventory.set(i, ItemStack.of(machineItems.getCompound(i))); | ||
} | ||
|
||
int progress = data.getInt("progress"); | ||
int total = data.getInt("total"); | ||
|
||
int count = 0; | ||
|
||
for (int slot : data.getIntArray("inputs")) { | ||
if (count++ == 0) { | ||
tooltip.add(helper.item(inventory.get(slot))); | ||
} else { | ||
tooltip.append(helper.item(inventory.get(slot))); | ||
} | ||
} | ||
|
||
// Progress Bar | ||
tooltip.append(helper.spacer(4, 0)); | ||
tooltip.append(helper.progress((float) progress / (float) total) | ||
.translate(new Vec2(-2.0F, 0.0F))); | ||
|
||
Arrays.stream(data.getIntArray("outputs")) | ||
.mapToObj(inventory::get) | ||
.map(helper::item) | ||
.forEach(tooltip::append); | ||
} | ||
|
||
MachineTier tier = MachineTier.byOrdinal(data.getInt("tier")); | ||
|
||
if (accessor.getPlayer().isShiftKeyDown() && tier.ordinal() > 0) { | ||
CompoundTag tierTag = new CompoundTag(); | ||
tierTag.putInt("Tier", tier.ordinal()); | ||
|
||
// Tier | ||
tooltip.add(helper.smallItem(new ItemStack(MachineryItems.TIER_UPGRADE.get(), 1, Optional.of(tierTag)))); | ||
tooltip.append(helper.spacer(4, 0)); | ||
tooltip.append(helper.text(Component.literal(tier.getSerializedName()))); | ||
} | ||
} | ||
|
||
@Override | ||
public void appendServerData(CompoundTag data, BlockAccessor accessor) { | ||
AbstractMachineBlockEntity machine = (AbstractMachineBlockEntity) accessor.getBlockEntity(); | ||
|
||
boolean showJadeProgress = Arrays.stream(machine.getSlotsForFace(null)) | ||
.mapToObj(machine::getItem) | ||
.anyMatch(itemStack -> !itemStack.isEmpty()); | ||
|
||
if (showJadeProgress) { | ||
ListTag items = new ListTag(); | ||
|
||
IntStream.range(0, machine.getContainerSize()) | ||
.mapToObj(machine::getItem) | ||
.map(stack -> stack.save(new CompoundTag())) | ||
.forEach(items::add); | ||
|
||
data.putIntArray("inputs", machine.getInputSlots()); | ||
data.putIntArray("outputs", machine.getOutputSlots()); | ||
|
||
data.putInt("size", machine.getContainerSize()); | ||
data.put("machine", items); | ||
|
||
CompoundTag furnaceTag = machine.saveWithoutMetadata(); | ||
|
||
data.putInt("progress", furnaceTag.getInt("ProcessTime")); | ||
data.putInt("total", furnaceTag.getInt("ProcessTimeTotal")); | ||
|
||
} | ||
|
||
data.putInt("tier", machine.getMachineTier(accessor.getBlockState()).ordinal()); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return UID; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/main/java/net/themcbrothers/usefulmachinery/compat/jade/RemoveVanillaStuffProvider.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,41 @@ | ||
package net.themcbrothers.usefulmachinery.compat.jade; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import net.themcbrothers.usefulmachinery.UsefulMachinery; | ||
import net.themcbrothers.usefulmachinery.block.entity.AbstractMachineBlockEntity; | ||
import snownee.jade.api.BlockAccessor; | ||
import snownee.jade.api.IBlockComponentProvider; | ||
import snownee.jade.api.ITooltip; | ||
import snownee.jade.api.Identifiers; | ||
import snownee.jade.api.config.IPluginConfig; | ||
|
||
/** | ||
* Provider that removes tooltip components from our machines | ||
*/ | ||
public enum RemoveVanillaStuffProvider implements IBlockComponentProvider { | ||
INSTANCE; | ||
|
||
private static final ResourceLocation UID = UsefulMachinery.rl("remove_vanilla_stuff"); | ||
|
||
@Override | ||
public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfig pluginConfig) { | ||
if (accessor.getBlockEntity() instanceof AbstractMachineBlockEntity) { | ||
tooltip.remove(Identifiers.UNIVERSAL_ITEM_STORAGE); | ||
} | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return UID; | ||
} | ||
|
||
@Override | ||
public int getDefaultPriority() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public boolean isRequired() { | ||
return true; | ||
} | ||
} |
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