Skip to content

Commit

Permalink
Make plants plantable on purified swamp dirt
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCyberBrick committed Jan 5, 2023
1 parent 60b5ed4 commit 3911c98
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
10 changes: 7 additions & 3 deletions src/main/java/thebetweenlands/common/item/IGenericItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

Expand Down Expand Up @@ -70,7 +72,7 @@ static class TypeContainer {
* @param type
* @return
*/
public static List<IGenericItem> getGenericItems(Class<? extends Enum<?>> type) {
public static <X extends Enum<?> & IGenericItem> List<IGenericItem> getGenericItems(Class<? extends X> type) {
List<IGenericItem> genericItems = TYPE_CONTAINER.typeToItems.get(type);
if(genericItems == null) {
if(!IGenericItem.class.isAssignableFrom(type))
Expand All @@ -88,7 +90,8 @@ public static List<IGenericItem> getGenericItems(Class<? extends Enum<?>> type)
* @param id
* @return
*/
public static IGenericItem getFromID(Class<? extends Enum<?>> type, int id) {
@Nullable
public static <X extends Enum<?> & IGenericItem> IGenericItem getFromID(Class<? extends X> type, int id) {
for(IGenericItem item : getGenericItems(type)) {
if(item.getID() == id)
return item;
Expand All @@ -102,7 +105,8 @@ public static IGenericItem getFromID(Class<? extends Enum<?>> type, int id) {
* @param stack
* @return
*/
public static IGenericItem getFromStack(Class<? extends Enum<?>> type, ItemStack stack) {
@Nullable
public static <X extends Enum<?> & IGenericItem> IGenericItem getFromStack(Class<? extends X> type, ItemStack stack) {
return stack.isEmpty() ? null : getFromID(type, stack.getItemDamage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {

@Override
public String getTranslationKey(ItemStack stack) {
try {
return "item.thebetweenlands." + IGenericItem.getFromStack(EnumItemCrushed.class, stack).getTranslationKey();
} catch (Exception e) {
return "item.thebetweenlands.unknown_crushed";
IGenericItem item = IGenericItem.getFromStack(EnumItemCrushed.class, stack);
if(item != null) {
return "item.thebetweenlands." + item.getTranslationKey();
}
return "item.thebetweenlands.unknown_crushed";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> list) {

@Override
public String getTranslationKey(ItemStack stack) {
try {
return "item.thebetweenlands." + IGenericItem.getFromStack(EnumItemPlantDrop.class, stack).getTranslationKey();
} catch (Exception e) {
return "item.thebetweenlands.unknown_plant_drop";
IGenericItem item = IGenericItem.getFromStack(EnumItemPlantDrop.class, stack);
if(item != null) {
return "item.thebetweenlands." + item.getTranslationKey();
}
return "item.thebetweenlands.unknown_plant_drop";
}

@Override
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/thebetweenlands/common/item/misc/ItemMisc.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ public ItemMisc() {
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
String key = "tooltip.bl.item_misc." + IGenericItem.getFromStack(EnumItemMisc.class, stack).getTranslationKey();
IGenericItem item = IGenericItem.getFromStack(EnumItemMisc.class, stack);

if(item != null) {
String key = "tooltip.bl.item_misc." + item.getTranslationKey();

if(I18n.hasKey(key)) {
tooltip.add(I18n.format(key));
if(I18n.hasKey(key)) {
tooltip.add(I18n.format(key));
}
}
}

Expand All @@ -74,11 +78,11 @@ public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> list) {

@Override
public String getTranslationKey(ItemStack stack) {
try {
return "item.thebetweenlands." + IGenericItem.getFromStack(EnumItemMisc.class, stack).getTranslationKey();
} catch (Exception e) {
return "item.thebetweenlands.unknown_generic";
IGenericItem item = IGenericItem.getFromStack(EnumItemMisc.class, stack);
if(item != null) {
return "item.thebetweenlands." + item.getTranslationKey();
}
return "item.thebetweenlands.unknown_generic";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {

@Override
public String getTranslationKey(ItemStack stack) {
try {
return "item.thebetweenlands." + IGenericItem.getFromStack(EnumTalisman.class, stack).getTranslationKey();
} catch (Exception e) {
return "item.thebetweenlands.unknown_talisman";
IGenericItem item = IGenericItem.getFromStack(EnumTalisman.class, stack);
if(item != null) {
return "item.thebetweenlands." + item.getTranslationKey();
}
return "item.thebetweenlands.unknown_talisman";
}

@SideOnly(Side.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ public enum SurfaceType implements Predicate<IBlockState> {
BlockMatcher.forBlock(Blocks.GRASS),
BlockMatcher.forBlock(Blocks.MYCELIUM),
BlockMatcher.forBlock(BlockRegistry.SWAMP_GRASS),
BlockMatcher.forBlock(BlockRegistry.DUG_PURIFIED_SWAMP_GRASS),
BlockMatcher.forBlock(BlockRegistry.DEAD_GRASS)
)),
DIRT(ImmutableList.of(
BlockMatcher.forBlock(BlockRegistry.SWAMP_DIRT),
BlockMatcher.forBlock(BlockRegistry.PURIFIED_SWAMP_DIRT),
BlockMatcher.forBlock(BlockRegistry.DUG_SWAMP_DIRT),
BlockMatcher.forBlock(Blocks.DIRT),
BlockMatcher.forBlock(BlockRegistry.MUD),
BlockMatcher.forBlock(BlockRegistry.COMPACTED_MUD),
Expand Down

0 comments on commit 3911c98

Please sign in to comment.