mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Moved ItemDrill's tryHarvestBlock to WorldUtil, for future use probably
This commit is contained in:
parent
12d09e1cae
commit
0db7276493
4 changed files with 93 additions and 70 deletions
|
@ -5,8 +5,6 @@ import ellpeck.actuallyadditions.config.ConfigurationHandler;
|
||||||
|
|
||||||
public enum ConfigBoolValues{
|
public enum ConfigBoolValues{
|
||||||
|
|
||||||
LEAF_BLOWER_ITEMS("Leaf Blower: Drops Items", ConfigCategories.TOOL_VALUES, true, "If the Leaf Blower lets destroyed Blocks' Drops drop"),
|
|
||||||
LEAF_BLOWER_PARTICLES("Leaf Blower: Particles", ConfigCategories.TOOL_VALUES, true, "If the Leaf Blower lets destroyed Blocks have particles when getting destroyed"),
|
|
||||||
LEAF_BLOWER_SOUND("Leaf Blower: Sound", ConfigCategories.TOOL_VALUES, true, "If the Leaf Blower makes Sounds"),
|
LEAF_BLOWER_SOUND("Leaf Blower: Sound", ConfigCategories.TOOL_VALUES, true, "If the Leaf Blower makes Sounds"),
|
||||||
|
|
||||||
JAM_VILLAGER_EXISTS("Jam Villager: Existence", ConfigCategories.WORLD_GEN, true, "If the Jam Villager and his House exist"),
|
JAM_VILLAGER_EXISTS("Jam Villager: Existence", ConfigCategories.WORLD_GEN, true, "If the Jam Villager and his House exist"),
|
||||||
|
|
|
@ -13,24 +13,19 @@ import ellpeck.actuallyadditions.util.ModUtil;
|
||||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.enchantment.Enchantment;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.SharedMonsterAttributes;
|
import net.minecraft.entity.SharedMonsterAttributes;
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.EnumRarity;
|
import net.minecraft.item.EnumRarity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.network.play.client.C07PacketPlayerDigging;
|
|
||||||
import net.minecraft.network.play.server.S23PacketBlockChange;
|
|
||||||
import net.minecraft.util.ChatComponentText;
|
import net.minecraft.util.ChatComponentText;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
|
@ -343,45 +338,8 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
|
||||||
boolean canHarvest = this.canHarvestBlock(block, stack) && (!isExtra || this.getDigSpeed(stack, block, meta) > 1.0F);
|
boolean canHarvest = this.canHarvestBlock(block, stack) && (!isExtra || this.getDigSpeed(stack, block, meta) > 1.0F);
|
||||||
if(hardness >= 0.0F && (!isExtra || (canHarvest && !block.hasTileEntity(meta)))){
|
if(hardness >= 0.0F && (!isExtra || (canHarvest && !block.hasTileEntity(meta)))){
|
||||||
this.extractEnergy(stack, use, false);
|
this.extractEnergy(stack, use, false);
|
||||||
|
//Break the Block
|
||||||
if(!world.isRemote){
|
return WorldUtil.playerHarvestBlock(world, xPos, yPos, zPos, player);
|
||||||
//Server-Side only, special cases
|
|
||||||
block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
//Shows the Harvest Particles and plays the Block's Sound
|
|
||||||
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
|
|
||||||
}
|
|
||||||
|
|
||||||
//If the Block was actually "removed", meaning it will drop an Item
|
|
||||||
boolean removed = block.removedByPlayer(world, player, xPos, yPos, zPos, canHarvest);
|
|
||||||
//Actually removes the Block from the World
|
|
||||||
if(removed){
|
|
||||||
//Before the Block is destroyed, special cases
|
|
||||||
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
|
|
||||||
|
|
||||||
if(!world.isRemote && !player.capabilities.isCreativeMode){
|
|
||||||
//Actually drops the Block's Items etc.
|
|
||||||
if(canHarvest){
|
|
||||||
block.harvestBlock(world, player, xPos, yPos, zPos, meta);
|
|
||||||
}
|
|
||||||
//Only drop XP when no Silk Touch is applied
|
|
||||||
if(!EnchantmentHelper.getSilkTouchModifier(player)){
|
|
||||||
//Drop XP depending on Fortune Level
|
|
||||||
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!world.isRemote){
|
|
||||||
//Update the Client of a Block Change
|
|
||||||
((EntityPlayerMP)player).playerNetServerHandler.sendPacket(new S23PacketBlockChange(xPos, yPos, zPos, world));
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
//Check the Server if a Block that changed on the Client really changed, if not, revert the change
|
|
||||||
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, xPos, yPos, zPos, Minecraft.getMinecraft().objectMouseOver.sideHit));
|
|
||||||
}
|
|
||||||
return removed;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,6 @@ public class ItemLeafBlower extends Item implements INameableItem{
|
||||||
|
|
||||||
public final int range = ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue();
|
public final int range = ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue();
|
||||||
public final int rangeUp = ConfigIntValues.LEAF_BLOWER_RANGE_UP.getValue();
|
public final int rangeUp = ConfigIntValues.LEAF_BLOWER_RANGE_UP.getValue();
|
||||||
public final boolean doesDrop = ConfigBoolValues.LEAF_BLOWER_ITEMS.isEnabled();
|
|
||||||
public final boolean hasParticles = ConfigBoolValues.LEAF_BLOWER_PARTICLES.isEnabled();
|
|
||||||
public final boolean hasSound = ConfigBoolValues.LEAF_BLOWER_SOUND.isEnabled();
|
public final boolean hasSound = ConfigBoolValues.LEAF_BLOWER_SOUND.isEnabled();
|
||||||
|
|
||||||
private final boolean isAdvanced;
|
private final boolean isAdvanced;
|
||||||
|
@ -73,14 +71,13 @@ public class ItemLeafBlower extends Item implements INameableItem{
|
||||||
//Deletes the Block
|
//Deletes the Block
|
||||||
world.setBlockToAir(theCoord.getX(), theCoord.getY(), theCoord.getZ());
|
world.setBlockToAir(theCoord.getX(), theCoord.getY(), theCoord.getZ());
|
||||||
//Plays the Breaking Sound
|
//Plays the Breaking Sound
|
||||||
if(this.hasParticles) world.playAuxSFX(2001, theCoord.getX(), theCoord.getY(), theCoord.getZ(), Block.getIdFromBlock(theBlock)+(meta << 12));
|
world.playAuxSFX(2001, theCoord.getX(), theCoord.getY(), theCoord.getZ(), Block.getIdFromBlock(theBlock)+(meta << 12));
|
||||||
|
|
||||||
if(this.doesDrop){
|
|
||||||
for(ItemStack theDrop : drops){
|
for(ItemStack theDrop : drops){
|
||||||
//Drops the Items into the World
|
//Drops the Items into the World
|
||||||
world.spawnEntityInWorld(new EntityItem(world, theCoord.getX() + 0.5, theCoord.getY() + 0.5, theCoord.getZ() + 0.5, theDrop));
|
world.spawnEntityInWorld(new EntityItem(world, theCoord.getX() + 0.5, theCoord.getY() + 0.5, theCoord.getZ() + 0.5, theDrop));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,15 @@ import cofh.api.energy.EnergyStorage;
|
||||||
import cofh.api.energy.IEnergyReceiver;
|
import cofh.api.energy.IEnergyReceiver;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.network.play.client.C07PacketPlayerDigging;
|
||||||
|
import net.minecraft.network.play.server.S23PacketBlockChange;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
|
@ -52,6 +56,7 @@ public class WorldUtil{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given Block with a given Meta is present in given Positions
|
* Checks if a given Block with a given Meta is present in given Positions
|
||||||
|
*
|
||||||
* @param positions The Positions, an array of {xCoord, yCoord, zCoord} arrays containing RELATIVE Positions
|
* @param positions The Positions, an array of {xCoord, yCoord, zCoord} arrays containing RELATIVE Positions
|
||||||
* @param block The Block
|
* @param block The Block
|
||||||
* @param meta The Meta
|
* @param meta The Meta
|
||||||
|
@ -154,7 +159,8 @@ public class WorldUtil{
|
||||||
if(filled != null && FluidContainerRegistry.isEmptyContainer(slots[inputSlot]) && (slots[outputSlot] == null || (slots[outputSlot].isItemEqual(filled) && slots[outputSlot].stackSize < slots[outputSlot].getMaxStackSize()))){
|
if(filled != null && FluidContainerRegistry.isEmptyContainer(slots[inputSlot]) && (slots[outputSlot] == null || (slots[outputSlot].isItemEqual(filled) && slots[outputSlot].stackSize < slots[outputSlot].getMaxStackSize()))){
|
||||||
int cap = FluidContainerRegistry.getContainerCapacity(tank.getFluid(), slots[inputSlot]);
|
int cap = FluidContainerRegistry.getContainerCapacity(tank.getFluid(), slots[inputSlot]);
|
||||||
if(cap > 0 && cap <= tank.getFluidAmount()){
|
if(cap > 0 && cap <= tank.getFluidAmount()){
|
||||||
if(slots[outputSlot] == null) slots[outputSlot] = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), slots[inputSlot].copy());
|
if(slots[outputSlot] == null)
|
||||||
|
slots[outputSlot] = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), slots[inputSlot].copy());
|
||||||
else slots[outputSlot].stackSize++;
|
else slots[outputSlot].stackSize++;
|
||||||
|
|
||||||
if(slots[outputSlot] != null){
|
if(slots[outputSlot] != null){
|
||||||
|
@ -175,7 +181,8 @@ public class WorldUtil{
|
||||||
if(slots[inputSlot] != null && FluidContainerRegistry.isFilledContainer(slots[inputSlot]) && (slots[outputSlot] == null || (slots[outputSlot].isItemEqual(FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy())) && slots[outputSlot].stackSize < slots[outputSlot].getMaxStackSize()))){
|
if(slots[inputSlot] != null && FluidContainerRegistry.isFilledContainer(slots[inputSlot]) && (slots[outputSlot] == null || (slots[outputSlot].isItemEqual(FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy())) && slots[outputSlot].stackSize < slots[outputSlot].getMaxStackSize()))){
|
||||||
if(containedFluid == null || FluidContainerRegistry.containsFluid(slots[inputSlot], new FluidStack(containedFluid, 0))){
|
if(containedFluid == null || FluidContainerRegistry.containsFluid(slots[inputSlot], new FluidStack(containedFluid, 0))){
|
||||||
if((tank.getFluid() == null || FluidContainerRegistry.getFluidForFilledItem(slots[inputSlot]).isFluidEqual(tank.getFluid())) && tank.getCapacity()-tank.getFluidAmount() >= FluidContainerRegistry.getContainerCapacity(slots[inputSlot])){
|
if((tank.getFluid() == null || FluidContainerRegistry.getFluidForFilledItem(slots[inputSlot]).isFluidEqual(tank.getFluid())) && tank.getCapacity()-tank.getFluidAmount() >= FluidContainerRegistry.getContainerCapacity(slots[inputSlot])){
|
||||||
if(slots[outputSlot] == null) slots[outputSlot] = FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy());
|
if(slots[outputSlot] == null)
|
||||||
|
slots[outputSlot] = FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy());
|
||||||
else slots[outputSlot].stackSize++;
|
else slots[outputSlot].stackSize++;
|
||||||
|
|
||||||
tank.fill(FluidContainerRegistry.getFluidForFilledItem(slots[inputSlot]), true);
|
tank.fill(FluidContainerRegistry.getFluidForFilledItem(slots[inputSlot]), true);
|
||||||
|
@ -188,13 +195,20 @@ public class WorldUtil{
|
||||||
|
|
||||||
public static ForgeDirection getDirectionByRotatingSide(int side){
|
public static ForgeDirection getDirectionByRotatingSide(int side){
|
||||||
switch(side){
|
switch(side){
|
||||||
case 0: return ForgeDirection.UP;
|
case 0:
|
||||||
case 1: return ForgeDirection.DOWN;
|
return ForgeDirection.UP;
|
||||||
case 2: return ForgeDirection.NORTH;
|
case 1:
|
||||||
case 3: return ForgeDirection.EAST;
|
return ForgeDirection.DOWN;
|
||||||
case 4: return ForgeDirection.SOUTH;
|
case 2:
|
||||||
case 5: return ForgeDirection.WEST;
|
return ForgeDirection.NORTH;
|
||||||
default: return ForgeDirection.UNKNOWN;
|
case 3:
|
||||||
|
return ForgeDirection.EAST;
|
||||||
|
case 4:
|
||||||
|
return ForgeDirection.SOUTH;
|
||||||
|
case 5:
|
||||||
|
return ForgeDirection.WEST;
|
||||||
|
default:
|
||||||
|
return ForgeDirection.UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,4 +273,60 @@ public class WorldUtil{
|
||||||
Vec3 vec31 = vec3.addVector((double)f7*distance, (double)f6*distance, (double)f8*distance);
|
Vec3 vec31 = vec3.addVector((double)f7*distance, (double)f6*distance, (double)f8*distance);
|
||||||
return world.func_147447_a(vec3, vec31, p1, p2, p3);
|
return world.func_147447_a(vec3, vec31, p1, p2, p3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Harvests a Block by a Player
|
||||||
|
*
|
||||||
|
* @param world The World
|
||||||
|
* @param xPos The X Coordinate
|
||||||
|
* @param yPos The Y Coordinate
|
||||||
|
* @param zPos The Z Coordinate
|
||||||
|
* @param player The Player
|
||||||
|
* @return If the Block could be harvested normally (so that it drops an item)
|
||||||
|
*/
|
||||||
|
public static boolean playerHarvestBlock(World world, int xPos, int yPos, int zPos, EntityPlayer player){
|
||||||
|
Block block = world.getBlock(xPos, yPos, zPos);
|
||||||
|
int meta = world.getBlockMetadata(xPos, yPos, zPos);
|
||||||
|
//If the Block can be harvested or not
|
||||||
|
boolean canHarvest = block.canHarvestBlock(player, meta) && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem().canHarvestBlock(block, player.getCurrentEquippedItem());
|
||||||
|
|
||||||
|
if(!world.isRemote){
|
||||||
|
//Server-Side only, special cases
|
||||||
|
block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//Shows the Harvest Particles and plays the Block's Sound
|
||||||
|
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
|
||||||
|
}
|
||||||
|
|
||||||
|
//If the Block was actually "removed", meaning it will drop an Item
|
||||||
|
boolean removed = block.removedByPlayer(world, player, xPos, yPos, zPos, canHarvest);
|
||||||
|
//Actually removes the Block from the World
|
||||||
|
if(removed){
|
||||||
|
//Before the Block is destroyed, special cases
|
||||||
|
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
|
||||||
|
|
||||||
|
if(!world.isRemote && !player.capabilities.isCreativeMode){
|
||||||
|
//Actually drops the Block's Items etc.
|
||||||
|
if(canHarvest){
|
||||||
|
block.harvestBlock(world, player, xPos, yPos, zPos, meta);
|
||||||
|
}
|
||||||
|
//Only drop XP when no Silk Touch is applied
|
||||||
|
if(!EnchantmentHelper.getSilkTouchModifier(player)){
|
||||||
|
//Drop XP depending on Fortune Level
|
||||||
|
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!world.isRemote){
|
||||||
|
//Update the Client of a Block Change
|
||||||
|
((EntityPlayerMP)player).playerNetServerHandler.sendPacket(new S23PacketBlockChange(xPos, yPos, zPos, world));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//Check the Server if a Block that changed on the Client really changed, if not, revert the change
|
||||||
|
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, xPos, yPos, zPos, Minecraft.getMinecraft().objectMouseOver.sideHit));
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue