Merge pull request #1316 from GirafiStudios/blue_fire
Fixed blue fire jar placing, Closes #1304
This commit is contained in:
commit
b3b5a635b5
|
@ -88,6 +88,8 @@ import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ModBlocks
|
public class ModBlocks
|
||||||
{
|
{
|
||||||
// TODO: use getDrops() in classes where the drops are very specific, instead of implementing all 3 of quantityDropped() getItemDropped() and damageDropped()
|
// TODO: use getDrops() in classes where the drops are very specific, instead of implementing all 3 of quantityDropped() getItemDropped() and damageDropped()
|
||||||
|
@ -129,8 +131,7 @@ public class ModBlocks
|
||||||
hive = registerBlock( new BlockBOPHive(), "hive" );
|
hive = registerBlock( new BlockBOPHive(), "hive" );
|
||||||
honey_block = registerBlock( new BlockBOPHoney(), "honey_block" );
|
honey_block = registerBlock( new BlockBOPHoney(), "honey_block" );
|
||||||
|
|
||||||
blue_fire = registerBlock( new BlockBOPBlueFire(), "blue_fire" );
|
blue_fire = registerBlock( new BlockBOPBlueFire(), "blue_fire", null);
|
||||||
blue_fire.setCreativeTab(null);
|
|
||||||
|
|
||||||
//Material Blocks
|
//Material Blocks
|
||||||
bamboo_thatching = registerBlock( (new BlockBOPGeneric(Material.WOOD, SoundType.WOOD)).setHardness(2.0F), "bamboo_thatching"); bamboo_thatching.setHarvestLevel("axe", 0);
|
bamboo_thatching = registerBlock( (new BlockBOPGeneric(Material.WOOD, SoundType.WOOD)).setHardness(2.0F), "bamboo_thatching"); bamboo_thatching.setHarvestLevel("axe", 0);
|
||||||
|
@ -353,11 +354,14 @@ public class ModBlocks
|
||||||
return registerBlock(block, blockName, tab, true);
|
return registerBlock(block, blockName, tab, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Block registerBlock(Block block, String blockName, CreativeTabs tab, boolean registerItemModels)
|
public static Block registerBlock(Block block, String blockName, @Nullable CreativeTabs tab, boolean registerItemModels)
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull(block, "Cannot register a null block");
|
Preconditions.checkNotNull(block, "Cannot register a null block");
|
||||||
block.setUnlocalizedName(blockName);
|
block.setUnlocalizedName(blockName);
|
||||||
|
if (tab != null)
|
||||||
|
{
|
||||||
block.setCreativeTab(tab);
|
block.setCreativeTab(tab);
|
||||||
|
}
|
||||||
|
|
||||||
if (block instanceof IBOPBlock)
|
if (block instanceof IBOPBlock)
|
||||||
{
|
{
|
||||||
|
|
|
@ -76,6 +76,8 @@ import net.minecraft.potion.PotionEffect;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ModItems
|
public class ModItems
|
||||||
{
|
{
|
||||||
public static void init()
|
public static void init()
|
||||||
|
@ -146,8 +148,7 @@ public class ModItems
|
||||||
white_dye = registerItem(new Item(), "white_dye");
|
white_dye = registerItem(new Item(), "white_dye");
|
||||||
black_dye = registerItem(new Item(), "black_dye");
|
black_dye = registerItem(new Item(), "black_dye");
|
||||||
|
|
||||||
earth = registerItem(new Item(), "earth");
|
earth = registerItem(new Item(), "earth", null);
|
||||||
earth.setCreativeTab(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item registerItem(Item item, String name)
|
public static Item registerItem(Item item, String name)
|
||||||
|
@ -155,7 +156,7 @@ public class ModItems
|
||||||
return registerItem(item, name, CreativeTabBOP.instance);
|
return registerItem(item, name, CreativeTabBOP.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item registerItem(Item item, String name, CreativeTabs tab)
|
public static Item registerItem(Item item, String name, @Nullable CreativeTabs tab)
|
||||||
{
|
{
|
||||||
item.setUnlocalizedName(name);
|
item.setUnlocalizedName(name);
|
||||||
if (tab != null)
|
if (tab != null)
|
||||||
|
|
|
@ -8,21 +8,15 @@
|
||||||
|
|
||||||
package biomesoplenty.common.item;
|
package biomesoplenty.common.item;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
import biomesoplenty.common.block.IBOPBlock;
|
import biomesoplenty.common.block.IBOPBlock;
|
||||||
import biomesoplenty.common.util.block.BlockStateUtils;
|
import biomesoplenty.common.util.block.BlockStateUtils;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
|
|
||||||
public class ItemBOPBlock extends ItemBlock
|
public class ItemBOPBlock extends ItemBlock
|
||||||
{
|
{
|
||||||
|
@ -45,7 +39,6 @@ public class ItemBOPBlock extends ItemBlock
|
||||||
|
|
||||||
// define the items which will appear in the creative tab (called by ItemBlock class)
|
// define the items which will appear in the creative tab (called by ItemBlock class)
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
|
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
|
||||||
{
|
{
|
||||||
if (this.isInCreativeTab(tab))
|
if (this.isInCreativeTab(tab))
|
||||||
|
|
|
@ -8,15 +8,11 @@
|
||||||
|
|
||||||
package biomesoplenty.common.item;
|
package biomesoplenty.common.item;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import biomesoplenty.api.enums.BOPGems;
|
import biomesoplenty.api.enums.BOPGems;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
|
|
||||||
public class ItemGem extends Item
|
public class ItemGem extends Item
|
||||||
{
|
{
|
||||||
|
@ -29,7 +25,6 @@ public class ItemGem extends Item
|
||||||
|
|
||||||
// add all the gem types as separate items in the creative tab
|
// add all the gem types as separate items in the creative tab
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
|
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
|
||||||
{
|
{
|
||||||
if (this.isInCreativeTab(tab))
|
if (this.isInCreativeTab(tab))
|
||||||
|
|
|
@ -12,22 +12,17 @@ import biomesoplenty.api.block.BOPBlocks;
|
||||||
import biomesoplenty.api.item.BOPItems;
|
import biomesoplenty.api.item.BOPItems;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.stats.StatList;
|
import net.minecraft.stats.StatList;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.*;
|
||||||
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.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ItemJarFilled extends Item
|
public class ItemJarFilled extends Item
|
||||||
{
|
{
|
||||||
|
@ -57,8 +52,7 @@ public class ItemJarFilled extends Item
|
||||||
|
|
||||||
// add all the contents types as separate items in the creative tab
|
// add all the contents types as separate items in the creative tab
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
public void getSubItems(@Nonnull CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems)
|
||||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
|
|
||||||
{
|
{
|
||||||
if (this.isInCreativeTab(tab))
|
if (this.isInCreativeTab(tab))
|
||||||
{
|
{
|
||||||
|
@ -89,100 +83,81 @@ public class ItemJarFilled extends Item
|
||||||
|
|
||||||
// get the correct name for this item by looking up the meta value in the JarContents enum
|
// get the correct name for this item by looking up the meta value in the JarContents enum
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public String getUnlocalizedName(ItemStack stack)
|
public String getUnlocalizedName(ItemStack stack)
|
||||||
{
|
{
|
||||||
return super.getUnlocalizedName() + "_" + this.getContentsType(stack).getName();
|
return super.getUnlocalizedName() + "_" + this.getContentsType(stack).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nonnull
|
||||||
protected Vec3d getAirPositionInFrontOfPlayer(World world, EntityPlayer player, double targetDistance)
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand)
|
||||||
{
|
{
|
||||||
float cosYaw = MathHelper.cos(-player.rotationYaw * 0.017453292F - (float)Math.PI);
|
ItemStack heldStack = player.getHeldItem(hand);
|
||||||
float sinYaw = MathHelper.sin(-player.rotationYaw * 0.017453292F - (float)Math.PI);
|
if (getContentsType(heldStack) == JarContents.BLUE_FIRE)
|
||||||
float cosPitch = -MathHelper.cos(-player.rotationPitch * 0.017453292F);
|
|
||||||
float facingX = sinYaw * cosPitch;
|
|
||||||
float facingY = MathHelper.sin(-player.rotationPitch * 0.017453292F);
|
|
||||||
float facingZ = cosYaw * cosPitch;
|
|
||||||
|
|
||||||
Vec3d playerEyePosition = new Vec3d(player.posX, player.posY + (double)player.getEyeHeight(), player.posZ);
|
|
||||||
Vec3d targetPosition = playerEyePosition.addVector((double)facingX * targetDistance, (double)facingY * targetDistance, (double)facingZ * targetDistance);
|
|
||||||
|
|
||||||
// see if there's anything in the way
|
|
||||||
RayTraceResult hit = world.rayTraceBlocks(playerEyePosition, targetPosition, true, false, false);
|
|
||||||
if (hit == null)
|
|
||||||
{
|
{
|
||||||
return targetPosition;
|
RayTraceResult raytraceresult = this.rayTrace(world, player, false);
|
||||||
|
if (raytraceresult == null)
|
||||||
|
{
|
||||||
|
return new ActionResult<>(EnumActionResult.PASS, heldStack);
|
||||||
|
}
|
||||||
|
else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK)
|
||||||
|
{
|
||||||
|
return new ActionResult<>(EnumActionResult.PASS, heldStack);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// there's something in the way - return the point just before the collision point
|
BlockPos rayPos = raytraceresult.getBlockPos();
|
||||||
double distance = playerEyePosition.distanceTo(hit.hitVec) * 0.9;
|
|
||||||
return playerEyePosition.addVector((double)facingX * distance, (double)facingY * distance, (double)facingZ * distance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (!world.isBlockModifiable(player, rayPos))
|
||||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
|
|
||||||
{
|
{
|
||||||
ItemStack stack = player.getHeldItem(hand);
|
return new ActionResult<>(EnumActionResult.FAIL, heldStack);
|
||||||
if (world.isRemote) {return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);}
|
|
||||||
switch (this.getContentsType(stack))
|
|
||||||
{
|
|
||||||
case HONEY: default:
|
|
||||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ItemStack emptyJar(ItemStack stack, EntityPlayer player, ItemStack emptyJarStack)
|
|
||||||
{
|
|
||||||
if (!player.capabilities.isCreativeMode)
|
|
||||||
{
|
|
||||||
stack.setCount(stack.getCount() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.addStat(StatList.getObjectUseStats(this));
|
|
||||||
|
|
||||||
if (!player.capabilities.isCreativeMode)
|
|
||||||
{
|
|
||||||
if (!player.inventory.addItemStackToInventory(emptyJarStack))
|
|
||||||
{
|
|
||||||
player.dropItem(emptyJarStack, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
|
||||||
{
|
|
||||||
ItemStack stack = player.getHeldItem(hand);
|
|
||||||
if (world.isRemote) {return EnumActionResult.FAIL;}
|
|
||||||
switch (this.getContentsType(stack))
|
|
||||||
{
|
|
||||||
case BLUE_FIRE:
|
|
||||||
pos = pos.offset(facing);
|
|
||||||
ItemStack itemstack = player.getHeldItem(hand);
|
|
||||||
|
|
||||||
if (!player.canPlayerEdit(pos, facing, itemstack))
|
|
||||||
{
|
|
||||||
return EnumActionResult.FAIL;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (world.isAirBlock(pos) && world.getBlockState(pos.down()).isTopSolid())
|
boolean isReplaceable = world.getBlockState(rayPos).getBlock().isReplaceable(world, rayPos);
|
||||||
|
BlockPos pos = isReplaceable && raytraceresult.sideHit == EnumFacing.UP ? rayPos : rayPos.offset(raytraceresult.sideHit);
|
||||||
|
|
||||||
|
if (!player.canPlayerEdit(pos, raytraceresult.sideHit, heldStack))
|
||||||
|
{
|
||||||
|
return new ActionResult<>(EnumActionResult.FAIL, heldStack);
|
||||||
|
}
|
||||||
|
else if (world.getBlockState(pos).getBlock().isReplaceable(world, pos) && world.getBlockState(pos.down()).isTopSolid())
|
||||||
{
|
{
|
||||||
world.setBlockState(pos, BOPBlocks.blue_fire.getDefaultState());
|
world.setBlockState(pos, BOPBlocks.blue_fire.getDefaultState());
|
||||||
this.emptyJar(stack, player, new ItemStack(BOPItems.jar_empty));
|
this.emptyJar(player, hand);
|
||||||
return EnumActionResult.SUCCESS;
|
return new ActionResult<>(EnumActionResult.SUCCESS, heldStack);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new ActionResult<>(EnumActionResult.FAIL, heldStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ActionResult<>(EnumActionResult.PASS, heldStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: are you supposed to be able to pour out honey? How much should you get? Why don't we just use buckets?
|
private void emptyJar(EntityPlayer player, EnumHand hand)
|
||||||
case HONEY: default:
|
{
|
||||||
return EnumActionResult.SUCCESS;
|
ItemStack heldStack = player.getHeldItem(hand);
|
||||||
|
ItemStack emptyJar = new ItemStack(BOPItems.jar_empty);
|
||||||
|
if (!player.capabilities.isCreativeMode)
|
||||||
|
{
|
||||||
|
if (heldStack.isEmpty())
|
||||||
|
{
|
||||||
|
player.setHeldItem(hand, emptyJar);
|
||||||
|
}
|
||||||
|
else if (!player.inventory.addItemStackToInventory(emptyJar))
|
||||||
|
{
|
||||||
|
player.dropItem(emptyJar, false);
|
||||||
|
}
|
||||||
|
else if (player instanceof EntityPlayerMP)
|
||||||
|
{
|
||||||
|
((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
|
||||||
|
}
|
||||||
|
heldStack.shrink(1);
|
||||||
|
player.addStat(Objects.requireNonNull(StatList.getObjectUseStats(this)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue