From b6bf393ee77e09c4ca868cc84764cdeb582b8ffd Mon Sep 17 00:00:00 2001 From: Peter McMurray Date: Tue, 7 Nov 2017 22:43:09 +1100 Subject: [PATCH] Slimes In A Bucket --- .../betterstorage/item/ItemBucketSlime.java | 447 ------------- .../common/item/BetterStorageItems.java | 10 +- .../common/item/ItemBucketSlime.java | 617 ++++++++++++++++++ .../config/BetterStorageConfig.java | 36 +- .../event/BetterStorageEventHandler.java | 43 +- .../betterstorage/proxy/CommonProxy.java | 35 +- .../assets/betterstorage/lang/en_us.lang | 3 + .../models/item/bucket_blue_slime.json | 8 + .../models/item/bucket_magma_cube.json | 8 + .../models/item/bucket_maze_slime.json | 8 + .../models/item/bucket_pink_slime.json | 8 + .../models/item/bucket_slime.json | 8 + .../models/item/bucket_thaumic_slime.json | 8 + .../models/item/slime_bucket.json | 8 - ...me_blueSlime.png => bucket_blue_slime.png} | Bin ...bucketSlime_empty.png => bucket_empty.png} | Bin ...me_magmaCube.png => bucket_magma_cube.png} | Bin ...me_mazeSlime.png => bucket_maze_slime.png} | Bin ...me_pinkSlime.png => bucket_pink_slime.png} | Bin ...bucketSlime_slime.png => bucket_slime.png} | Bin ...umicSlime.png => bucket_thaumic_slime.png} | Bin 21 files changed, 736 insertions(+), 511 deletions(-) delete mode 100644 old_src/main/java/net/mcft/copy/betterstorage/item/ItemBucketSlime.java create mode 100644 src/main/java/io/github/tehstoneman/betterstorage/common/item/ItemBucketSlime.java create mode 100644 src/main/resources/assets/betterstorage/models/item/bucket_blue_slime.json create mode 100644 src/main/resources/assets/betterstorage/models/item/bucket_magma_cube.json create mode 100644 src/main/resources/assets/betterstorage/models/item/bucket_maze_slime.json create mode 100644 src/main/resources/assets/betterstorage/models/item/bucket_pink_slime.json create mode 100644 src/main/resources/assets/betterstorage/models/item/bucket_slime.json create mode 100644 src/main/resources/assets/betterstorage/models/item/bucket_thaumic_slime.json delete mode 100644 src/main/resources/assets/betterstorage/models/item/slime_bucket.json rename src/main/resources/assets/betterstorage/textures/items/{bucketSlime_blueSlime.png => bucket_blue_slime.png} (100%) rename src/main/resources/assets/betterstorage/textures/items/{bucketSlime_empty.png => bucket_empty.png} (100%) rename src/main/resources/assets/betterstorage/textures/items/{bucketSlime_magmaCube.png => bucket_magma_cube.png} (100%) rename src/main/resources/assets/betterstorage/textures/items/{bucketSlime_mazeSlime.png => bucket_maze_slime.png} (100%) rename src/main/resources/assets/betterstorage/textures/items/{bucketSlime_pinkSlime.png => bucket_pink_slime.png} (100%) rename src/main/resources/assets/betterstorage/textures/items/{bucketSlime_slime.png => bucket_slime.png} (100%) rename src/main/resources/assets/betterstorage/textures/items/{bucketSlime_thaumicSlime.png => bucket_thaumic_slime.png} (100%) diff --git a/old_src/main/java/net/mcft/copy/betterstorage/item/ItemBucketSlime.java b/old_src/main/java/net/mcft/copy/betterstorage/item/ItemBucketSlime.java deleted file mode 100644 index 8b4b3971..00000000 --- a/old_src/main/java/net/mcft/copy/betterstorage/item/ItemBucketSlime.java +++ /dev/null @@ -1,447 +0,0 @@ -package io.github.tehstoneman.betterstorage.item; - -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.github.tehstoneman.betterstorage.BetterStorage; -import io.github.tehstoneman.betterstorage.common.item.BetterStorageItems; -import io.github.tehstoneman.betterstorage.utils.LanguageUtils; -import io.github.tehstoneman.betterstorage.utils.StackUtils; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.monster.EntitySlime; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.Items; -import net.minecraft.init.SoundEvents; -import net.minecraft.item.EnumAction; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.StringUtils; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.world.World; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class ItemBucketSlime extends Item -{ - private static Map< String, Handler > handlers = new HashMap<>(); - - public ItemBucketSlime() - { - setContainerItem( Items.BUCKET ); - setMaxStackSize( 0 ); - setMaxDamage( 0 ); - setHasSubtypes( true ); - } - - @Override - public String getUnlocalizedName( ItemStack stack ) - { - final String id = getSlimeId( stack ); - final Handler handler = getHandler( id ); - final String name = StackUtils.get( stack, (String)null, "Slime", "name" ); - if( name != null ) - return super.getUnlocalizedName() + "." + name; - return super.getUnlocalizedName(); - } - - @Override - @SideOnly( Side.CLIENT ) - public boolean hasEffect( ItemStack stack ) - { - return stack.isItemEnchanted() || StackUtils.has( stack, "Effects" ); - } - - @Override - @SideOnly( Side.CLIENT ) - public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean advancedTooltips ) - { - - final String id = getSlimeId( stack ); - final Handler handler = getHandler( id ); - final String name = StackUtils.get( stack, (String)null, "Slime", "name" ); - if( name != null || advancedTooltips ) - list.add( "Contains: " + ( name != null ? "\"" + name + "\"" + ( advancedTooltips ? " (" + id + ")" : "" ) : id ) ); - - final NBTTagList effectList = (NBTTagList)StackUtils.getTag( stack, "Effects" ); - if( effectList != null && handler != null ) - { - final int max = advancedTooltips || GuiScreen.isShiftKeyDown() ? 6 : 3; - - for( int i = 0; i < Math.min( effectList.tagCount(), max ); i++ ) - { - final PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT( effectList.getCompoundTagAt( i ) ); - final Potion potion = effect.getPotion(); - final int duration = (int)( effect.getDuration() * handler.durationMultiplier() ); - - final StringBuilder str = new StringBuilder().append( potion.isBadEffect() ? TextFormatting.RED : TextFormatting.GRAY ) - .append( BetterStorage.proxy.localize( effect.getEffectName() ) ); - - if( effect.getAmplifier() > 0 ) - str.append( " " ).append( BetterStorage.proxy.localize( "potion.potency." + effect.getAmplifier() ) ); - - str.append( " (" ).append( StringUtils.ticksToElapsedTime( duration ) ).append( ")" ); - - list.add( str.toString() ); - } - - final int more = effectList.tagCount() - max; - - if( more > 0 ) - list.add( TextFormatting.DARK_GRAY.toString() + TextFormatting.ITALIC - + LanguageUtils.translateTooltip( "bucketSlime.more." + ( more == 1 ? "1" : "x" ), "%X%", Integer.toString( more ) ) ); - - } - - } - - @Override - public EnumActionResult onItemUse( ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, - float hitY, float hitZ ) - { - // If player is sneaking, eat slime - // instead of placing it in the world. - if( player.isSneaking() ) - return EnumActionResult.FAIL; - - if( world.isRemote ) - return EnumActionResult.PASS; - - pos.add( side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ() ); - - final String id = getSlimeId( stack ); - final String name = StackUtils.get( stack, (String)null, "Slime", "name" ); - final Entity entity = EntityList.createEntityByName( id, world ); - final Handler handler = getHandler( id ); - - if( entity != null && handler != null && entity instanceof EntityLiving ) - { - final EntityLiving slime = (EntityLiving)entity; - - final float rotation = MathHelper.wrapDegrees( world.rand.nextFloat() * 360.0F ); - slime.setLocationAndAngles( pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, rotation, 0.0F ); - slime.rotationYawHead = slime.renderYawOffset = rotation; - - if( name != null ) - slime.setCustomNameTag( name ); - handler.setSize( slime, 1 ); - - final NBTTagList effectList = (NBTTagList)StackUtils.getTag( stack, "Effects" ); - if( effectList != null ) - for( int i = 0; i < effectList.tagCount(); i++ ) - slime.addPotionEffect( PotionEffect.readCustomPotionEffectFromNBT( effectList.getCompoundTagAt( i ) ) ); - - world.spawnEntityInWorld( slime ); - slime.playSound( SoundEvents.ENTITY_SLIME_JUMP, 1.2F, 0.6F ); - - player.setHeldItem( EnumHand.MAIN_HAND, new ItemStack( Items.BUCKET ) ); - } - - return EnumActionResult.SUCCESS; - } - - // Eating slime - - @Override - public EnumAction getItemUseAction( ItemStack stack ) - { - return EnumAction.DRINK; - } - - @Override - public int getMaxItemUseDuration( ItemStack stack ) - { - return 48; - } - - @Override - public ActionResult< ItemStack > onItemRightClick( ItemStack stack, World world, EntityPlayer player, EnumHand hand ) - { - /* - * if( hand == EnumHand.MAIN_HAND) - * { - * player.setItemInUse(stack, getMaxItemUseDuration(stack)); - * return stack; - * } - */ - return super.onItemRightClick( stack, world, player, hand ); - } - - /* - * @Override - * public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) { - * Handler handler = getHandler(stack); - * if (handler != null) { - * player.getFoodStats().addStats(handler.foodAmount(), handler.saturationAmount()); - * NBTTagList effectList = (NBTTagList)StackUtils.getTag(stack, "Effects"); - * if (effectList != null) { - * for (int i = 0; i < effectList.tagCount(); i++) { - * PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(effectList.getCompoundTagAt(i)); - * int duration = (int)(effect.getDuration() * handler.durationMultiplier()); - * effect = new PotionEffect(effect.getPotionID(), duration, effect.getAmplifier()); - * player.addPotionEffect(effect); - * } - * } - * handler.onEaten(player, false); - * } - * return new ItemStack(Items.BUCKET); - * } - */ - - // Helper functions - - /** - * Called when a player right clicks an entity with an empty bucket. - * If the entity clicked is a small slime, attempts to pick it up and - * sets the held item to a Slime in a Bucket containing that slime. - */ - public static void pickUpSlime( EntityPlayer player, EntityLiving slime ) - { - final Handler handler = getHandler( slime ); - - if( slime.isDead || handler == null || handler.getSize( slime ) != 1 ) - return; - - final ItemStack stack = new ItemStack( BetterStorageItems.SLIME_BUCKET ); - - final String entityId = EntityList.getEntityString( slime ); - if( !entityId.equals( "Slime" ) ) - StackUtils.set( stack, entityId, "Slime", "id" ); - if( slime.hasCustomName() ) - StackUtils.set( stack, slime.getCustomNameTag(), "Slime", "name" ); - - final Collection< PotionEffect > effects = slime.getActivePotionEffects(); - if( !effects.isEmpty() ) - { - final NBTTagList effectList = new NBTTagList(); - for( final PotionEffect effect : effects ) - effectList.appendTag( effect.writeCustomPotionEffectToNBT( new NBTTagCompound() ) ); - StackUtils.set( stack, effectList, "Effects" ); - } - - if( --player.getHeldItemMainhand().stackSize <= 0 ) - player.setHeldItem( EnumHand.MAIN_HAND, stack ); - /* - * else if (!player.inventory.addItemStackToInventory(stack)) - * player.dropPlayerItemWithRandomChoice(stack, true); - */ - else - ( (EntityPlayerMP)player ).inventoryContainer.detectAndSendChanges(); - - slime.playSound( SoundEvents.ENTITY_SLIME_JUMP, 1.2F, 0.8F ); - slime.isDead = true; - } - - /** Returns the slime ID from a slime bucket. */ - public static String getSlimeId( ItemStack stack ) - { - return StackUtils.get( stack, "Slime", "Slime", "id" ); - } - - /** Registers a slime handler. */ - public static void registerHandler( Handler handler ) - { - handlers.put( handler.entityName, handler ); - } - - /** Returns the handler for an entity id, null if none. */ - public static Handler getHandler( String id ) - { - return handlers.get( id ); - } - - /** Returns the handler for an entity, null if none. */ - public static Handler getHandler( EntityLiving slime ) - { - return getHandler( EntityList.getEntityString( slime ) ); - } - - /** Returns the handler for slime bucket, null if none. */ - public static Handler getHandler( ItemStack stack ) - { - return getHandler( getSlimeId( stack ) ); - } - - // Slime handlers - - static - { - registerHandler( new Handler( "slime", "Slime" ) - { - @Override - public int foodAmount() - { - return 3; - } - - @Override - public float saturationAmount() - { - return 0.2F; - } - } ); - registerHandler( new Handler( "magmaCube", "LavaSlime" ) - { - @Override - public float durationMultiplier() - { - return 0.4F; - } - /* - * @Override public void onEaten(EntityPlayer player, boolean potionEffects) { - * player.setFire(2); - * player.addPotionEffect(new PotionEffect(Potion.jump.id, (potionEffects ? 10 : 20) * 20, - * (potionEffects ? 2 : 3))); - * player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, (potionEffects ? 24 : 32) * 20, 0)); - * } - */} ); - registerHandler( new Handler( "mazeSlime", "TwilightForest.Maze Slime" ) - { - /* - * @Override public void onEaten(EntityPlayer player, boolean potionEffects) { - * player.attackEntityFrom(DamageSource.magic, 3.0F); - * player.addPotionEffect(new PotionEffect(Potion.jump.id, (potionEffects ? 4 : 8) * 20, 0)); - * player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, (potionEffects ? 4 : 8) * 20, 1)); - * player.addPotionEffect(new PotionEffect(Potion.resistance.id, 30 * 20, 1)); - * } - */} ); - registerHandler( new Handler( "pinkSlime", "MineFactoryReloaded.mfrEntityPinkSlime" ) - { - @Override - public int foodAmount() - { - return 6; - } - - @Override - public float saturationAmount() - { - return 0.75F; - } - /* - * @Override public void onEaten(EntityPlayer player, boolean potionEffects) { - * super.onEaten(player, potionEffects); - * player.addPotionEffect(new PotionEffect(Potion.field_76434_w.id, (potionEffects ? 40 : 60) * 20, 4)); - * } - */ - } ); - registerHandler( new Handler( "thaumicSlime", "Thaumcraft.ThaumSlime" ) - { - private final int potionFluxId = -1; - - @Override - public float durationMultiplier() - { - return 1.0F; - } - /* - * @Override public void onEaten(EntityPlayer player, boolean potionEffects) { - * if (potionFluxId == -1) { - * // Look for flux potion effect. - * for (Potion potion : Potion.potionTypes) - * if (potion != null) - * if (potion.getName() == "potion.fluxtaint") { - * potionFluxId = potion.id; break; } - * // If not found, just use wither. - * if (potionFluxId == -1) - * potionFluxId = Potion.wither.id; - * } - * super.onEaten(player, potionEffects); - * player.addPotionEffect(new PotionEffect(potionFluxId, 8 * 20, 0)); - * } - */ - } ); - registerHandler( new Handler( "blueSlime", "TConstruct.EdibleSlime" ) - { - @Override - public float durationMultiplier() - { - return 0.2F; - } - } ); - } - - public static class Handler - { - - public final String name; - public final String entityName; - - // public IIcon icon; - - public Handler( String name, String entityName ) - { - this.name = name; - this.entityName = entityName; - } - - /** Returns the icon location to be used in registerIcons. */ - /* - * public void registerIcon(IIconRegister iconRegister) { - * icon = iconRegister.registerIcon(Constants.modId + ":bucketSlime_" + name); - * } - */ - - /** Returns the size of the slime. */ - public int getSize( EntityLiving slime ) - { - if( slime instanceof EntitySlime ) - return ( (EntitySlime)slime ).getSlimeSize(); - else - return 0; - } - - /** Sets the size of the slime. */ - public void setSize( EntityLiving slime, int size ) - { - final NBTTagCompound compound = new NBTTagCompound(); - slime.writeToNBT( compound ); - compound.setInteger( "Size", size - 1 ); - slime.readFromNBT( compound ); - } - - /** How much food is restored when eating this slime. */ - public int foodAmount() - { - return 4; - } - - /** The satuation amount added when eating this slime. */ - public float saturationAmount() - { - return 0.3F; - } - - /** Duration will get multiplied by this value. */ - public float durationMultiplier() - { - return 0.25F; - } - - /** - * Called when this slime is eaten, allows adding effects to the player - * in addition to the potion effects of the slime itself. - */ - /* - * public void onEaten(EntityPlayer player, boolean potionEffects) { - * player.addPotionEffect(new PotionEffect(Potion.jump.id, (potionEffects ? 6 : 16) * 20, 1)); - * } - */ - - } -} diff --git a/src/main/java/io/github/tehstoneman/betterstorage/common/item/BetterStorageItems.java b/src/main/java/io/github/tehstoneman/betterstorage/common/item/BetterStorageItems.java index 5b55a601..e5997fd2 100644 --- a/src/main/java/io/github/tehstoneman/betterstorage/common/item/BetterStorageItems.java +++ b/src/main/java/io/github/tehstoneman/betterstorage/common/item/BetterStorageItems.java @@ -35,8 +35,9 @@ public final class BetterStorageItems public static ItemCardboardArmor CARDBOARD_LEGGINGS = new ItemCardboardArmor( EntityEquipmentSlot.LEGS ); public static ItemCardboardArmor CARDBOARD_BOOTS = new ItemCardboardArmor( EntityEquipmentSlot.FEET ); + public static ItemBucketSlime SLIME_BUCKET = new ItemBucketSlime(); + // public static ItemDrinkingHelmet drinkingHelmet; - // public static ItemBucketSlime SLIME_BUCKET; // public static ItemPresentBook PRESENT_BOOK; public static boolean anyCardboardItemsEnabled; @@ -78,10 +79,7 @@ public static void registerItemModels() if( BetterStorage.config.cardboardBootsEnabled ) CARDBOARD_BOOTS.registerItemModels(); - /* - * if( BetterStorage.globalConfig.getBoolean( GlobalConfig.slimeBucketEnabled ) ) - * ModelLoader.setCustomModelResourceLocation( SLIME_BUCKET, 0, - * new ModelResourceLocation( SLIME_BUCKET.getRegistryName(), "inventory" ) ); - */ + if( BetterStorage.config.slimeBucketEnabled ) + SLIME_BUCKET.registerItemModels(); } } diff --git a/src/main/java/io/github/tehstoneman/betterstorage/common/item/ItemBucketSlime.java b/src/main/java/io/github/tehstoneman/betterstorage/common/item/ItemBucketSlime.java new file mode 100644 index 00000000..94465a77 --- /dev/null +++ b/src/main/java/io/github/tehstoneman/betterstorage/common/item/ItemBucketSlime.java @@ -0,0 +1,617 @@ +package io.github.tehstoneman.betterstorage.common.item; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import io.github.tehstoneman.betterstorage.BetterStorage; +import io.github.tehstoneman.betterstorage.utils.LanguageUtils; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.EntitySlime; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Items; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.EnumAction; +import net.minecraft.item.Item; +import net.minecraft.item.ItemMonsterPlacer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.IStringSerializable; +import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StringUtils; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.common.util.Constants.NBT; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemBucketSlime extends ItemBetterStorage +{ + private static Map< ResourceLocation, Handler > handlers = new HashMap<>(); + + public ItemBucketSlime() + { + super( "bucket" ); + setContainerItem( Items.BUCKET ); + setHasSubtypes( true ); + setMaxStackSize( 0 ); + setMaxDamage( 0 ); + setHasSubtypes( true ); + } + + @Override + public int getMetadata( int damage ) + { + return damage; + } + + @Override + public void getSubItems( Item itemIn, CreativeTabs tab, NonNullList< ItemStack > subItems ) + { + for( final EnumSlime slime : EnumSlime.values() ) + subItems.add( new ItemStack( itemIn, 1, slime.getMetadata() ) ); + } + + @Override + public String getUnlocalizedName( ItemStack stack ) + { + // final int meta = stack.getMetadata(); + return super.getUnlocalizedName() + "." + EnumSlime.byMetadata( 0 ).getUnlocalizedName(); + } + + @Override + @SideOnly( Side.CLIENT ) + public boolean hasEffect( ItemStack stack ) + { + return stack.isItemEnchanted() || stack.hasTagCompound() && stack.getTagCompound().hasKey( "effects" ); + } + + @Override + @SideOnly( Side.CLIENT ) + public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean advancedTooltips ) + { + final EnumSlime slime = EnumSlime.byMetadata( stack.getMetadata() ); + final ResourceLocation resourceLocation = slime.getResourceLocation(); + final Handler handler = getHandler( resourceLocation ); + String name = null; + if( stack.hasTagCompound() ) + { + final NBTTagCompound compound = stack.getTagCompound(); + if( compound.hasKey( "name" ) ) + name = compound.getString( "name" ); + } + if( name != null || advancedTooltips ) + { + final String localName = name != null + ? "\"" + name + "\"" + ( advancedTooltips ? " (" + BetterStorage.proxy.localize( handler.entityName ) + ")" : "" ) + : BetterStorage.proxy.localize( handler.entityName ); + list.add( BetterStorage.proxy.localize( "tooltip.betterstorage.bucket.slime.contains", localName ) ); + } + + if( stack.hasTagCompound() ) + { + final NBTTagCompound compound = stack.getTagCompound(); + if( compound.hasKey( "effects" ) ) + { + final NBTTagList effectList = compound.getTagList( "effects", NBT.TAG_COMPOUND ); + if( effectList != null && handler != null ) + { + final int max = advancedTooltips || GuiScreen.isShiftKeyDown() ? 6 : 3; + + for( int i = 0; i < Math.min( effectList.tagCount(), max ); i++ ) + { + final PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT( effectList.getCompoundTagAt( i ) ); + final Potion potion = effect.getPotion(); + final int duration = (int)( effect.getDuration() * handler.durationMultiplier() ); + + final StringBuilder str = new StringBuilder().append( potion.isBadEffect() ? TextFormatting.RED : TextFormatting.GRAY ) + .append( BetterStorage.proxy.localize( effect.getEffectName() ) ); + + if( effect.getAmplifier() > 0 ) + str.append( " " ).append( BetterStorage.proxy.localize( "potion.potency." + effect.getAmplifier() ) ); + + str.append( " (" ).append( StringUtils.ticksToElapsedTime( duration ) ).append( ")" ); + + list.add( str.toString() ); + } + + final int more = effectList.tagCount() - max; + + if( more > 0 ) + list.add( TextFormatting.DARK_GRAY.toString() + TextFormatting.ITALIC + LanguageUtils + .translateTooltip( "bucketSlime.more." + ( more == 1 ? "1" : "x" ), "%X%", Integer.toString( more ) ) ); + } + } + } + } + + @Override + public EnumActionResult onItemUse( EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, + float hitZ ) + { + final ItemStack stack = player.getHeldItem( hand ); + // If player is sneaking, eat slime + // instead of placing it in the world. + if( player.isSneaking() ) + return EnumActionResult.FAIL; + + if( worldIn.isRemote ) + return EnumActionResult.PASS; + + final ResourceLocation resourceLocation = getSlimeId( stack ); + + final BlockPos blockpos = pos.offset( facing ); + final Handler handler = getHandler( resourceLocation ); + final double d0 = getYOffset( worldIn, blockpos ); + final Entity entity = ItemMonsterPlacer.spawnCreature( worldIn, handler.resourceLocation, blockpos.getX() + 0.5D, blockpos.getY() + d0, + blockpos.getZ() + 0.5D ); + + if( entity != null && handler != null && entity instanceof EntityLiving ) + { + final EntityLiving slime = (EntityLiving)entity; + + handler.setSize( slime, 1 ); + + if( stack.hasTagCompound() ) + { + final NBTTagCompound compound = stack.getTagCompound(); + if( compound.hasKey( "name" ) ) + entity.setCustomNameTag( compound.getString( "name" ) ); + final NBTTagList effectList = compound.getTagList( "effects", NBT.TAG_COMPOUND ); + if( effectList != null ) + for( int i = 0; i < effectList.tagCount(); i++ ) + slime.addPotionEffect( PotionEffect.readCustomPotionEffectFromNBT( effectList.getCompoundTagAt( i ) ) ); + } + + if( !player.capabilities.isCreativeMode ) + player.setHeldItem( EnumHand.MAIN_HAND, new ItemStack( Items.BUCKET ) ); + } + + return EnumActionResult.SUCCESS; + } + + // Eating slime + + @Override + public EnumAction getItemUseAction( ItemStack stack ) + { + return EnumAction.DRINK; + } + + @Override + public int getMaxItemUseDuration( ItemStack stack ) + { + return 48; + } + + @Override + public ActionResult< ItemStack > onItemRightClick( World worldIn, EntityPlayer playerIn, EnumHand handIn ) + { + if( handIn == EnumHand.MAIN_HAND ) + { + final ItemStack stack = playerIn.getHeldItem( handIn ); + // playerIn.canEat( true ); + playerIn.setActiveHand( handIn ); + return new ActionResult( EnumActionResult.SUCCESS, playerIn.getHeldItem( handIn ) ); + } + + return super.onItemRightClick( worldIn, playerIn, handIn ); + } + + @Override + public ItemStack onItemUseFinish( ItemStack stack, World worldIn, EntityLivingBase entityLiving ) + { + if( entityLiving instanceof EntityPlayer ) + { + final EntityPlayer player = (EntityPlayer)entityLiving; + final Handler handler = getHandler( stack ); + if( handler != null ) + { + player.getFoodStats().addStats( handler.foodAmount(), handler.saturationAmount() ); + if( stack.hasTagCompound() ) + { + final NBTTagCompound compound = stack.getTagCompound(); + if( compound.hasKey( "effects" ) ) + { + final NBTTagList effectList = compound.getTagList( "effects", NBT.TAG_COMPOUND ); + for( int i = 0; i < effectList.tagCount(); i++ ) + { + PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT( effectList.getCompoundTagAt( i ) ); + final int duration = (int)( effect.getDuration() * handler.durationMultiplier() ); + effect = new PotionEffect( effect.getPotion(), duration, effect.getAmplifier() ); + player.addPotionEffect( effect ); + } + } + } + handler.onEaten( player, false ); + } + } + return new ItemStack( Items.BUCKET ); + } + + // Helper functions + + /** + * Called when a player right clicks an entity with an empty bucket. + * If the entity clicked is a small slime, attempts to pick it up and + * sets the held item to a Slime in a Bucket containing that slime. + */ + public static void pickUpSlime( EntityPlayer player, EntityLiving slime ) + { + final Handler handler = getHandler( slime ); + if( slime.isDead || handler == null || handler.getSize( slime ) != 1 ) + return; + + final ItemStack stack = new ItemStack( BetterStorageItems.SLIME_BUCKET, 1, EnumSlime.byName( handler.name ).getMetadata() ); + + final String entityId = EntityList.getEntityString( slime ); + if( slime.hasCustomName() ) + { + NBTTagCompound compound = new NBTTagCompound(); + if( stack.hasTagCompound() ) + compound = stack.getTagCompound(); + compound.setString( "name", slime.getCustomNameTag() ); + stack.setTagCompound( compound ); + } + + final Collection< PotionEffect > effects = slime.getActivePotionEffects(); + if( !effects.isEmpty() ) + { + NBTTagCompound compound = new NBTTagCompound(); + if( stack.hasTagCompound() ) + compound = stack.getTagCompound(); + final NBTTagList effectList = new NBTTagList(); + for( final PotionEffect effect : effects ) + effectList.appendTag( effect.writeCustomPotionEffectToNBT( new NBTTagCompound() ) ); + compound.setTag( "effects", effectList ); + stack.setTagCompound( compound ); + } + if( player.getHeldItemMainhand().getCount() <= 1 ) + player.setHeldItem( EnumHand.MAIN_HAND, stack ); + + else + { + player.getHeldItemMainhand().shrink( 1 ); + if( !player.inventory.addItemStackToInventory( stack ) ) + player.dropItem( stack, true, false ); + + else + ( (EntityPlayerMP)player ).inventoryContainer.detectAndSendChanges(); + } + + slime.playSound( SoundEvents.ENTITY_SLIME_JUMP, 1.2F, 0.8F ); + slime.isDead = true; + } + + /** Returns the slime ID from a slime bucket. */ + public static ResourceLocation getSlimeId( ItemStack stack ) + { + return EnumSlime.byMetadata( stack.getMetadata() ).getResourceLocation(); + } + + /** Registers a slime handler. */ + public static void registerHandler( Handler handler ) + { + handlers.put( handler.resourceLocation, handler ); + } + + /** Returns the handler for an entity id, null if none. */ + public static Handler getHandler( ResourceLocation resourceLocation ) + { + return handlers.get( resourceLocation ); + } + + /** Returns the handler for an entity, null if none. */ + public static Handler getHandler( EntityLiving slime ) + { + return getHandler( EntityList.getKey( slime ) ); + } + + /** Returns the handler for slime bucket, null if none. */ + public static Handler getHandler( ItemStack stack ) + { + return getHandler( getSlimeId( stack ) ); + } + + @Override + @SideOnly( Side.CLIENT ) + public void registerItemModels() + { + for( final EnumSlime slime : EnumSlime.values() ) + ModelLoader.setCustomModelResourceLocation( this, slime.getMetadata(), + new ModelResourceLocation( getRegistryName() + "_" + slime.getUnlocalizedName(), "inventory" ) ); + } + + // Copied from ItemMonsterPlacer (Spawn eggs) + + protected double getYOffset( World p_190909_1_, BlockPos p_190909_2_ ) + { + final AxisAlignedBB axisalignedbb = new AxisAlignedBB( p_190909_2_ ).addCoord( 0.0D, -1.0D, 0.0D ); + final List< AxisAlignedBB > list = p_190909_1_.getCollisionBoxes( (Entity)null, axisalignedbb ); + + if( list.isEmpty() ) + return 0.0D; + else + { + double d0 = axisalignedbb.minY; + + for( final AxisAlignedBB axisalignedbb1 : list ) + d0 = Math.max( axisalignedbb1.maxY, d0 ); + + return d0 - p_190909_2_.getY(); + } + } + + // Slime handlers + + static + { + registerHandler( new Handler( EnumSlime.GREEN_SLIME.name, new ResourceLocation( EnumSlime.GREEN_SLIME.getUnlocalizedName() ) ) + { + @Override + public int foodAmount() + { + return 3; + } + + @Override + public float saturationAmount() + { + return 0.2F; + } + } ); + registerHandler( new Handler( EnumSlime.MAGMA_CUBE.name, new ResourceLocation( EnumSlime.MAGMA_CUBE.getUnlocalizedName() ) ) + { + @Override + public float durationMultiplier() + { + return 0.4F; + } + + @Override + public void onEaten( EntityPlayer player, boolean potionEffects ) + { + player.setFire( 2 ); + player.addPotionEffect( new PotionEffect( Potion.getPotionFromResourceLocation( "jump_boost" ), ( potionEffects ? 10 : 20 ) * 20, + potionEffects ? 2 : 3 ) ); + player.addPotionEffect( new PotionEffect( Potion.getPotionFromResourceLocation( "strength" ), ( potionEffects ? 24 : 32 ) * 20, 0 ) ); + } + } ); + /* + * registerHandler( new Handler( EnumSlime.MAZE_SLIME.name, "TwilightForest.Maze Slime" ) + * { + * @Override + * public void onEaten(EntityPlayer player, boolean potionEffects) { + * player.attackEntityFrom(DamageSource.magic, 3.0F); + * player.addPotionEffect(new PotionEffect(Potion.jump.id, (potionEffects ? 4 : 8) * 20, 0)); + * player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, (potionEffects ? 4 : 8) * 20, 1)); + * player.addPotionEffect(new PotionEffect(Potion.resistance.id, 30 * 20, 1)); + * } + * } ); + */ + /* + * registerHandler( new Handler( EnumSlime.PINK_SLIME.name, "MineFactoryReloaded.mfrEntityPinkSlime" ) + * { + * @Override + * public int foodAmount() + * { + * return 6; + * } + * + * @Override + * public float saturationAmount() + * { + * return 0.75F; + * } + * + * @Override + * public void onEaten(EntityPlayer player, boolean potionEffects) { + * super.onEaten(player, potionEffects); + * player.addPotionEffect(new PotionEffect(Potion.field_76434_w.id, (potionEffects ? 40 : 60) * 20, 4)); + * } + * + * } ); + */ + /* + * registerHandler( new Handler( EnumSlime.THAUM_SLIME.name, "Thaumcraft.ThaumSlime" ) + * { + * private final int potionFluxId = -1; + * + * @Override + * public float durationMultiplier() + * { + * return 1.0F; + * } + * + * @Override + * public void onEaten(EntityPlayer player, boolean potionEffects) { + * if (potionFluxId == -1) { + * // Look for flux potion effect. + * for (Potion potion : Potion.potionTypes) + * if (potion != null) + * if (potion.getName() == "potion.fluxtaint") { + * potionFluxId = potion.id; break; } + * // If not found, just use wither. + * if (potionFluxId == -1) + * potionFluxId = Potion.wither.id; + * } + * super.onEaten(player, potionEffects); + * player.addPotionEffect(new PotionEffect(potionFluxId, 8 * 20, 0)); + * } + * + * } ); + */ + /* + * registerHandler( new Handler( EnumSlime.BLUE_SLIME.name, "TConstruct.EdibleSlime" ) + * { + * + * @Override + * public float durationMultiplier() + * { + * return 0.2F; + * } + * } ); + */ + } + + public static class Handler + { + + public final String name; + public final String entityName; + public final ResourceLocation resourceLocation; + + public Handler( String name, String entityName ) + { + this.name = name; + this.entityName = entityName; + resourceLocation = null; + } + + public Handler( String name, ResourceLocation resource ) + { + this.name = name; + entityName = EntityList.getTranslationName( resource ); + resourceLocation = resource; + } + + /** Returns the size of the slime. */ + public int getSize( EntityLiving slime ) + { + if( slime instanceof EntitySlime ) + return ( (EntitySlime)slime ).getSlimeSize(); + else + return 0; + } + + /** Sets the size of the slime. */ + public void setSize( EntityLiving slime, int size ) + { + final NBTTagCompound compound = new NBTTagCompound(); + slime.writeToNBT( compound ); + compound.setInteger( "Size", size - 1 ); + slime.readFromNBT( compound ); + } + + /** How much food is restored when eating this slime. */ + public int foodAmount() + { + return 4; + } + + /** The satuation amount added when eating this slime. */ + public float saturationAmount() + { + return 0.3F; + } + + /** Duration will get multiplied by this value. */ + public float durationMultiplier() + { + return 0.25F; + } + + /** + * Called when this slime is eaten, allows adding effects to the player + * in addition to the potion effects of the slime itself. + */ + public void onEaten( EntityPlayer player, boolean potionEffects ) + { + player.addPotionEffect( new PotionEffect( Potion.getPotionFromResourceLocation( "jump_boost" ), ( potionEffects ? 6 : 16 ) * 20, 1 ) ); + } + + } + + public enum EnumSlime implements IStringSerializable + { + //@formatter:off + GREEN_SLIME ( 0, "Slime", new ResourceLocation("slime") ), + MAGMA_CUBE ( 1, "LavaSlime", new ResourceLocation("magma_cube") ); + // MAZE_SLIME ( 2, "maze_slime" ), + // PINK_SLIME ( 3, "pink_slime" ), + // THAUM_SLIME ( 4, "thaumic_slime" ), + // BLUE_SLIME ( 5, "blue_slime" ); + //@formatter:on + + private final int meta; + private final String name; + private final ResourceLocation resourceLocation; + + private static EnumSlime[] META_LOOKUP = new EnumSlime[values().length]; + private static Map< String, EnumSlime > NAME_LOOKUP = new HashMap<>();; + + static + { + for( final EnumSlime slime : values() ) + { + META_LOOKUP[slime.getMetadata()] = slime; + NAME_LOOKUP.put( slime.name, slime ); + } + } + + private EnumSlime( int meta, String name, ResourceLocation resourceLocation ) + { + this.meta = meta; + this.name = name; + this.resourceLocation = resourceLocation; + } + + public static EnumSlime byMetadata( int meta ) + { + if( meta < 0 || meta >= META_LOOKUP.length ) + meta = 0; + return META_LOOKUP[meta]; + } + + public static EnumSlime byName( String name ) + { + return NAME_LOOKUP.get( name ); + } + + @Override + public String toString() + { + return name; + } + + @Override + public String getName() + { + return name; + } + + public ResourceLocation getResourceLocation() + { + return resourceLocation; + } + + public String getUnlocalizedName() + { + return resourceLocation.getResourcePath(); + } + + public int getMetadata() + { + return meta; + } + }; +} diff --git a/src/main/java/io/github/tehstoneman/betterstorage/config/BetterStorageConfig.java b/src/main/java/io/github/tehstoneman/betterstorage/config/BetterStorageConfig.java index 8ea0d75e..ea9c6138 100644 --- a/src/main/java/io/github/tehstoneman/betterstorage/config/BetterStorageConfig.java +++ b/src/main/java/io/github/tehstoneman/betterstorage/config/BetterStorageConfig.java @@ -10,8 +10,8 @@ public class BetterStorageConfig { private final Configuration config; - public static final String CATEGORY_BLOCKS = "blocks"; - public static final String CATEGORY_ITEMS = "items"; + public static final String CATEGORY_BLOCKS = "blocks"; + public static final String CATEGORY_ITEMS = "items"; public static final String CATEGORY_ENCHANTMENTS = "enchantments"; // Block settings @@ -29,6 +29,7 @@ public class BetterStorageConfig public boolean keyringEnabled; public boolean lockEnabled; public boolean cardboardSheetEnabled; + public boolean slimeBucketEnabled; // Cardboard items public boolean cardboardHelmetEnabled; @@ -42,13 +43,13 @@ public class BetterStorageConfig public boolean cardboardHoeEnabled; // Enchantments - public boolean enchUnlockingEnabled;// = "enchantment.unlocking"; - public boolean enchLockpickingEnabled;// = "enchantment.lockpicking"; - public boolean enchMorphingEnabled;// = "enchantment.morphing"; - public boolean enchPersistanceEnabled;// = "enchantment.persistance"; - public boolean enchSecurityEnabled;// = "enchantment.security"; - public boolean enchShockEnabled;// = "enchantment.shock"; - public boolean enchTriggerEnabled;// = "enchantment.trigger"; + public boolean enchUnlockingEnabled; + public boolean enchLockpickingEnabled; + public boolean enchMorphingEnabled; + public boolean enchPersistanceEnabled; + public boolean enchSecurityEnabled; + public boolean enchShockEnabled; + public boolean enchTriggerEnabled; // General settings public int reinforcedColumns; @@ -58,7 +59,7 @@ public class BetterStorageConfig public int cardboardBoxUses; public boolean cardboardBoxShowContents; - public boolean lockBreakable; + public boolean lockBreakable; public boolean enableHelpTooltips; public boolean enableWarningMessages; @@ -163,6 +164,8 @@ public void syncConfig( boolean loadConfigFromFile, boolean readFieldsFromConfig .setLanguageKey( "item.betterstorage.cardboard_axe.name" ).setRequiresMcRestart( true ); final Property propCardboardHoeEnabled = config.get( CATEGORY_ITEMS, "cardboardHoeEnabled", true ) .setLanguageKey( "item.betterstorage.cardboard_hoe.name" ).setRequiresMcRestart( true ); + final Property propSlimeBucketEnabled = config.get( CATEGORY_ITEMS, "slimeBucketEnabled", true ) + .setLanguageKey( "item.betterstorage.bucket.slime.name" ).setRequiresMcRestart( true ); // Enchantment settings final Property propEnchUnlockingEnabled = config.get( CATEGORY_ENCHANTMENTS, "enchUnlockingEnabled", true ) @@ -245,7 +248,8 @@ public void syncConfig( boolean loadConfigFromFile, boolean readFieldsFromConfig "cardboardPickaxeEnabled", "cardboardShovelEnabled", "cardboardAxeEnabled", - "cardboardHoeEnabled" } ) ); + "cardboardHoeEnabled", + "slimeBucketEnabled" } ) ); config.setCategoryPropertyOrder( CATEGORY_ENCHANTMENTS, Arrays.asList( new String[] { "enchUnlockingEnabled", "enchLockpickingEnabled", @@ -266,7 +270,7 @@ public void syncConfig( boolean loadConfigFromFile, boolean readFieldsFromConfig enchSecurityEnabled = propEnchSecurityEnabled.getBoolean(); enchShockEnabled = propEnchShockEnabled.getBoolean(); enchTriggerEnabled = propEnchTriggerEnabled.getBoolean(); - + crateEnabled = propCrateEnabled.getBoolean(); reinforcedChestEnabled = propReinforcedChestEnabled.getBoolean(); lockerEnabled = propLockerEnabled.getBoolean(); @@ -284,6 +288,7 @@ public void syncConfig( boolean loadConfigFromFile, boolean readFieldsFromConfig cardboardShovelEnabled = propCardboardShovelEnabled.getBoolean(); cardboardAxeEnabled = propCardboardAxeEnabled.getBoolean(); cardboardHoeEnabled = propCardboardHoeEnabled.getBoolean(); + slimeBucketEnabled = propSlimeBucketEnabled.getBoolean(); keyEnabled = propKeyEnabled.getBoolean(); masterKeyEnabled = propMasterKeyEnabled.getBoolean(); @@ -296,7 +301,7 @@ public void syncConfig( boolean loadConfigFromFile, boolean readFieldsFromConfig cardboardBoxRows = propCardboardBoxRows.getInt(); cardboardBoxUses = propCardboardBoxUses.getInt(); cardboardBoxShowContents = propCardboardBoxShowContents.getBoolean(); - + lockBreakable = propLockBreakable.getBoolean(); enableHelpTooltips = propEnableHelpTooltips.getBoolean(); @@ -311,7 +316,7 @@ public void syncConfig( boolean loadConfigFromFile, boolean readFieldsFromConfig propEnchSecurityEnabled.set( enchSecurityEnabled ); propEnchShockEnabled.set( enchShockEnabled ); propEnchTriggerEnabled.set( enchTriggerEnabled ); - + propCrateEnabled.set( crateEnabled ); propReinforcedChestEnabled.set( reinforcedChestEnabled ); propLockerEnabled.set( lockerEnabled ); @@ -325,13 +330,14 @@ public void syncConfig( boolean loadConfigFromFile, boolean readFieldsFromConfig propKeyringEnabled.set( keyringEnabled ); propLockEnabled.set( lockEnabled ); propCardboardSheetEnabled.set( cardboardSheetEnabled ); + propSlimeBucketEnabled.set( slimeBucketEnabled ); propReinforcedColumns.set( reinforcedColumns ); propReinforcedChestEnabled.set( enableCrateInventoryInterface ); propCardboardBoxRows.set( cardboardBoxRows ); propCardboardBoxUses.set( cardboardBoxUses ); propCardboardBoxShowContents.set( cardboardBoxShowContents ); - + propLockBreakable.set( lockBreakable ); propEnableHelpTooltips.set( enableHelpTooltips ); propEnableWarningMessages.set( enableWarningMessages ); diff --git a/src/main/java/io/github/tehstoneman/betterstorage/event/BetterStorageEventHandler.java b/src/main/java/io/github/tehstoneman/betterstorage/event/BetterStorageEventHandler.java index 392574e9..338808f3 100644 --- a/src/main/java/io/github/tehstoneman/betterstorage/event/BetterStorageEventHandler.java +++ b/src/main/java/io/github/tehstoneman/betterstorage/event/BetterStorageEventHandler.java @@ -1,28 +1,37 @@ package io.github.tehstoneman.betterstorage.event; +import java.util.logging.Logger; + import io.github.tehstoneman.betterstorage.BetterStorage; import io.github.tehstoneman.betterstorage.ModInfo; import io.github.tehstoneman.betterstorage.api.ICardboardItem; import io.github.tehstoneman.betterstorage.api.IDyeableItem; import io.github.tehstoneman.betterstorage.common.item.BetterStorageItems; +import io.github.tehstoneman.betterstorage.common.item.ItemBucketSlime; import io.github.tehstoneman.betterstorage.common.item.cardboard.ItemCardboardSheet; import net.minecraft.block.Block; import net.minecraft.block.BlockCauldron; import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract; import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent; import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class BetterStorageEventHandler { + private boolean preventSlimeBucketUse; + @SubscribeEvent public void onConfigChangeEvent( OnConfigChangedEvent event ) { @@ -91,16 +100,42 @@ public void onPlayerInteract( PlayerInteractEvent event ) if( !world.isRemote && BetterStorage.config.lockableDoorEnabled && hand == EnumHand.MAIN_HAND && block == Blocks.IRON_DOOR && holding.getItem() == BetterStorageItems.LOCK ) player.inventory.setInventorySlotContents( player.inventory.currentItem, ItemStack.EMPTY ); - // } // Prevent eating of slime buckets after capturing them. + if( preventSlimeBucketUse ) + { + event.setCanceled( true ); + preventSlimeBucketUse = false; + } + } + + @SubscribeEvent + public void onEntityInteract( EntityInteract event ) + { + + if( event.getEntity().world.isRemote || event.isCanceled() ) + return; + + final EntityPlayer player = event.getEntityPlayer(); + final Entity target = event.getTarget(); + final ItemStack holding = player.getHeldItemMainhand(); + /* - * if( preventSlimeBucketUse ) + * if( target.getClass() == EntityChicken.class && holding != null && holding.getItem() == Items.NAME_TAG ) * { - * event.setCanceled( true ); - * preventSlimeBucketUse = false; + * + * final EntityChicken chicken = (EntityChicken)target; + * if( !chicken.isDead && !chicken.isChild() && "Cluckington".equals( holding.getDisplayName() ) ) + * EntityCluckington.spawn( chicken ); + * * } */ + if( BetterStorage.config.slimeBucketEnabled && target instanceof EntityLiving && holding != null && holding.getItem() == Items.BUCKET ) + { + ItemBucketSlime.pickUpSlime( player, (EntityLiving)target ); + if( player.getHeldItemMainhand().getItem() instanceof ItemBucketSlime ) + preventSlimeBucketUse = true; + } } } diff --git a/src/main/java/io/github/tehstoneman/betterstorage/proxy/CommonProxy.java b/src/main/java/io/github/tehstoneman/betterstorage/proxy/CommonProxy.java index d1ae9189..44b82a26 100644 --- a/src/main/java/io/github/tehstoneman/betterstorage/proxy/CommonProxy.java +++ b/src/main/java/io/github/tehstoneman/betterstorage/proxy/CommonProxy.java @@ -97,7 +97,10 @@ public void preInit() BetterStorageItems.CARDBOARD_LEGGINGS.register( "cardboard_leggings" ); if( BetterStorage.config.cardboardBootsEnabled ) BetterStorageItems.CARDBOARD_BOOTS.register( "cardboard_boots" ); - } + + if( BetterStorage.config.slimeBucketEnabled ) + BetterStorageItems.SLIME_BUCKET.register(); +} public void initialize() { @@ -126,36 +129,6 @@ public void postInit() * } */ - /* - * @SubscribeEvent - * public void onEntityInteract(EntityInteractEvent event) { - * - * if (event.entity.worldObj.isRemote || event.isCanceled()) return; - * - * EntityPlayer player = event.entityPlayer; - * Entity target = event.target; - * ItemStack holding = player.getCurrentEquippedItem(); - * - * if ((target.getClass() == EntityChicken.class) && - * (holding != null) && (holding.getItem() == Items.name_tag)) { - * - * EntityChicken chicken = (EntityChicken)target; - * if (!chicken.isDead && !chicken.isChild() && - * "Cluckington".equals(holding.getDisplayName())) - * EntityCluckington.spawn(chicken); - * - * } - * - * if ((BetterStorageItems.slimeBucket != null) && (target instanceof EntityLiving) && - * (holding != null) && (holding.getItem() == Items.bucket)) { - * ItemBucketSlime.pickUpSlime(player, (EntityLiving)target); - * if (player.getCurrentEquippedItem().getItem() instanceof ItemBucketSlime) - * preventSlimeBucketUse = true; - * } - * - * } - */ - public String localize( String unlocalized, Object... args ) { return I18n.translateToLocalFormatted( unlocalized, args ); diff --git a/src/main/resources/assets/betterstorage/lang/en_us.lang b/src/main/resources/assets/betterstorage/lang/en_us.lang index 66ea9b59..fc91ebd2 100644 --- a/src/main/resources/assets/betterstorage/lang/en_us.lang +++ b/src/main/resources/assets/betterstorage/lang/en_us.lang @@ -58,6 +58,8 @@ tile.betterstorage.reinforced_locker.name.full=Reinforced %s Locker tile.betterstorage.reinforced_locker.name.tooltip=Enable or disable reinforced lockers.\n(No effect if lockers are disabled) # Items +item.betterstorage.bucket.slime.name=Slime in a Bucket +item.betterstorage.bucket.slime.name.tooltip=Enable or disable slime buckets. item.betterstorage.cardboard_axe.name=Cardboard Axe item.betterstorage.cardboard_axe.name.tooltip=Enable or disable cardboard axe. item.betterstorage.cardboard_boots.name=Cardboard Boots @@ -88,6 +90,7 @@ item.betterstorage.master_key.name=Master Key item.betterstorage.master_key.name.tooltip=Enable or disable master key.\n(Requires keys enabled) # Tooltips +tooltip.betterstorage.bucket.slime.contains=Contains: %s tooltip.betterstorage.cardboardBox.containsItems=Contains items. tooltip.betterstorage.cardboardBox.plusMore=... Plus %s more. tooltip.betterstorage.cardboardBox.useHint.reusable=Reusable portable storage. diff --git a/src/main/resources/assets/betterstorage/models/item/bucket_blue_slime.json b/src/main/resources/assets/betterstorage/models/item/bucket_blue_slime.json new file mode 100644 index 00000000..445d1259 --- /dev/null +++ b/src/main/resources/assets/betterstorage/models/item/bucket_blue_slime.json @@ -0,0 +1,8 @@ +{ + "parent": "item/generated", + "textures": + { + "layer0": "betterstorage:items/bucket_empty", + "layer1": "betterstorage:items/bucket_blue_slime" + } +} diff --git a/src/main/resources/assets/betterstorage/models/item/bucket_magma_cube.json b/src/main/resources/assets/betterstorage/models/item/bucket_magma_cube.json new file mode 100644 index 00000000..c87b6024 --- /dev/null +++ b/src/main/resources/assets/betterstorage/models/item/bucket_magma_cube.json @@ -0,0 +1,8 @@ +{ + "parent": "item/generated", + "textures": + { + "layer0": "betterstorage:items/bucket_empty", + "layer1": "betterstorage:items/bucket_magma_cube" + } +} diff --git a/src/main/resources/assets/betterstorage/models/item/bucket_maze_slime.json b/src/main/resources/assets/betterstorage/models/item/bucket_maze_slime.json new file mode 100644 index 00000000..c57e7baa --- /dev/null +++ b/src/main/resources/assets/betterstorage/models/item/bucket_maze_slime.json @@ -0,0 +1,8 @@ +{ + "parent": "item/generated", + "textures": + { + "layer0": "betterstorage:items/bucket_empty", + "layer1": "betterstorage:items/bucket_maze_slime" + } +} diff --git a/src/main/resources/assets/betterstorage/models/item/bucket_pink_slime.json b/src/main/resources/assets/betterstorage/models/item/bucket_pink_slime.json new file mode 100644 index 00000000..5a919c71 --- /dev/null +++ b/src/main/resources/assets/betterstorage/models/item/bucket_pink_slime.json @@ -0,0 +1,8 @@ +{ + "parent": "item/generated", + "textures": + { + "layer0": "betterstorage:items/bucket_empty", + "layer1": "betterstorage:items/bucket_pink_slime" + } +} diff --git a/src/main/resources/assets/betterstorage/models/item/bucket_slime.json b/src/main/resources/assets/betterstorage/models/item/bucket_slime.json new file mode 100644 index 00000000..a214b11d --- /dev/null +++ b/src/main/resources/assets/betterstorage/models/item/bucket_slime.json @@ -0,0 +1,8 @@ +{ + "parent": "item/generated", + "textures": + { + "layer0": "betterstorage:items/bucket_empty", + "layer1": "betterstorage:items/bucket_slime" + } +} diff --git a/src/main/resources/assets/betterstorage/models/item/bucket_thaumic_slime.json b/src/main/resources/assets/betterstorage/models/item/bucket_thaumic_slime.json new file mode 100644 index 00000000..d3169f3f --- /dev/null +++ b/src/main/resources/assets/betterstorage/models/item/bucket_thaumic_slime.json @@ -0,0 +1,8 @@ +{ + "parent": "item/generated", + "textures": + { + "layer0": "betterstorage:items/bucket_empty", + "layer1": "betterstorage:items/bucket_thaumic_slime" + } +} diff --git a/src/main/resources/assets/betterstorage/models/item/slime_bucket.json b/src/main/resources/assets/betterstorage/models/item/slime_bucket.json deleted file mode 100644 index ad7cb3e8..00000000 --- a/src/main/resources/assets/betterstorage/models/item/slime_bucket.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "parent": "item/generated", - "textures": - { - "layer0": "betterstorage:items/bucketSlime_empty", - "layer1": "betterstorage:items/bucketSlime_slime" - } -} diff --git a/src/main/resources/assets/betterstorage/textures/items/bucketSlime_blueSlime.png b/src/main/resources/assets/betterstorage/textures/items/bucket_blue_slime.png similarity index 100% rename from src/main/resources/assets/betterstorage/textures/items/bucketSlime_blueSlime.png rename to src/main/resources/assets/betterstorage/textures/items/bucket_blue_slime.png diff --git a/src/main/resources/assets/betterstorage/textures/items/bucketSlime_empty.png b/src/main/resources/assets/betterstorage/textures/items/bucket_empty.png similarity index 100% rename from src/main/resources/assets/betterstorage/textures/items/bucketSlime_empty.png rename to src/main/resources/assets/betterstorage/textures/items/bucket_empty.png diff --git a/src/main/resources/assets/betterstorage/textures/items/bucketSlime_magmaCube.png b/src/main/resources/assets/betterstorage/textures/items/bucket_magma_cube.png similarity index 100% rename from src/main/resources/assets/betterstorage/textures/items/bucketSlime_magmaCube.png rename to src/main/resources/assets/betterstorage/textures/items/bucket_magma_cube.png diff --git a/src/main/resources/assets/betterstorage/textures/items/bucketSlime_mazeSlime.png b/src/main/resources/assets/betterstorage/textures/items/bucket_maze_slime.png similarity index 100% rename from src/main/resources/assets/betterstorage/textures/items/bucketSlime_mazeSlime.png rename to src/main/resources/assets/betterstorage/textures/items/bucket_maze_slime.png diff --git a/src/main/resources/assets/betterstorage/textures/items/bucketSlime_pinkSlime.png b/src/main/resources/assets/betterstorage/textures/items/bucket_pink_slime.png similarity index 100% rename from src/main/resources/assets/betterstorage/textures/items/bucketSlime_pinkSlime.png rename to src/main/resources/assets/betterstorage/textures/items/bucket_pink_slime.png diff --git a/src/main/resources/assets/betterstorage/textures/items/bucketSlime_slime.png b/src/main/resources/assets/betterstorage/textures/items/bucket_slime.png similarity index 100% rename from src/main/resources/assets/betterstorage/textures/items/bucketSlime_slime.png rename to src/main/resources/assets/betterstorage/textures/items/bucket_slime.png diff --git a/src/main/resources/assets/betterstorage/textures/items/bucketSlime_thaumicSlime.png b/src/main/resources/assets/betterstorage/textures/items/bucket_thaumic_slime.png similarity index 100% rename from src/main/resources/assets/betterstorage/textures/items/bucketSlime_thaumicSlime.png rename to src/main/resources/assets/betterstorage/textures/items/bucket_thaumic_slime.png