diff --git a/TODO.txt b/TODO.txt index f5858c2..4073fef 100644 --- a/TODO.txt +++ b/TODO.txt @@ -38,4 +38,7 @@ food No Extra recipes ??? ??? Electrical-like power ??? ??? Atlases ??? ??? Alloys + Steel + Bronze + Alnico ??? ??? "Luggage" (chests with persistent contents) \ No newline at end of file diff --git a/src/java/mmm/food/FMilkBucket.java b/src/java/mmm/food/FMilkBucket.java new file mode 100644 index 0000000..afa174e --- /dev/null +++ b/src/java/mmm/food/FMilkBucket.java @@ -0,0 +1,37 @@ +package mmm.food; + + +import mmm.utils.I_UItemModelProvider; +import mmm.utils.URegistry; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Items; +import net.minecraft.item.Item; + + + +public class FMilkBucket + extends Item + implements I_UItemModelProvider +{ + + public final FMilkType milkType; + + + public FMilkBucket( FMilkType milkType ) + { + super( ); + this.milkType = milkType; + URegistry.setIdentifiers( this , "food" , "milk" , milkType.name ); + this.setMaxStackSize( 1 ); + this.setCreativeTab( CreativeTabs.MISC ); + } + + + @Override + public ModelResourceLocation getModelResourceLocation( ) + { + return new ModelResourceLocation( Items.MILK_BUCKET.getRegistryName( ) , "inventory" ); + } + +} diff --git a/src/java/mmm/food/FMilkType.java b/src/java/mmm/food/FMilkType.java new file mode 100644 index 0000000..cd1a144 --- /dev/null +++ b/src/java/mmm/food/FMilkType.java @@ -0,0 +1,93 @@ +package mmm.food; + + +import java.util.function.Predicate; + +import com.google.common.collect.HashMultimap; + +import mmm.utils.URegistry; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.passive.EntityPig; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.passive.HorseType; +import net.minecraft.init.Items; +import net.minecraft.item.Item; + + + +public class FMilkType +{ + public static final HashMultimap< Class< ? extends EntityAnimal > , FMilkType > MILK_TYPES; + + public static final FMilkType COW; + public static final FMilkType SHEEP; + public static final FMilkType PIG; + public static final FMilkType HORSE; + public static final FMilkType DONKEY; + + static { + MILK_TYPES = HashMultimap.create( ); + + COW = new FMilkType( ); + SHEEP = new FMilkType( "sheep" , EntitySheep.class ); + PIG = new FMilkType( "pig" , EntityPig.class ); + HORSE = new FMilkType( "horse" , EntityHorse.class ) + .setExtraCheck( a -> ( (EntityHorse) a ).getType( ) == HorseType.HORSE ); + DONKEY = new FMilkType( "donkey" , EntityHorse.class ) + .setExtraCheck( a -> ( (EntityHorse) a ).getType( ) == HorseType.DONKEY ); + } + + + public static void preInit( ) + { + // EMPTY + } + + public final String name; + public final boolean isVanilla; + public final Class< ? extends EntityAnimal > animal; + public final Item bucket; + private Predicate< EntityAnimal > extraCheck; + + + private FMilkType( ) + { + this( "cow" , true , EntityCow.class , Items.MILK_BUCKET ); + } + + + public FMilkType( String name , Class< ? extends EntityAnimal > animal ) + { + this( name , false , animal , null ); + } + + + private FMilkType( String name , boolean isVanilla , Class< ? extends EntityAnimal > animal , Item bucket ) + { + this.name = name; + this.isVanilla = isVanilla; + this.animal = animal; + if ( bucket == null ) { + bucket = new FMilkBucket( this ); + URegistry.addItem( bucket ); + } + this.bucket = bucket; + MILK_TYPES.put( animal , this ); + } + + + public FMilkType setExtraCheck( Predicate< EntityAnimal > extraCheck ) + { + this.extraCheck = extraCheck; + return this; + } + + + public boolean check( EntityAnimal animal ) + { + return this.extraCheck == null || this.extraCheck.test( animal ); + } + +} diff --git a/src/java/mmm/food/FMilkingHandler.java b/src/java/mmm/food/FMilkingHandler.java new file mode 100644 index 0000000..8c778ba --- /dev/null +++ b/src/java/mmm/food/FMilkingHandler.java @@ -0,0 +1,65 @@ +package mmm.food; + + +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + + + +public class FMilkingHandler +{ + + @SubscribeEvent + public void handleMilking( PlayerInteractEvent.EntityInteract event ) + { + ItemStack heldStack = event.getItemStack( ); + if ( heldStack == null || heldStack.getItem( ) != Items.BUCKET ) { + return; + } + Entity target = event.getTarget( ); + if ( ! ( target instanceof EntityAnimal ) ) { + return; + } + + EntityAnimal animal = (EntityAnimal) target; + if ( animal.isChild( ) ) { + return; + } + + if ( !FMilkType.MILK_TYPES.containsKey( animal.getClass( ) ) ) { + return; + } + + Set< FMilkType > milkTypes = FMilkType.MILK_TYPES.get( animal.getClass( ) ); + FMilkType milkType = null; + for ( FMilkType type : milkTypes ) { + if ( type.check( animal ) ) { + milkType = type; + break; + } + } + if ( milkType == null ) { + return; + } + + EntityPlayer player = event.getEntityPlayer( ); + if ( !milkType.isVanilla || player.capabilities.isCreativeMode ) { + ItemStack bucket = new ItemStack( milkType.bucket ); + if ( --heldStack.stackSize == 0 ) { + player.setHeldItem( event.getHand( ) , bucket ); + } else if ( !player.inventory.addItemStackToInventory( bucket ) ) { + player.dropItem( bucket , false ); + } + player.playSound( SoundEvents.ENTITY_COW_MILK , 1.0F , 1.0F ); + } + } + +} diff --git a/src/java/mmm/food/Food.java b/src/java/mmm/food/Food.java new file mode 100644 index 0000000..91ec215 --- /dev/null +++ b/src/java/mmm/food/Food.java @@ -0,0 +1,22 @@ +package mmm.food; + + +import net.minecraftforge.common.MinecraftForge; + + + +public class Food +{ + + static { + FMilkType.preInit( ); + MinecraftForge.EVENT_BUS.register( new FMilkingHandler( ) ); + } + + + public static void preInit( ) + { + // EMPTY + } + +} diff --git a/src/java/mmm/proxy/PCommon.java b/src/java/mmm/proxy/PCommon.java index abad892..771fe50 100644 --- a/src/java/mmm/proxy/PCommon.java +++ b/src/java/mmm/proxy/PCommon.java @@ -3,6 +3,7 @@ package mmm.proxy; import mmm.Mmm; import mmm.deco.DecorativeBlocks; +import mmm.food.Food; import mmm.materials.Materials; import mmm.tech.tools.Tools; import mmm.utils.UAccessors; @@ -21,9 +22,10 @@ public abstract class PCommon { UAccessors.preInit( ); - DecorativeBlocks.preInit( ); Materials.preInit( ); Tools.preInit( ); + Food.preInit( ); + DecorativeBlocks.preInit( ); URegistry.registerRecipes( ); } diff --git a/src/java/mmm/utils/I_UItemModelProvider.java b/src/java/mmm/utils/I_UItemModelProvider.java new file mode 100644 index 0000000..3512e16 --- /dev/null +++ b/src/java/mmm/utils/I_UItemModelProvider.java @@ -0,0 +1,10 @@ +package mmm.utils; + +import net.minecraft.client.renderer.block.model.ModelResourceLocation; + +public interface I_UItemModelProvider +{ + + public ModelResourceLocation getModelResourceLocation( ); + +} diff --git a/src/java/mmm/utils/URegistry.java b/src/java/mmm/utils/URegistry.java index d1f8db3..a87f2fd 100644 --- a/src/java/mmm/utils/URegistry.java +++ b/src/java/mmm/utils/URegistry.java @@ -142,8 +142,13 @@ public class URegistry continue; } final Item item = entry.getKey( ); - ModelLoader.setCustomModelResourceLocation( item , 0 , - new ModelResourceLocation( item.getRegistryName( ) , "inventory" ) ); + ModelResourceLocation location; + if ( item instanceof I_UItemModelProvider ) { + location = ( (I_UItemModelProvider) item ).getModelResourceLocation( ); + } else { + location = new ModelResourceLocation( item.getRegistryName( ) , "inventory" ); + } + ModelLoader.setCustomModelResourceLocation( item , 0 , location ); } } } diff --git a/src/resources/assets/mmm/lang/en_US.lang b/src/resources/assets/mmm/lang/en_US.lang index a3d19ce..143c1cf 100644 --- a/src/resources/assets/mmm/lang/en_US.lang +++ b/src/resources/assets/mmm/lang/en_US.lang @@ -40,4 +40,11 @@ item.mmm.tech.tools.copper.sword.name=Copper Sword item.mmm.tech.tools.copper.armor.feet.name=Copper Boots item.mmm.tech.tools.copper.armor.legs.name=Copper Leggings item.mmm.tech.tools.copper.armor.chest.name=Copper Chestplate -item.mmm.tech.tools.copper.armor.head.name=Copper Helmet \ No newline at end of file +item.mmm.tech.tools.copper.armor.head.name=Copper Helmet + + +item.milk.name=Cow milk +item.mmm.food.milk.sheep.name=Sheep milk +item.mmm.food.milk.pig.name=Pig milk +item.mmm.food.milk.horse.name=Horse milk +item.mmm.food.milk.donkey.name=Donkey milk