mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 20:22:33 +00:00
claim bypass fix --rods
This commit is contained in:
1 parent
9da2885b18
commit
a9112a40fb
13 files changed
+95
-50
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package vazkii.botania.common.core.helper;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemHelper {
|
||||
public static boolean canPlaceBlock(World world, int x, int y, int z, int xAt, int yAt, int zAt, EntityPlayer player){
|
||||
Block block = world.getBlock(x,y,z);
|
||||
Block blockAt= world.getBlock(xAt,zAt,yAt);
|
||||
int meta = world.getBlockMetadata(x,y,z);
|
||||
BlockSnapshot snapshot = new BlockSnapshot(world,x,y,z,block,meta);
|
||||
BlockEvent.PlaceEvent event = new BlockEvent.PlaceEvent(snapshot,blockAt,player);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
|
||||
return !event.isCanceled();
|
||||
}
|
||||
// public static boolean canPlaceMultiBLock(World world, List<ChunkCoordinates> list, int xAt, int yAt, int zAt, EntityPlayer player){
|
||||
//
|
||||
// Block block = world.getBlock(xAt,yAt ,zAt);
|
||||
// BlockEvent.MultiPlaceEvent event = new BlockEvent.MultiPlaceEvent(blocksnapshots,block,player);
|
||||
// }
|
||||
public static boolean canBreakBlock(World world,int x, int y, int z,EntityPlayer player){
|
||||
Block block = world.getBlock(x,y,z);
|
||||
int meta = world.getBlockMetadata(x,y,z);
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, meta, player);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
boolean canMineBlock = world.canMineBlock(player,x,y,z);
|
||||
|
||||
return !event.isCanceled() && canMineBlock;
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,8 @@ public class EntityFlameRing extends Entity {
|
||||
for(EntityLivingBase entity : entities) {
|
||||
if(entity == null || MathHelper.pointDistancePlane(posX, posY, entity.posX, entity.posY) > radius)
|
||||
continue;
|
||||
|
||||
entity.setFire(4);
|
||||
if(entity.attackEntityFrom(DamageSource.onFire,1))
|
||||
entity.setFire(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraftforge.event.world.BlockEvent;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.core.helper.ItemHelper;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.item.equipment.tool.elementium.ItemElementiumPick;
|
||||
import vazkii.botania.common.item.equipment.tool.terrasteel.ItemTerraPick;
|
||||
@@ -80,13 +81,8 @@ public final class ToolCommons {
|
||||
|
||||
if(block != null && blk != block)
|
||||
return;
|
||||
if(!world.isRemote){
|
||||
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world,((EntityPlayerMP)player).theItemInWorldManager.getGameType(),(EntityPlayerMP)player, x, y, z);
|
||||
if(event.isCanceled())
|
||||
return;
|
||||
}
|
||||
Material mat = world.getBlock(x, y, z).getMaterial();
|
||||
if(!world.isRemote && blk != null && !blk.isAir(world, x, y, z) && blk.getPlayerRelativeBlockHardness(player, world, x, y, z) > 0) {
|
||||
if(!world.isRemote && ItemHelper.canBreakBlock(world,x,y,z,player) && blk != null && !blk.isAir(world, x, y, z) && blk.getPlayerRelativeBlockHardness(player, world, x, y, z) > 0) {
|
||||
if(!blk.canHarvestBlock(player, meta) || !isRightMaterial(mat, materialsListing))
|
||||
return;
|
||||
|
||||
|
||||
@@ -30,25 +30,7 @@ public class Lens {
|
||||
public void apply(ItemStack stack, BurstProperties props) {
|
||||
// NO-OP
|
||||
}
|
||||
protected boolean canPlaceBlock(World world, int x, int y, int z, int xAt, int yAt, int zAt, EntityPlayer player){
|
||||
Block block = world.getBlock(x,y,z);
|
||||
Block blockAt= world.getBlock(xAt,zAt,yAt);
|
||||
int meta = world.getBlockMetadata(x,y,z);
|
||||
BlockSnapshot snapshot = new BlockSnapshot(world,x,y,z,block,meta);
|
||||
BlockEvent.PlaceEvent event = new BlockEvent.PlaceEvent(snapshot,blockAt,player);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
|
||||
return !event.isCanceled();
|
||||
}
|
||||
protected boolean canBreakBlock(World world,int x, int y, int z,EntityPlayer player){
|
||||
Block block = world.getBlock(x,y,z);
|
||||
int meta = world.getBlockMetadata(x,y,z);
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, meta, player);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
boolean canMineBlock = world.canMineBlock(player,x,y,z);
|
||||
|
||||
return !event.isCanceled() && canMineBlock;
|
||||
}
|
||||
protected boolean canInteract(EntityPlayer player, Entity entity){
|
||||
EntityInteractEvent event = new EntityInteractEvent(player,entity);
|
||||
return !event.isCanceled();
|
||||
|
||||
@@ -25,6 +25,9 @@ import net.minecraftforge.event.world.BlockEvent;
|
||||
import vazkii.botania.api.internal.IManaBurst;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.tile.TileIncensePlate;
|
||||
import vazkii.botania.common.core.helper.ItemHelper;
|
||||
|
||||
import static vazkii.botania.common.core.helper.ItemHelper.canPlaceBlock;
|
||||
|
||||
public class LensFire extends Lens {
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import vazkii.botania.api.internal.IManaBurst;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.tile.TileManaFlame;
|
||||
|
||||
import static vazkii.botania.common.core.helper.ItemHelper.canPlaceBlock;
|
||||
|
||||
public class LensLight extends Lens {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,6 +33,8 @@ import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
|
||||
import static vazkii.botania.common.core.helper.ItemHelper.canBreakBlock;
|
||||
|
||||
public class LensMine extends Lens {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,8 @@ import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.internal.IManaBurst;
|
||||
import vazkii.botania.common.Botania;
|
||||
|
||||
import static vazkii.botania.common.core.helper.ItemHelper.canBreakBlock;
|
||||
|
||||
public class LensPaint extends Lens {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,8 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import vazkii.botania.api.internal.IManaBurst;
|
||||
|
||||
import static vazkii.botania.common.core.helper.ItemHelper.canBreakBlock;
|
||||
|
||||
public class LensPiston extends Lens {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,8 @@ import net.minecraft.world.World;
|
||||
import vazkii.botania.api.internal.IManaBurst;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
|
||||
import static vazkii.botania.common.core.helper.ItemHelper.canBreakBlock;
|
||||
|
||||
public class LensWeight extends Lens {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,6 +39,7 @@ import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
|
||||
import vazkii.botania.common.block.BlockCamo;
|
||||
import vazkii.botania.common.core.helper.ItemHelper;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.item.ItemMod;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
@@ -46,6 +47,8 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import static vazkii.botania.common.core.helper.ItemHelper.canPlaceBlock;
|
||||
|
||||
public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWireframeCoordinateListProvider {
|
||||
|
||||
private static final int RANGE = 3;
|
||||
@@ -90,7 +93,7 @@ public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWirefra
|
||||
} else if(canExchange(par1ItemStack) && !ItemNBTHelper.getBoolean(par1ItemStack, TAG_SWAPPING, false)) {
|
||||
Block block = getBlock(par1ItemStack);
|
||||
int meta = getBlockMeta(par1ItemStack);
|
||||
List<ChunkCoordinates> swap = getBlocksToSwap(par3World, par1ItemStack, block, meta, par4, par5, par6, null, 0);
|
||||
List<ChunkCoordinates> swap = getBlocksToSwap(par3World, par1ItemStack, par2EntityPlayer, block, meta, par4, par5, par6, null, 0);
|
||||
if(swap.size() > 0) {
|
||||
ItemNBTHelper.setBoolean(par1ItemStack, TAG_SWAPPING, true);
|
||||
ItemNBTHelper.setInt(par1ItemStack, TAG_SELECT_X, par4);
|
||||
@@ -135,27 +138,35 @@ public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWirefra
|
||||
ItemNBTHelper.setBoolean(stack, TAG_SWAPPING, false);
|
||||
return;
|
||||
}
|
||||
|
||||
//block right-clicked
|
||||
int x = ItemNBTHelper.getInt(stack, TAG_SELECT_X, 0);
|
||||
int y = ItemNBTHelper.getInt(stack, TAG_SELECT_Y, 0);
|
||||
int z = ItemNBTHelper.getInt(stack, TAG_SELECT_Z, 0);
|
||||
//block that will replace.
|
||||
Block targetBlock = getTargetBlock(stack);
|
||||
int targetMeta = getTargetBlockMeta(stack);
|
||||
List<ChunkCoordinates> swap = getBlocksToSwap(world, stack, block, meta, x, y, z, targetBlock, targetMeta);
|
||||
if(swap.size() == 0) {
|
||||
//list of blocks to replace
|
||||
List<ChunkCoordinates> swap = getBlocksToSwap(world, stack,player ,block, meta, x, y, z, targetBlock, targetMeta);
|
||||
if(swap.isEmpty()) {
|
||||
ItemNBTHelper.setBoolean(stack, TAG_SWAPPING, false);
|
||||
return;
|
||||
}
|
||||
|
||||
ChunkCoordinates coords = swap.get(world.rand.nextInt(swap.size()));
|
||||
boolean exchange = exchange(world, player, coords.posX, coords.posY, coords.posZ, stack, block, meta);
|
||||
if(exchange)
|
||||
ManaItemHandler.requestManaExactForTool(stack, player, COST, true);
|
||||
else ItemNBTHelper.setBoolean(stack, TAG_SWAPPING, false);
|
||||
for(ChunkCoordinates coords: swap){
|
||||
boolean exchange = exchange(world, player, coords.posX, coords.posY, coords.posZ, stack, block, meta);
|
||||
if(exchange)
|
||||
ManaItemHandler.requestManaExactForTool(stack, player, COST, true);
|
||||
}
|
||||
ItemNBTHelper.setBoolean(stack, TAG_SWAPPING, false);
|
||||
// ChunkCoordinates coords = swap.get(world.rand.nextInt(swap.size()));
|
||||
//
|
||||
// boolean exchange = exchange(world, player, coords.posX, coords.posY, coords.posZ, stack, block, meta);
|
||||
// if(exchange)
|
||||
//
|
||||
// else
|
||||
}
|
||||
}
|
||||
|
||||
public List<ChunkCoordinates> getBlocksToSwap(World world, ItemStack stack, Block blockToSwap, int metaToSwap, int xc, int yc, int zc, Block targetBlock, int targetMeta) {
|
||||
public List<ChunkCoordinates> getBlocksToSwap(World world, ItemStack stack,EntityPlayer player, Block blockToSwap, int metaToSwap, int xc, int yc, int zc, Block targetBlock, int targetMeta) {
|
||||
// If we have no target block passed in, infer it to be
|
||||
// the block which the swapping is centered on (presumably the block
|
||||
// which the player is looking at)
|
||||
@@ -222,15 +233,17 @@ public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWirefra
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if(!blockAt.isAir(world, x, y, z) && blockAt.getPlayerRelativeBlockHardness(player, world, x, y, z) > 0 && (blockAt != blockToSet || meta != metaToSet)) {
|
||||
if(!world.isRemote) {
|
||||
if(!player.capabilities.isCreativeMode) {
|
||||
List<ItemStack> drops = blockAt.getDrops(world, x, y, z, meta, 0);
|
||||
for(ItemStack drop : drops)
|
||||
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, drop));
|
||||
removeFromInventory(player, stack, blockToSet, metaToSet, true);
|
||||
if (canPlaceBlock(world, x, y, z, x, y, z, player)) {
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
List<ItemStack> drops = blockAt.getDrops(world, x, y, z, meta, 0);
|
||||
for (ItemStack drop : drops)
|
||||
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, drop));
|
||||
removeFromInventory(player, stack, blockToSet, metaToSet, true);
|
||||
}
|
||||
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(blockAt) + (meta << 12));
|
||||
world.setBlock(x, y, z, blockToSet, metaToSet, 1 | 2);
|
||||
blockToSet.onBlockPlacedBy(world, x, y, z, player, placeStack);
|
||||
}
|
||||
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(blockAt) + (meta << 12));
|
||||
world.setBlock(x, y, z, blockToSet, metaToSet, 1 | 2);
|
||||
blockToSet.onBlockPlacedBy(world, x, y, z, player, placeStack);
|
||||
}
|
||||
displayRemainderCounter(player, stack);
|
||||
return true;
|
||||
@@ -329,8 +342,8 @@ public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWirefra
|
||||
Block block = getBlock(stack);
|
||||
int meta = getBlockMeta(stack);
|
||||
int count = getInventoryItemCount(player, stack, block, meta);
|
||||
if(!player.worldObj.isRemote)
|
||||
ItemsRemainingRenderHandler.set(new ItemStack(block, 1, meta), count);
|
||||
//if(!player.worldObj.isRemote)
|
||||
//ItemsRemainingRenderHandler.set(new ItemStack(block, 1, meta), count);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -414,7 +427,7 @@ public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWirefra
|
||||
}
|
||||
|
||||
if(!player.worldObj.isAirBlock(x, y, z)) {
|
||||
List<ChunkCoordinates> coordsList = getBlocksToSwap(player.worldObj, stack, block, meta, x, y, z, targetBlock, targetMeta);
|
||||
List<ChunkCoordinates> coordsList = getBlocksToSwap(player.worldObj, stack,player, block, meta, x, y, z, targetBlock, targetMeta);
|
||||
for(ChunkCoordinates coords : coordsList)
|
||||
if(coords.posX == x && coords.posY == y && coords.posZ == z) {
|
||||
coordsList.remove(coords);
|
||||
|
||||
@@ -25,6 +25,7 @@ import vazkii.botania.api.item.IManaProficiencyArmor;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.core.helper.ItemHelper;
|
||||
import vazkii.botania.common.item.ItemMod;
|
||||
import vazkii.botania.common.item.equipment.tool.ToolCommons;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
@@ -82,7 +83,7 @@ public class ItemSmeltRod extends ItemMod implements IManaUsingItem {
|
||||
data.progress--;
|
||||
decremented = true;
|
||||
if(data.progress <= 0) {
|
||||
if(!p.worldObj.isRemote) {
|
||||
if(!p.worldObj.isRemote && ItemHelper.canBreakBlock(p.worldObj,pos.blockX, pos.blockY, pos.blockZ,p)) {
|
||||
p.worldObj.setBlock(pos.blockX, pos.blockY, pos.blockZ, Block.getBlockFromItem(result.getItem()), result.getItemDamage(), 1 | 2);
|
||||
p.worldObj.playSoundAtEntity(p, "fire.ignite", 0.6F, 1F);
|
||||
p.worldObj.playSoundAtEntity(p, "fire.fire", 1F, 1F);
|
||||
|
||||
@@ -34,6 +34,7 @@ import vazkii.botania.api.subtile.ISpecialFlower;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.achievement.ICraftAchievement;
|
||||
import vazkii.botania.common.achievement.ModAchievements;
|
||||
import vazkii.botania.common.core.helper.ItemHelper;
|
||||
import vazkii.botania.common.item.ItemMod;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
@@ -160,7 +161,8 @@ public class ItemTerraformRod extends ItemMod implements IManaUsingItem, IBlockP
|
||||
if(par2World.isRemote || ManaItemHandler.requestManaExactForTool(par1ItemStack, par3EntityPlayer, cost, true)) {
|
||||
if(!par2World.isRemote)
|
||||
for(CoordsWithBlock block : blocks)
|
||||
par2World.setBlock(block.posX, block.posY, block.posZ, block.block);
|
||||
if(ItemHelper.canBreakBlock(par2World,block.posX, block.posY, block.posZ, par3EntityPlayer))
|
||||
par2World.setBlock(block.posX, block.posY, block.posZ, block.block);
|
||||
|
||||
if(!blocks.isEmpty()) {
|
||||
for(int i = 0; i < 10; i++)
|
||||
|
||||
Reference in new issue
Block a user