Skip to content

Commit

Permalink
Add Swap Test items
Browse files Browse the repository at this point in the history
  • Loading branch information
Choonster committed Oct 4, 2015
1 parent 763c40d commit 85136f5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
Expand Up @@ -103,6 +103,8 @@ private void registerItemModels() {
registerItemModel(ModItems.snowballLauncher, "minecraft:fishing_rod");
registerItemModel(ModItems.slingshot);
registerItemModel(ModItems.unicodeTooltips, "minecraft:rabbit");
registerItemModel(ModItems.swapTestA, "minecraft:brick");
registerItemModel(ModItems.swapTestB, "minecraft:netherbrick");
}

private void registerItemModel(Item item) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/choonster/testmod3/init/ModItems.java
Expand Up @@ -22,6 +22,8 @@ public class ModItems {
public static ItemSnowballLauncher snowballLauncher;
public static ItemSlingshot slingshot;
public static ItemUnicodeTooltips unicodeTooltips;
public static ItemSwapTest swapTestA;
public static ItemSwapTest swapTestB;

public static Item.ToolMaterial TOOL_MATERIAL_GLOWSTONE;

Expand Down Expand Up @@ -55,6 +57,11 @@ public static void registerItems() {

unicodeTooltips = registerItem(new ItemUnicodeTooltips());

swapTestA = registerItem(new ItemSwapTest("A"));
swapTestB = registerItem(new ItemSwapTest("B"));
swapTestA.setOtherItem(new ItemStack(swapTestB));
swapTestB.setOtherItem(new ItemStack(swapTestA));

TOOL_MATERIAL_GLOWSTONE = EnumHelper.addToolMaterial("glowstone", 1, 5, 0.5f, 1.0f, 10).setRepairItem(new ItemStack(Items.glowstone_dust));
}

Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/choonster/testmod3/item/ItemSwapTest.java
@@ -0,0 +1,53 @@
package com.choonster.testmod3.item;

import com.choonster.testmod3.TestMod3;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;

import java.util.List;

/**
* An item that's converted to another when shift-right clicked.
* <p>
* Test for this thread:
* http://www.minecraftforge.net/forum/index.php/topic,34244.0.html
*/
public class ItemSwapTest extends Item {
private ItemStack otherItem;

public ItemSwapTest(String name) {
setCreativeTab(TestMod3.creativeTab);
setUnlocalizedName("swapTest" + name);
}

public boolean hasOtherItem() {
return otherItem != null;
}

public void setOtherItem(ItemStack otherItem) {
this.otherItem = otherItem;
}

@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) {
super.addInformation(stack, playerIn, tooltip, advanced);

if (hasOtherItem()) {
tooltip.add(StatCollector.translateToLocalFormatted("item.swapTestWithItem.desc", otherItem.getDisplayName()));
} else {
tooltip.add(StatCollector.translateToLocal("item.swapTestWithoutItem.desc"));
}
}

@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
if (hasOtherItem() && playerIn.isSneaking()) {
return otherItem.copy();
}

return super.onItemRightClick(itemStackIn, worldIn, playerIn);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/testmod3/lang/en_US.lang
Expand Up @@ -36,11 +36,15 @@ item.entityTest.name=Entity Test
item.blockDestroyer.name=Block Destroyer
item.woodenAxe.name=Wooden Cutting Axe
item.unicodeTooltips.name=Unicode Tooltips
item.swapTestA.name=Swap Test A
item.swapTestB.name=Swap Test B

# Tooltips
item.unicodeTooltips.desc.1=§a§oLine 1 (Section Characters in Lang File)§r
item.unicodeTooltips.desc.2=Line 2 (Section Characters in Code)
item.unicodeTooltips.desc.3=Line 3 (EnumChatFormatting)
item.swapTestWithItem.desc=Shift-right click to convert to %s
item.swapTestWithoutItem.desc=No conversion defined for this item

# Chat messages
message.entityInteractCount=Interact count: %s
Expand Down

0 comments on commit 85136f5

Please sign in to comment.