mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Fixed a big Bug with the Drill
This commit is contained in:
parent
255e357039
commit
249c8cb3ca
6 changed files with 92 additions and 41 deletions
|
@ -22,6 +22,7 @@ import net.minecraft.util.StatCollector;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockPhantomface extends BlockContainerBase implements INameableItem{
|
||||
|
||||
|
@ -41,6 +42,7 @@ public class BlockPhantomface extends BlockContainerBase implements INameableIte
|
|||
this.setHardness(4.5F);
|
||||
this.setResistance(10.0F);
|
||||
this.setStepSound(soundTypeStone);
|
||||
this.setTickRandomly(true);
|
||||
|
||||
if(type == FACE || type == LIQUIFACE || type == ENERGYFACE) this.range = ConfigIntValues.PHANTOMFACE_RANGE.getValue();
|
||||
else if(type == BREAKER || type == PLACER) this.range = ConfigIntValues.PHANTOM_PLACER_RANGE.getValue();
|
||||
|
@ -127,6 +129,28 @@ public class BlockPhantomface extends BlockContainerBase implements INameableIte
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void randomDisplayTick(World world, int x, int y, int z, Random rand){
|
||||
WorldPos boundPosition = null;
|
||||
if(this.type == FACE || this.type == ENERGYFACE || this.type == LIQUIFACE) boundPosition = ((TileEntityPhantomface)world.getTileEntity(x, y, z)).boundPosition;
|
||||
else if(this.type == PLACER || this.type == BREAKER) boundPosition = ((TileEntityPhantomPlacer)world.getTileEntity(x, y, z)).boundPosition;
|
||||
|
||||
if(boundPosition != null){
|
||||
for(int l = 0; l < 3; l++){
|
||||
double d1 = (double)((float)boundPosition.getY()+rand.nextFloat());
|
||||
int i1 = rand.nextInt(2)*2-1;
|
||||
int j1 = rand.nextInt(2)*2-1;
|
||||
double d4 = ((double)rand.nextFloat()-0.5D)*0.125D;
|
||||
double d2 = (double)boundPosition.getZ()+0.5D+0.25D*(double)j1;
|
||||
double d5 = (double)(rand.nextFloat()*1.0F*(float)j1);
|
||||
double d0 = (double)boundPosition.getX()+0.5D+0.25D*(double)i1;
|
||||
double d3 = (double)(rand.nextFloat()*1.0F*(float)i1);
|
||||
world.spawnParticle("portal", d0, d1, d2, d3, d4, d5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TheItemBlock extends ItemBlock{
|
||||
|
||||
private Block theBlock;
|
||||
|
|
|
@ -3,7 +3,6 @@ package ellpeck.actuallyadditions.items;
|
|||
import cofh.api.energy.ItemEnergyContainer;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.ActuallyAdditions;
|
||||
|
@ -19,10 +18,11 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
|
@ -36,8 +36,6 @@ import net.minecraft.util.MovingObjectPosition;
|
|||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -268,29 +266,18 @@ public class ItemDrill extends ItemEnergyContainer implements INameableItem{
|
|||
if(this.getEnergyStored(stack) >= use){
|
||||
Block block = world.getBlock(xPos, yPos, zPos);
|
||||
float hardness = block.getBlockHardness(world, xPos, yPos, zPos);
|
||||
int meta = world.getBlockMetadata(xPos, yPos, zPos);
|
||||
if(hardness > -1.0F && ((x == xPos && y == yPos && z == zPos) || this.canHarvestBlock(block, stack))){
|
||||
this.extractEnergy(stack, use, false);
|
||||
|
||||
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
int meta = world.getBlockMetadata(xPos, yPos, zPos);
|
||||
|
||||
if(block.canSilkHarvest(world, player, xPos, yPos, zPos, meta) && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)){
|
||||
addSilkDrops(drops, block, meta, world, player);
|
||||
}
|
||||
else{
|
||||
int fortune = this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE) ? (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II) ? 3 : 1) : 0;
|
||||
drops.addAll(block.getDrops(world, xPos, yPos, zPos, meta, fortune));
|
||||
block.dropXpOnBlockBreak(world, x, y, z, block.getExpDrop(world, meta, fortune));
|
||||
block.harvestBlock(world, player, xPos, yPos, zPos, meta);
|
||||
if(!EnchantmentHelper.getSilkTouchModifier(player)){
|
||||
block.dropXpOnBlockBreak(world, x, y, z, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player)));
|
||||
}
|
||||
|
||||
if(!(x == xPos && y == yPos && z == zPos)){
|
||||
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
|
||||
}
|
||||
world.setBlockToAir(xPos, yPos, zPos);
|
||||
for(ItemStack theDrop : drops){
|
||||
EntityItem item = new EntityItem(world, xPos+0.5, yPos+0.5, zPos+0.5, theDrop);
|
||||
item.delayBeforeCanPickup = 10;
|
||||
world.spawnEntityInWorld(item);
|
||||
if(!(xPos == x && yPos == y && zPos == z)){
|
||||
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -301,18 +288,6 @@ public class ItemDrill extends ItemEnergyContainer implements INameableItem{
|
|||
}
|
||||
}
|
||||
|
||||
public static void addSilkDrops(ArrayList<ItemStack> drops, Block block, int meta, World world, EntityPlayer player){
|
||||
try{
|
||||
Method method = ReflectionHelper.findMethod(Block.class, block, new String[]{"createStackedBlock"}, int.class);
|
||||
ItemStack silkDrop = (ItemStack)method.invoke(block, meta);
|
||||
if(silkDrop != null) drops.add(silkDrop);
|
||||
}
|
||||
catch(Exception e){
|
||||
player.addChatComponentMessage(new ChatComponentText("Oh! That shouldn't have happened! Trying to get and use a private Method here might have bugged! Report this situation to the Mod Author ASAP!"));
|
||||
ModUtil.LOGGER.log(Level.ERROR, "Player "+player.getDisplayName()+" who should break a Block using a Drill at "+player.posX+", "+player.posY+", "+player.posZ+" in World "+world.provider.dimensionId+" threw an Exception trying to get and use a private Method! Report this to the Mod Author ASAP!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "itemDrill";
|
||||
|
@ -325,6 +300,11 @@ public class ItemDrill extends ItemEnergyContainer implements INameableItem{
|
|||
int use = this.getEnergyUsePerBlock(stack);
|
||||
if(this.getEnergyStored(stack) >= use){
|
||||
if(!world.isRemote){
|
||||
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)) stack.addEnchantment(Enchantment.silkTouch, 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(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
|
||||
this.breakBlocks(stack, 2, world, x, y, z, player);
|
||||
|
@ -332,6 +312,16 @@ public class ItemDrill extends ItemEnergyContainer implements INameableItem{
|
|||
else this.breakBlocks(stack, 1, world, x, y, z, player);
|
||||
}
|
||||
else this.breakBlocks(stack, 0, world, x, y, z, player);
|
||||
|
||||
NBTTagList ench = stack.getEnchantmentTagList();
|
||||
if(ench != null){
|
||||
for(int i = 0; i < ench.tagCount(); i++){
|
||||
short id = ench.getCompoundTagAt(i).getShort("id");
|
||||
if(id == Enchantment.silkTouch.effectId || id == Enchantment.fortune.effectId){
|
||||
ench.removeTag(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,8 @@ package ellpeck.actuallyadditions.items.tools;
|
|||
|
||||
import com.google.common.collect.Sets;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.items.InitItems;
|
||||
import ellpeck.actuallyadditions.util.INameableItem;
|
||||
import ellpeck.actuallyadditions.util.ItemUtil;
|
||||
import ellpeck.actuallyadditions.util.KeyUtil;
|
||||
|
@ -15,7 +13,9 @@ import net.minecraft.block.material.Material;
|
|||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -29,9 +29,9 @@ import java.util.Set;
|
|||
@SuppressWarnings("unchecked")
|
||||
public class ItemAllToolAA extends ItemTool implements INameableItem{
|
||||
|
||||
public static final Set axeSet = ReflectionHelper.getPrivateValue(ItemAxe.class, (ItemAxe)InitItems.itemAxeEmerald, 0);
|
||||
public static final Set pickSet = ReflectionHelper.getPrivateValue(ItemPickaxe.class, (ItemPickaxe)InitItems.itemPickaxeEmerald, 0);
|
||||
public static final Set shovelSet = ReflectionHelper.getPrivateValue(ItemSpade.class, (ItemSpade)InitItems.itemShovelEmerald, 0);
|
||||
public static final Set axeSet = Sets.newHashSet(Blocks.planks, Blocks.bookshelf, Blocks.log, Blocks.log2, Blocks.chest, Blocks.pumpkin, Blocks.lit_pumpkin);
|
||||
public static final Set pickSet = Sets.newHashSet(Blocks.cobblestone, Blocks.double_stone_slab, Blocks.stone_slab, Blocks.stone, Blocks.sandstone, Blocks.mossy_cobblestone, Blocks.iron_ore, Blocks.iron_block, Blocks.coal_ore, Blocks.gold_block, Blocks.gold_ore, Blocks.diamond_ore, Blocks.diamond_block, Blocks.ice, Blocks.netherrack, Blocks.lapis_ore, Blocks.lapis_block, Blocks.redstone_ore, Blocks.lit_redstone_ore, Blocks.rail, Blocks.detector_rail, Blocks.golden_rail, Blocks.activator_rail);
|
||||
public static final Set shovelSet = Sets.newHashSet(Blocks.grass, Blocks.dirt, Blocks.sand, Blocks.gravel, Blocks.snow_layer, Blocks.snow, Blocks.clay, Blocks.farmland, Blocks.soul_sand, Blocks.mycelium);
|
||||
|
||||
private static final Set allSet = Sets.newHashSet();
|
||||
static{
|
||||
|
|
|
@ -70,7 +70,7 @@ public class PacketSyncerToClient implements IMessage{
|
|||
|
||||
public static void sendPacket(TileEntity tile){
|
||||
if(tile instanceof IPacketSyncerToClient){
|
||||
PacketHandler.theNetwork.sendToAllAround(new PacketSyncerToClient(tile, ((IPacketSyncerToClient)tile).getValues()), new NetworkRegistry.TargetPoint(tile.getWorldObj().provider.dimensionId, tile.xCoord, tile.yCoord, tile.zCoord, 64));
|
||||
PacketHandler.theNetwork.sendToAllAround(new PacketSyncerToClient(tile, ((IPacketSyncerToClient)tile).getValues()), new NetworkRegistry.TargetPoint(tile.getWorldObj().provider.dimensionId, tile.xCoord, tile.yCoord, tile.zCoord, 128));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import cofh.api.energy.IEnergyReceiver;
|
|||
import ellpeck.actuallyadditions.blocks.BlockPhantomface;
|
||||
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
||||
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
||||
import ellpeck.actuallyadditions.network.sync.IPacketSyncerToClient;
|
||||
import ellpeck.actuallyadditions.network.sync.PacketSyncerToClient;
|
||||
import ellpeck.actuallyadditions.util.WorldPos;
|
||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -23,9 +25,10 @@ import net.minecraftforge.fluids.FluidStack;
|
|||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class TileEntityPhantomface extends TileEntityInventoryBase{
|
||||
public class TileEntityPhantomface extends TileEntityInventoryBase implements IPacketSyncerToClient{
|
||||
|
||||
public WorldPos boundPosition;
|
||||
private WorldPos lastBoundPos;
|
||||
|
||||
public int type;
|
||||
|
||||
|
@ -69,6 +72,11 @@ public class TileEntityPhantomface extends TileEntityInventoryBase{
|
|||
if(!this.hasBoundTile()){
|
||||
this.boundPosition = null;
|
||||
}
|
||||
|
||||
if(this.boundPosition != null && !this.boundPosition.isEqual(this.lastBoundPos)){
|
||||
this.lastBoundPos = this.boundPosition.copy();
|
||||
this.sendUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,6 +125,27 @@ public class TileEntityPhantomface extends TileEntityInventoryBase{
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getValues(){
|
||||
if(this.boundPosition != null){
|
||||
return new int[]{this.boundPosition.getWorld().provider.dimensionId, this.boundPosition.getX(), this.boundPosition.getY(), this.boundPosition.getZ()};
|
||||
}
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValues(int[] values){
|
||||
if(values.length > 0){
|
||||
this.boundPosition = new WorldPos(DimensionManager.getWorld(values[0]), values[1], values[2], values[3]);
|
||||
}
|
||||
else this.boundPosition = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUpdate(){
|
||||
PacketSyncerToClient.sendPacket(this);
|
||||
}
|
||||
|
||||
public static class TileEntityPhantomLiquiface extends TileEntityPhantomface implements IFluidHandler{
|
||||
|
||||
public TileEntityPhantomLiquiface(){
|
||||
|
|
|
@ -41,4 +41,12 @@ public class WorldPos{
|
|||
public TileEntity getTileEntity(){
|
||||
return this.world != null ? this.world.getTileEntity(this.x, this.y, this.z) : null;
|
||||
}
|
||||
|
||||
public boolean isEqual(WorldPos pos){
|
||||
return pos != null && this.x == pos.getX() && this.y == pos.getY() && this.z == pos.getZ() && this.world == pos.getWorld();
|
||||
}
|
||||
|
||||
public WorldPos copy(){
|
||||
return new WorldPos(this.world, this.x, this.y, this.z);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue