backport anti-hack detection from json branch

This commit is contained in:
asiekierka 2015-10-06 14:13:17 +02:00
parent b9f16462d8
commit 4e38f7e027
2 changed files with 16 additions and 2 deletions

View file

@ -2,4 +2,5 @@ Bugs fixed:
* [#3056] PipeTransportFluids crash (asie)
* [#3055] Redstone Engines not heating up (asie)
* Builder anti-hack system bug (asie)
* Random crashes with integrated server tile entity lookup (asie)

View file

@ -12,6 +12,7 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@ -25,6 +26,7 @@ import buildcraft.api.blueprints.BuildingPermission;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicBlockBase;
import buildcraft.api.blueprints.SchematicFactory;
@ -80,7 +82,18 @@ public class BuildingSlotBlock extends BuildingSlot {
// This is also slightly hackish, but that's what you get when
// you're unable to break an API too much.
if (!getSchematic().isAlreadyBuilt(context, x, y, z)) {
return false;
if (context.world().isAirBlock(x, y, z)) {
return false;
} else if (!(getSchematic() instanceof SchematicBlock)
|| context.world().getBlock(x, y, z).isAssociatedBlock(((SchematicBlock) getSchematic()).block)) {
BCLog.logger.warn("Placed block does not match expectations! Most likely a bug in BuildCraft or a supported mod. Removed mismatched block.");
BCLog.logger.warn("Location: " + x + ", " + y + ", " + z + " - Block: " + Block.blockRegistry.getNameForObject(context.world().getBlock(x, y, z)) + "@" + context.world().getBlockMetadata(x, y, z));
context.world().removeTileEntity(x, y, z);
context.world().setBlockToAir(x, y, z);
return true;
} else {
return false;
}
}
// This is slightly hackish, but it's a very important way to verify
@ -107,7 +120,7 @@ public class BuildingSlotBlock extends BuildingSlot {
BCLog.logger.warn("Location: " + x + ", " + y + ", " + z + " - ItemStack: " + s.toString());
context.world().removeTileEntity(x, y, z);
context.world().setBlockToAir(x, y, z);
return false;
return true;
}
}
// Restore the stored requirements.