Milk basics
+ Various milk types + Handle milking of pigs, sheep, horses and donkeys + Allow milking of cows in creative mode + Rename default milk bucket to "Cow milk"
This commit is contained in:
parent
7226a03d24
commit
f404da6034
9 changed files with 248 additions and 4 deletions
3
TODO.txt
3
TODO.txt
|
@ -38,4 +38,7 @@ food No Extra recipes
|
|||
??? ??? Electrical-like power
|
||||
??? ??? Atlases
|
||||
??? ??? Alloys
|
||||
Steel
|
||||
Bronze
|
||||
Alnico
|
||||
??? ??? "Luggage" (chests with persistent contents)
|
37
src/java/mmm/food/FMilkBucket.java
Normal file
37
src/java/mmm/food/FMilkBucket.java
Normal file
|
@ -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" );
|
||||
}
|
||||
|
||||
}
|
93
src/java/mmm/food/FMilkType.java
Normal file
93
src/java/mmm/food/FMilkType.java
Normal file
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
65
src/java/mmm/food/FMilkingHandler.java
Normal file
65
src/java/mmm/food/FMilkingHandler.java
Normal file
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
22
src/java/mmm/food/Food.java
Normal file
22
src/java/mmm/food/Food.java
Normal file
|
@ -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
|
||||
}
|
||||
|
||||
}
|
|
@ -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( );
|
||||
}
|
||||
|
|
10
src/java/mmm/utils/I_UItemModelProvider.java
Normal file
10
src/java/mmm/utils/I_UItemModelProvider.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package mmm.utils;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
|
||||
public interface I_UItemModelProvider
|
||||
{
|
||||
|
||||
public ModelResourceLocation getModelResourceLocation( );
|
||||
|
||||
}
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,3 +41,10 @@ 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
|
||||
|
||||
|
||||
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
|
||||
|
|
Reference in a new issue