Skip to content

Commit 7f2318f

Browse files
Add Annihilation Plane enchantment support, deprecate Identity (AE2-UEL#510)
1 parent 925cf09 commit 7f2318f

File tree

15 files changed

+365
-78
lines changed

15 files changed

+365
-78
lines changed

src/main/java/appeng/core/localization/GuiText.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ public enum GuiText {
209209

210210
// Used in Crafting Toasts
211211
CraftingToastDone,
212-
CraftingToastCancelled;
212+
CraftingToastCancelled,
213+
214+
CanBeEnchanted,
215+
IncreasedEnergyUseFromEnchants,
216+
Deprecated;
213217

214218
private final String root;
215219

src/main/java/appeng/core/localization/WailaText.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public enum WailaText {
4141
Showing,
4242

4343
Contains,
44-
Channels;
44+
Channels,
45+
EnchantedWith,
46+
IdentityDeprecated;
4547

4648
private final String root;
4749

src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ public PartWailaDataProvider() {
6969
final IPartWailaDataProvider powerState = new PowerStateWailaDataProvider();
7070
final IPartWailaDataProvider p2pState = new P2PStateWailaDataProvider();
7171
final IPartWailaDataProvider partStack = new PartStackWailaDataProvider();
72+
final IPartWailaDataProvider annihilationPlane = new AnnihilationPlaneDataProvider();
7273

73-
this.providers = Lists.newArrayList(channel, storageMonitor, powerState, partStack, p2pState);
74+
this.providers = Lists.newArrayList(channel, storageMonitor, powerState, partStack, p2pState, annihilationPlane);
7475
}
7576

7677
@Override
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package appeng.integration.modules.waila.part;
2+
3+
import appeng.api.parts.IPart;
4+
import appeng.core.localization.WailaText;
5+
import appeng.parts.automation.PartAnnihilationPlane;
6+
import appeng.parts.automation.PartIdentityAnnihilationPlane;
7+
import appeng.util.EnchantmentUtil;
8+
import mcp.mobius.waila.api.IWailaConfigHandler;
9+
import mcp.mobius.waila.api.IWailaDataAccessor;
10+
import net.minecraft.enchantment.Enchantment;
11+
import net.minecraft.entity.player.EntityPlayerMP;
12+
import net.minecraft.nbt.NBTTagCompound;
13+
import net.minecraft.tileentity.TileEntity;
14+
import net.minecraft.util.math.BlockPos;
15+
import net.minecraft.world.World;
16+
17+
import java.util.List;
18+
import java.util.Map;
19+
20+
public class AnnihilationPlaneDataProvider extends BasePartWailaDataProvider {
21+
@Override
22+
public List<String> getWailaBody(IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
23+
if (part instanceof PartIdentityAnnihilationPlane) {
24+
currentToolTip.add(WailaText.IdentityDeprecated.getLocal());
25+
} else if (part instanceof PartAnnihilationPlane plane) {
26+
NBTTagCompound nbtData = accessor.getNBTData();
27+
Map<Enchantment, Integer> enchantments = EnchantmentUtil.getEnchantments(nbtData);
28+
if (!enchantments.isEmpty()) {
29+
currentToolTip.add(WailaText.EnchantedWith.getLocal());
30+
for (var enchantment : enchantments.keySet()) {
31+
currentToolTip.add(enchantment.getTranslatedName(enchantments.get(enchantment)));
32+
}
33+
}
34+
}
35+
36+
return currentToolTip;
37+
}
38+
39+
@Override
40+
public NBTTagCompound getNBTData(EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
41+
if (part instanceof PartAnnihilationPlane plane) {
42+
plane.writeEnchantments(tag);
43+
}
44+
45+
return tag;
46+
}
47+
}

src/main/java/appeng/items/AEBaseItem.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ public final void getSubItems(final CreativeTabs creativeTab, final NonNullList<
5757
}
5858
}
5959

60-
@Override
61-
public boolean isBookEnchantable(final ItemStack itemstack1, final ItemStack itemstack2) {
62-
return false;
63-
}
64-
6560
@SideOnly(Side.CLIENT)
6661
protected void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
6762
super.addInformation(stack, world, lines, advancedTooltips);

src/main/java/appeng/items/parts/ItemPart.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
import appeng.items.AEBaseItem;
3131
import com.google.common.base.Preconditions;
3232
import com.google.common.collect.ImmutableSet;
33+
import net.minecraft.client.util.ITooltipFlag;
3334
import net.minecraft.creativetab.CreativeTabs;
35+
import net.minecraft.enchantment.Enchantment;
36+
import net.minecraft.enchantment.EnchantmentHelper;
3437
import net.minecraft.entity.player.EntityPlayer;
38+
import net.minecraft.init.Enchantments;
3539
import net.minecraft.item.ItemStack;
3640
import net.minecraft.util.EnumActionResult;
3741
import net.minecraft.util.EnumFacing;
@@ -133,10 +137,20 @@ public int getDamageByType(final PartType t) {
133137

134138
@Override
135139
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) {
136-
if (this.getTypeByStack(player.getHeldItem(hand)) == PartType.INVALID_TYPE) {
140+
ItemStack heldItem = player.getHeldItem(hand);
141+
PartType typeByStack = getTypeByStack(heldItem);
142+
if (typeByStack == PartType.INVALID_TYPE) {
137143
return EnumActionResult.FAIL;
138144
}
139145

146+
if (player.isSneaking() && typeByStack == PartType.IDENTITY_ANNIHILATION_PLANE) {
147+
ItemStack newPlane = new ItemStack(this, heldItem.getCount(), PartType.ANNIHILATION_PLANE.getBaseDamage());
148+
newPlane.addEnchantment(Enchantments.SILK_TOUCH,1);
149+
150+
player.setHeldItem(hand, newPlane);
151+
return EnumActionResult.SUCCESS;
152+
}
153+
140154
return AEApi.instance().partHelper().placeBus(player.getHeldItem(hand), pos, side, player, hand, w);
141155
}
142156

@@ -178,6 +192,43 @@ protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullL
178192
}
179193
}
180194

195+
@Override
196+
protected void addCheckedInformation(ItemStack stack, World world, List<String> lines, ITooltipFlag advancedTooltips) {
197+
if (getTypeByStack(stack) == PartType.ANNIHILATION_PLANE) {
198+
var enchantments = EnchantmentHelper.getEnchantments(stack);
199+
if (enchantments.isEmpty()) {
200+
lines.add(GuiText.CanBeEnchanted.getLocal());
201+
}
202+
else {
203+
lines.add(GuiText.IncreasedEnergyUseFromEnchants.getLocal());
204+
}
205+
}
206+
207+
if (getTypeByStack(stack) == PartType.IDENTITY_ANNIHILATION_PLANE) {
208+
lines.add(GuiText.Deprecated.getLocal());
209+
}
210+
}
211+
212+
@Override
213+
public int getItemEnchantability() {
214+
return 10;
215+
}
216+
217+
@Override
218+
public boolean isEnchantable(ItemStack stack) {
219+
return getTypeByStack(stack) == PartType.ANNIHILATION_PLANE;
220+
}
221+
222+
@Override
223+
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
224+
return enchantment == Enchantments.UNBREAKING || enchantment == Enchantments.FORTUNE || enchantment == Enchantments.SILK_TOUCH || enchantment == Enchantments.EFFICIENCY;
225+
}
226+
227+
@Override
228+
public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
229+
return getTypeByStack(stack) == PartType.ANNIHILATION_PLANE;
230+
}
231+
181232
@Nonnull
182233
public PartType getTypeByStack(final ItemStack is) {
183234
Preconditions.checkNotNull(is);

src/main/java/appeng/parts/AEBasePart.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,19 @@ public void uploadSettings(final SettingsFrom from, final NBTTagCompound compoun
359359
* @param from source of settings
360360
* @return compound of source
361361
*/
362+
@Deprecated
362363
protected NBTTagCompound downloadSettings(final SettingsFrom from) {
363-
final NBTTagCompound output = new NBTTagCompound();
364+
NBTTagCompound compound = downloadSettings(from, new NBTTagCompound());
365+
return compound.isEmpty() ? null : compound;
366+
}
367+
368+
/**
369+
* Exports settings for attaching it to a memory card or item stack.
370+
*
371+
* @param from The purpose to export settings for.
372+
* @param output The tag to write the settings to.
373+
*/
374+
protected NBTTagCompound downloadSettings(final SettingsFrom from, final NBTTagCompound output) {
364375

365376
final IConfigManager cm = this.getConfigManager();
366377
if (cm != null) {
@@ -392,7 +403,7 @@ protected NBTTagCompound downloadSettings(final SettingsFrom from) {
392403
}
393404
}
394405

395-
return output.isEmpty() ? null : output;
406+
return output;
396407
}
397408

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

421432
if (player.isSneaking()) {
422-
final NBTTagCompound data = this.downloadSettings(SettingsFrom.MEMORY_CARD);
423-
if (data != null) {
433+
final NBTTagCompound data = this.downloadSettings(SettingsFrom.MEMORY_CARD, new NBTTagCompound());
434+
if (!data.isEmpty()) {
424435
memoryCard.setMemoryCardContents(memCardIS, name, data);
425436
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED);
426437
}

0 commit comments

Comments
 (0)