Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.basset.slimerancher.items;
- import java.util.List;
- import com.basset.slimerancher.SlimeRancher;
- import com.basset.slimerancher.entities.VacpackShotItem;
- import com.basset.slimerancher.gui.VacpackOverlay;
- import com.basset.slimerancher.inventories.VacpackInventory;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.renderer.block.model.ModelResourceLocation;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Items;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.ItemSword;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.util.ActionResult;
- import net.minecraft.util.EnumActionResult;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import net.minecraft.world.WorldServer;
- import net.minecraftforge.client.model.ModelLoader;
- import net.minecraftforge.fluids.FluidStack;
- import net.minecraftforge.fluids.capability.IFluidHandler;
- import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
- import net.minecraftforge.fml.common.gameevent.TickEvent;
- import net.minecraftforge.items.IItemHandler;
- import net.minecraftforge.items.ItemStackHandler;
- public class ItemVacpack extends SlimeRancherItem {
- public static int range = 5;
- public static double speed = 0.02;
- private VacpackInventory inventory;
- private boolean suck = false;
- public ItemVacpack() {
- super("vacpack", CreativeTabs.TOOLS, 1);
- }
- @Override
- public void onCreated(ItemStack stack, World world, EntityPlayer player) {
- // initialize a new inventory for the itemstack's item
- if (((ItemVacpack) stack.getItem()).getInventory() == null) {
- ((ItemVacpack) stack.getItem()).setInventory(new VacpackInventory(stack));
- }
- }
- public VacpackInventory getInventory() {
- return this.inventory;
- }
- public boolean getSuck() {
- return this.suck;
- }
- public void toggleSuck() {
- this.suck = ! this.suck;
- }
- private void setInventory(VacpackInventory inv) {
- this.inventory = inv;
- }
- @Override
- public int getMaxItemUseDuration(ItemStack stack) {
- return 1; // return any value greater than zero
- }
- /**
- * Called when the equipped item is right clicked.
- */
- @Override
- public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand handIn) {
- // we can't use `this` because its inventory is not updated
- // we have to get the specific inventory of the rightclicked Vacpack
- ItemStack stackThis = player.getHeldItemMainhand(); // rightclicked stack
- VacpackInventory invThis = new VacpackInventory(stackThis); // REAL inventory
- // we don't want to shoot if the player is opening the vacpack's inventory
- if (player.isSneaking()) {
- if (!world.isRemote) {
- player.openGui(SlimeRancher.instance, SlimeRancher.GUI_ITEM_INV, world, 0, 0, 0);
- }
- } else {
- // consumeItemInventory returns null if there's no itemstack in the selected slot
- ItemStack item = invThis.consumeInventoryItem();
- // if item is null, the EntityItem will not be created
- // same if the item.getItem() is null
- if (item != null) {
- //world.playSoundAtEntity(player, SlimeRancher.MODID + ":vacpack_shoot", 0.5F, 1.0F);
- SlimeRancher.debug("shooting " + item.getItem().getUnlocalizedName() + ", count " + item.getCount());
- if (!world.isRemote) {
- world.spawnEntity(new VacpackShotItem(world, player, item));
- }
- } else {
- SlimeRancher.debug("cannot shoot");
- //world.playSoundAtEntity(player, SlimeRancher.MODID + ":vacpack_empty", 0.5F, 1.0F);
- }
- }
- return new ActionResult<ItemStack>(EnumActionResult.PASS, player.getHeldItem(handIn));
- }
- @Override
- public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {
- }
- @Override
- public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) {
- ((ItemVacpack) stack.getItem()).toggleSuck();
- return true; // dont do anything else when we swing the item
- }
- public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
- return true; // dont attack the entity when we left click it
- }
- public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
- return true; // dont break the block we start to left click
- }
- public boolean canDestroyBlockInCreative(World world, BlockPos pos, ItemStack stack, EntityPlayer player) {
- return false;
- }
- /**
- * Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and
- * update it's contents.
- *
- * method content stolen from Just-a-Magnet-Mod
- */
- public void onUpdate(ItemStack stack, World worldIn, Entity player, int itemSlot, boolean isSelected) {
- // Grab a list of the items around the player
- if (! isSelected || ! ((ItemVacpack) stack.getItem()).getSuck()) { return; }
- List<EntityItem> floatingItems = worldIn.getEntitiesWithinAABB(
- EntityItem.class,
- new AxisAlignedBB(
- player.posX - range,
- player.posY - range,
- player.posZ - range,
- player.posX + range,
- player.posY + range,
- player.posZ + range )
- );
- if( floatingItems.isEmpty() ) { return; }
- for( EntityItem item : floatingItems ) {
- item.addVelocity(
- (player.posX - item.posX)*speed,
- ((player.posY + 2)- item.posY)*speed,
- (player.posZ - item.posZ)*speed );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement