mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Revamped the Drill to use the correct Method, made it fully work on Client and Server now
This commit is contained in:
parent
1b36e7c19a
commit
2d5ac591d8
2 changed files with 64 additions and 63 deletions
|
@ -193,47 +193,47 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
|
||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void breakBlocks(ItemStack stack, int radius, World world, int x, int y, int z, EntityPlayer player){
|
public boolean breakBlocks(ItemStack stack, int radius, World world, int x, int y, int z, EntityPlayer player){
|
||||||
int xRange = radius;
|
int xRange = radius;
|
||||||
int yRange = radius;
|
int yRange = radius;
|
||||||
int zRange = 0;
|
int zRange = 0;
|
||||||
|
|
||||||
MovingObjectPosition pos = WorldUtil.getNearestBlockWithDefaultReachDistance(world, player);
|
MovingObjectPosition pos = WorldUtil.getNearestBlockWithDefaultReachDistance(world, player);
|
||||||
|
if(pos == null) return false;
|
||||||
|
|
||||||
if(pos != null){
|
int side = pos.sideHit;
|
||||||
int side = pos.sideHit;
|
if(side == 0 || side == 1){
|
||||||
if(side == 0 || side == 1){
|
zRange = radius;
|
||||||
zRange = radius;
|
yRange = 0;
|
||||||
yRange = 0;
|
}
|
||||||
}
|
if(side == 4 || side == 5){
|
||||||
if(side == 4 || side == 5){
|
xRange = 0;
|
||||||
xRange = 0;
|
zRange = radius;
|
||||||
zRange = radius;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//Break Middle Block first
|
//Break Middle Block first
|
||||||
int use = this.getEnergyUsePerBlock(stack);
|
int use = this.getEnergyUsePerBlock(stack);
|
||||||
if(this.getEnergyStored(stack) >= use){
|
if(this.getEnergyStored(stack) >= use){
|
||||||
this.tryHarvestBlock(world, x, y, z, false, stack, player, use);
|
this.tryHarvestBlock(world, x, y, z, false, stack, player, use);
|
||||||
}
|
}
|
||||||
else return;
|
else return true;
|
||||||
|
|
||||||
//Break Blocks around
|
//Break Blocks around
|
||||||
if(radius > 0){
|
if(radius > 0){
|
||||||
for(int xPos = x-xRange; xPos <= x+xRange; xPos++){
|
for(int xPos = x-xRange; xPos <= x+xRange; xPos++){
|
||||||
for(int yPos = y-yRange; yPos <= y+yRange; yPos++){
|
for(int yPos = y-yRange; yPos <= y+yRange; yPos++){
|
||||||
for(int zPos = z-zRange; zPos <= z+zRange; zPos++){
|
for(int zPos = z-zRange; zPos <= z+zRange; zPos++){
|
||||||
if(!(x == xPos && y == yPos && z == zPos)){
|
if(!(x == xPos && y == yPos && z == zPos)){
|
||||||
if(this.getEnergyStored(stack) >= use){
|
if(this.getEnergyStored(stack) >= use){
|
||||||
this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use);
|
this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use);
|
||||||
}
|
|
||||||
else return;
|
|
||||||
}
|
}
|
||||||
|
else return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryHarvestBlock(World world, int xPos, int yPos, int zPos, boolean isExtra, ItemStack stack, EntityPlayer player, int use){
|
private void tryHarvestBlock(World world, int xPos, int yPos, int zPos, boolean isExtra, ItemStack stack, EntityPlayer player, int use){
|
||||||
|
@ -241,19 +241,24 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
|
||||||
float hardness = block.getBlockHardness(world, xPos, yPos, zPos);
|
float hardness = block.getBlockHardness(world, xPos, yPos, zPos);
|
||||||
int meta = world.getBlockMetadata(xPos, yPos, zPos);
|
int meta = world.getBlockMetadata(xPos, yPos, zPos);
|
||||||
if(hardness >= 0.0F && (!isExtra || (this.canHarvestBlock(block, stack) && !block.hasTileEntity(meta)))){
|
if(hardness >= 0.0F && (!isExtra || (this.canHarvestBlock(block, stack) && !block.hasTileEntity(meta)))){
|
||||||
this.extractEnergy(stack, use, false);
|
if(!world.isRemote){
|
||||||
|
this.extractEnergy(stack, use, false);
|
||||||
|
|
||||||
block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
|
block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
|
||||||
if(block.removedByPlayer(world, player, xPos, yPos, zPos, true)){
|
if(block.removedByPlayer(world, player, xPos, yPos, zPos, true)){
|
||||||
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
|
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
|
||||||
block.harvestBlock(world, player, xPos, yPos, zPos, meta);
|
block.harvestBlock(world, player, xPos, yPos, zPos, meta);
|
||||||
|
|
||||||
if(!EnchantmentHelper.getSilkTouchModifier(player)){
|
if(!EnchantmentHelper.getSilkTouchModifier(player)){
|
||||||
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player)));
|
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
|
||||||
|
|
||||||
if(isExtra){
|
if(block.removedByPlayer(world, player, xPos, yPos, zPos, true)){
|
||||||
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
|
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,38 +270,34 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase living){
|
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player){
|
||||||
if(living instanceof EntityPlayer){
|
boolean toReturn = true;
|
||||||
EntityPlayer player = (EntityPlayer)living;
|
int use = this.getEnergyUsePerBlock(stack);
|
||||||
int use = this.getEnergyUsePerBlock(stack);
|
if(this.getEnergyStored(stack) >= use){
|
||||||
if(this.getEnergyStored(stack) >= use){
|
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)) stack.addEnchantment(Enchantment.silkTouch, 1);
|
||||||
if(!world.isRemote){
|
else{
|
||||||
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)) stack.addEnchantment(Enchantment.silkTouch, 1);
|
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)) stack.addEnchantment(Enchantment.fortune, this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II) ? 3 : 1);
|
||||||
else{
|
}
|
||||||
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)) stack.addEnchantment(Enchantment.fortune, this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II) ? 3 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!living.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){
|
if(!player.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){
|
||||||
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
|
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
|
||||||
this.breakBlocks(stack, 2, world, x, y, z, player);
|
toReturn = this.breakBlocks(stack, 2, player.worldObj, x, y, z, player);
|
||||||
}
|
}
|
||||||
else this.breakBlocks(stack, 1, world, x, y, z, player);
|
else toReturn = this.breakBlocks(stack, 1, player.worldObj, x, y, z, player);
|
||||||
}
|
}
|
||||||
else this.breakBlocks(stack, 0, world, x, y, z, player);
|
else toReturn = this.breakBlocks(stack, 0, player.worldObj, x, y, z, player);
|
||||||
|
|
||||||
NBTTagList ench = stack.getEnchantmentTagList();
|
NBTTagList ench = stack.getEnchantmentTagList();
|
||||||
if(ench != null){
|
if(ench != null){
|
||||||
for(int i = 0; i < ench.tagCount(); i++){
|
for(int i = 0; i < ench.tagCount(); i++){
|
||||||
short id = ench.getCompoundTagAt(i).getShort("id");
|
short id = ench.getCompoundTagAt(i).getShort("id");
|
||||||
if(id == Enchantment.silkTouch.effectId || id == Enchantment.fortune.effectId){
|
if(id == Enchantment.silkTouch.effectId || id == Enchantment.fortune.effectId){
|
||||||
ench.removeTag(i);
|
ench.removeTag(i);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -227,7 +227,7 @@ public class WorldUtil{
|
||||||
float f1 = player.prevRotationPitch+(player.rotationPitch-player.prevRotationPitch)*f;
|
float f1 = player.prevRotationPitch+(player.rotationPitch-player.prevRotationPitch)*f;
|
||||||
float f2 = player.prevRotationYaw+(player.rotationYaw-player.prevRotationYaw)*f;
|
float f2 = player.prevRotationYaw+(player.rotationYaw-player.prevRotationYaw)*f;
|
||||||
double d0 = player.prevPosX+(player.posX-player.prevPosX)*(double)f;
|
double d0 = player.prevPosX+(player.posX-player.prevPosX)*(double)f;
|
||||||
double d1 = player.prevPosY+(player.posY-player.prevPosY)*(double)f+(double)player.getEyeHeight();
|
double d1 = player.prevPosY+(player.posY-player.prevPosY)*(double)f+(double)(world.isRemote ? player.getEyeHeight()-player.getDefaultEyeHeight() : player.getEyeHeight());
|
||||||
double d2 = player.prevPosZ+(player.posZ-player.prevPosZ)*(double)f;
|
double d2 = player.prevPosZ+(player.posZ-player.prevPosZ)*(double)f;
|
||||||
Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
|
Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
|
||||||
float f3 = MathHelper.cos(-f2*0.017453292F-(float)Math.PI);
|
float f3 = MathHelper.cos(-f2*0.017453292F-(float)Math.PI);
|
||||||
|
|
Loading…
Reference in a new issue