-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EIO Integration + Implement Custom Capacitors Directly
- Loading branch information
1 parent
41d3408
commit 7205bc0
Showing
17 changed files
with
186 additions
and
24 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
Binary file not shown.
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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
// Add any additional repositories for your dependencies here | ||
|
||
repositories { | ||
maven { | ||
maven { // Mixin Maven Fix | ||
url = 'https://repo.spongepowered.org/maven' | ||
} | ||
maven { // Autoconfig and Autosave | ||
name 'Mod Maven' | ||
url 'https://modmaven.dev' | ||
} | ||
} |
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
101 changes: 101 additions & 0 deletions
101
src/main/java/com/nomiceu/nomilabs/item/ItemCapacitor.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,101 @@ | ||
package com.nomiceu.nomilabs.item; | ||
|
||
import com.enderio.core.client.handlers.SpecialTooltipHandler; | ||
import com.nomiceu.nomilabs.LabsValues; | ||
import crazypants.enderio.api.capacitor.CapabilityCapacitorData; | ||
import crazypants.enderio.api.capacitor.ICapacitorData; | ||
import crazypants.enderio.api.capacitor.ICapacitorKey; | ||
import crazypants.enderio.base.lang.Lang; | ||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.client.util.ITooltipFlag; | ||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.ICapabilityProvider; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class ItemCapacitor extends Item { | ||
public final ICapacitorData data; | ||
public ItemCapacitor(ResourceLocation rl, CreativeTabs tab, ICapacitorData data) { | ||
setCreativeTab(tab); | ||
setRegistryName(rl); | ||
setMaxStackSize(64); | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public void addInformation(@NotNull ItemStack stack, @Nullable World worldIn, @NotNull List<String> tooltip, @NotNull ITooltipFlag flagIn) { | ||
super.addInformation(stack, worldIn, tooltip, flagIn); | ||
tooltip.add(I18n.format("tooltip.nomilabs.capacitors.description")); // Not using default here. This one adds `EnderIO`, making it clearer | ||
// Add default info | ||
if (SpecialTooltipHandler.showAdvancedTooltips()) | ||
SpecialTooltipHandler.addDetailedTooltipFromResources(tooltip, Lang.MACHINE_UPGRADE.getKey()); | ||
else | ||
SpecialTooltipHandler.addShowDetailsTooltip(tooltip); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public ICapabilityProvider initCapabilities(@NotNull ItemStack stack, @Nullable NBTTagCompound nbt) { | ||
return new CapacitorCapabilityProvider(data); | ||
} | ||
|
||
public static class CapacitorCapabilityProvider implements ICapabilityProvider { | ||
private final ICapacitorData data; | ||
public CapacitorCapabilityProvider(ICapacitorData data) { | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public boolean hasCapability(@NotNull Capability<?> capability, @Nullable EnumFacing facing) { | ||
return capability == CapabilityCapacitorData.getCapNN(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T> T getCapability(@NotNull Capability<T> capability, @Nullable EnumFacing facing) { | ||
if (capability == CapabilityCapacitorData.getCapNN()) | ||
return CapabilityCapacitorData.getCapNN().cast(data); | ||
return null; | ||
} | ||
} | ||
|
||
public enum LabsCapacitorData implements ICapacitorData { | ||
COMPRESSED("compressed_octadic", 4), | ||
DOUBLE_COMPRESSED("double_compressed_octadic", 5); | ||
|
||
private final String name; | ||
private final float level; | ||
|
||
LabsCapacitorData(String name, float level) { | ||
this.name = name; | ||
this.level = level; | ||
} | ||
|
||
|
||
@Override | ||
public float getUnscaledValue(@NotNull ICapacitorKey iCapacitorKey) { | ||
return level; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getUnlocalizedName() { | ||
return name; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getLocalizedName() { | ||
return I18n.format(LabsValues.LABS_MODID + "." + name); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/nomiceu/nomilabs/item/ItemExcitationCoil.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
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
2 changes: 1 addition & 1 deletion
2
...iceu/nomilabs/util/LabsTooltipHelper.java → ...u/nomilabs/tooltip/LabsTooltipHelper.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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/nomiceu/nomilabs/tooltip/TooltipAdder.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,34 @@ | ||
package com.nomiceu.nomilabs.tooltip; | ||
|
||
import com.enderio.core.client.handlers.SpecialTooltipHandler; | ||
import crazypants.enderio.api.capacitor.CapabilityCapacitorData; | ||
import crazypants.enderio.base.capacitor.CapacitorKey; | ||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.text.TextFormatting; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
import java.math.RoundingMode; | ||
import java.text.DecimalFormat; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class TooltipAdder { | ||
public static void addTooltipNormal(List<String> tooltip, ItemStack stack) { | ||
// Add Information of EIO Capacitors' Levels | ||
if (stack.hasCapability(CapabilityCapacitorData.getCapNN(), null)) { | ||
if (!SpecialTooltipHandler.showAdvancedTooltips()) return; | ||
|
||
var cap = Objects.requireNonNull(stack.getCapability(CapabilityCapacitorData.getCapNN(), null)); // Null shouldn't happen, as hasCapability returned true | ||
var level = cap.getUnscaledValue(CapacitorKey.NO_POWER); | ||
|
||
var formatter = new DecimalFormat("0.##"); // Format Levels to two decimal places (or less, this also removes trailing zeros) | ||
formatter.setRoundingMode(RoundingMode.HALF_UP); // Rounds up if in the middle (.5), else rounds to nearest | ||
|
||
// No clue what to use as the capacitor key, using NO_POWER, common declarations, in EnderIO and Nomi-Labs, don't use that parameter anyways | ||
tooltip.add(TextFormatting.DARK_PURPLE + I18n.format("tooltip.nomilabs.capacitors.level", formatter.format(level))); | ||
} | ||
} | ||
} |
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