Skip to content

Commit

Permalink
Add Annihilation Plane enchantment support, deprecate Identity (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeng-github01 authored Nov 29, 2024
1 parent 925cf09 commit 7f2318f
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 78 deletions.
6 changes: 5 additions & 1 deletion src/main/java/appeng/core/localization/GuiText.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ public enum GuiText {

// Used in Crafting Toasts
CraftingToastDone,
CraftingToastCancelled;
CraftingToastCancelled,

CanBeEnchanted,
IncreasedEnergyUseFromEnchants,
Deprecated;

private final String root;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/appeng/core/localization/WailaText.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public enum WailaText {
Showing,

Contains,
Channels;
Channels,
EnchantedWith,
IdentityDeprecated;

private final String root;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public PartWailaDataProvider() {
final IPartWailaDataProvider powerState = new PowerStateWailaDataProvider();
final IPartWailaDataProvider p2pState = new P2PStateWailaDataProvider();
final IPartWailaDataProvider partStack = new PartStackWailaDataProvider();
final IPartWailaDataProvider annihilationPlane = new AnnihilationPlaneDataProvider();

this.providers = Lists.newArrayList(channel, storageMonitor, powerState, partStack, p2pState);
this.providers = Lists.newArrayList(channel, storageMonitor, powerState, partStack, p2pState, annihilationPlane);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package appeng.integration.modules.waila.part;

import appeng.api.parts.IPart;
import appeng.core.localization.WailaText;
import appeng.parts.automation.PartAnnihilationPlane;
import appeng.parts.automation.PartIdentityAnnihilationPlane;
import appeng.util.EnchantmentUtil;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.List;
import java.util.Map;

public class AnnihilationPlaneDataProvider extends BasePartWailaDataProvider {
@Override
public List<String> getWailaBody(IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
if (part instanceof PartIdentityAnnihilationPlane) {
currentToolTip.add(WailaText.IdentityDeprecated.getLocal());
} else if (part instanceof PartAnnihilationPlane plane) {
NBTTagCompound nbtData = accessor.getNBTData();
Map<Enchantment, Integer> enchantments = EnchantmentUtil.getEnchantments(nbtData);
if (!enchantments.isEmpty()) {
currentToolTip.add(WailaText.EnchantedWith.getLocal());
for (var enchantment : enchantments.keySet()) {
currentToolTip.add(enchantment.getTranslatedName(enchantments.get(enchantment)));
}
}
}

return currentToolTip;
}

@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
if (part instanceof PartAnnihilationPlane plane) {
plane.writeEnchantments(tag);
}

return tag;
}
}
5 changes: 0 additions & 5 deletions src/main/java/appeng/items/AEBaseItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public final void getSubItems(final CreativeTabs creativeTab, final NonNullList<
}
}

@Override
public boolean isBookEnchantable(final ItemStack itemstack1, final ItemStack itemstack2) {
return false;
}

@SideOnly(Side.CLIENT)
protected void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
super.addInformation(stack, world, lines, advancedTooltips);
Expand Down
53 changes: 52 additions & 1 deletion src/main/java/appeng/items/parts/ItemPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
import appeng.items.AEBaseItem;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -133,10 +137,20 @@ public int getDamageByType(final PartType t) {

@Override
public EnumActionResult onItemUse(final EntityPlayer player, final World w, final BlockPos pos, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ) {
if (this.getTypeByStack(player.getHeldItem(hand)) == PartType.INVALID_TYPE) {
ItemStack heldItem = player.getHeldItem(hand);
PartType typeByStack = getTypeByStack(heldItem);
if (typeByStack == PartType.INVALID_TYPE) {
return EnumActionResult.FAIL;
}

if (player.isSneaking() && typeByStack == PartType.IDENTITY_ANNIHILATION_PLANE) {
ItemStack newPlane = new ItemStack(this, heldItem.getCount(), PartType.ANNIHILATION_PLANE.getBaseDamage());
newPlane.addEnchantment(Enchantments.SILK_TOUCH,1);

player.setHeldItem(hand, newPlane);
return EnumActionResult.SUCCESS;
}

return AEApi.instance().partHelper().placeBus(player.getHeldItem(hand), pos, side, player, hand, w);
}

Expand Down Expand Up @@ -178,6 +192,43 @@ protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullL
}
}

@Override
protected void addCheckedInformation(ItemStack stack, World world, List<String> lines, ITooltipFlag advancedTooltips) {
if (getTypeByStack(stack) == PartType.ANNIHILATION_PLANE) {
var enchantments = EnchantmentHelper.getEnchantments(stack);
if (enchantments.isEmpty()) {
lines.add(GuiText.CanBeEnchanted.getLocal());
}
else {
lines.add(GuiText.IncreasedEnergyUseFromEnchants.getLocal());
}
}

if (getTypeByStack(stack) == PartType.IDENTITY_ANNIHILATION_PLANE) {
lines.add(GuiText.Deprecated.getLocal());
}
}

@Override
public int getItemEnchantability() {
return 10;
}

@Override
public boolean isEnchantable(ItemStack stack) {
return getTypeByStack(stack) == PartType.ANNIHILATION_PLANE;
}

@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return enchantment == Enchantments.UNBREAKING || enchantment == Enchantments.FORTUNE || enchantment == Enchantments.SILK_TOUCH || enchantment == Enchantments.EFFICIENCY;
}

@Override
public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
return getTypeByStack(stack) == PartType.ANNIHILATION_PLANE;
}

@Nonnull
public PartType getTypeByStack(final ItemStack is) {
Preconditions.checkNotNull(is);
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/appeng/parts/AEBasePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,19 @@ public void uploadSettings(final SettingsFrom from, final NBTTagCompound compoun
* @param from source of settings
* @return compound of source
*/
@Deprecated
protected NBTTagCompound downloadSettings(final SettingsFrom from) {
final NBTTagCompound output = new NBTTagCompound();
NBTTagCompound compound = downloadSettings(from, new NBTTagCompound());
return compound.isEmpty() ? null : compound;
}

/**
* Exports settings for attaching it to a memory card or item stack.
*
* @param from The purpose to export settings for.
* @param output The tag to write the settings to.
*/
protected NBTTagCompound downloadSettings(final SettingsFrom from, final NBTTagCompound output) {

final IConfigManager cm = this.getConfigManager();
if (cm != null) {
Expand Down Expand Up @@ -392,7 +403,7 @@ protected NBTTagCompound downloadSettings(final SettingsFrom from) {
}
}

return output.isEmpty() ? null : output;
return output;
}

public boolean useStandardMemoryCard() {
Expand All @@ -419,8 +430,8 @@ private boolean useMemoryCard(final EntityPlayer player) {
final String name = is.getTranslationKey();

if (player.isSneaking()) {
final NBTTagCompound data = this.downloadSettings(SettingsFrom.MEMORY_CARD);
if (data != null) {
final NBTTagCompound data = this.downloadSettings(SettingsFrom.MEMORY_CARD, new NBTTagCompound());
if (!data.isEmpty()) {
memoryCard.setMemoryCardContents(memCardIS, name, data);
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED);
}
Expand Down
Loading

0 comments on commit 7f2318f

Please sign in to comment.