added building permissions, close #1509
This commit is contained in:
parent
f38dc134c2
commit
920be38a5f
11 changed files with 148 additions and 0 deletions
38
api/buildcraft/api/blueprints/BuildingPermission.java
Executable file
38
api/buildcraft/api/blueprints/BuildingPermission.java
Executable file
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
package buildcraft.api.blueprints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schematics recorded in the blueprints can restrict situations where a
|
||||||
|
* blueprint can be used. A same schematic class can have different
|
||||||
|
* permissions depending on its contents. It's particularly useful when
|
||||||
|
* fixing a schematic, if blueprints that saved the previous version should
|
||||||
|
* not be built because of a bug (such as dupe bug on inventories).
|
||||||
|
*/
|
||||||
|
public enum BuildingPermission {
|
||||||
|
/**
|
||||||
|
* No restrictions, blueprints using this schematic are good in all
|
||||||
|
* contexts.
|
||||||
|
*/
|
||||||
|
ALL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This blueprints containing this schematic can only be used in
|
||||||
|
* creative. Maybe the block can't be crafted in survival in the first
|
||||||
|
* place, or the content of the schematic is known to have dupe bugs.
|
||||||
|
*/
|
||||||
|
CREATIVE_ONLY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blueprints containing this schematic should not be built. This is
|
||||||
|
* typically used when a critical problems have been fixed, but older
|
||||||
|
* versions of the schematic are too badly broken to be retreived.
|
||||||
|
*/
|
||||||
|
NONE,
|
||||||
|
}
|
|
@ -261,4 +261,12 @@ public abstract class Schematic {
|
||||||
public BuildingStage getBuildStage () {
|
public BuildingStage getBuildStage () {
|
||||||
return BuildingStage.STANDALONE;
|
return BuildingStage.STANDALONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the building permission for blueprint containing this schematic.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BuildingPermission getBuildingPermission () {
|
||||||
|
return BuildingPermission.ALL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ public abstract class SchematicBlockBase extends Schematic {
|
||||||
/**
|
/**
|
||||||
* Return true if the block should not be placed to the world. Requirements
|
* Return true if the block should not be placed to the world. Requirements
|
||||||
* will not be asked on such a block, and building will not be called.
|
* will not be asked on such a block, and building will not be called.
|
||||||
|
* Post processing will still be called on these blocks though.
|
||||||
*/
|
*/
|
||||||
public boolean doNotBuild() {
|
public boolean doNotBuild() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -133,6 +133,8 @@ item.blueprintItem.name=Blueprint
|
||||||
item.blueprint.unnamed=<unnamed>
|
item.blueprint.unnamed=<unnamed>
|
||||||
item.blueprint.author=by
|
item.blueprint.author=by
|
||||||
item.blueprint.blank=Blank
|
item.blueprint.blank=Blank
|
||||||
|
item.blueprint.creative_only=Creative Only
|
||||||
|
item.blueprint.no_build=No Building
|
||||||
item.PipeItemsWood.name=Wooden Transport Pipe
|
item.PipeItemsWood.name=Wooden Transport Pipe
|
||||||
item.PipeItemsCobblestone.name=Cobblestone Transport Pipe
|
item.PipeItemsCobblestone.name=Cobblestone Transport Pipe
|
||||||
item.PipeItemsStone.name=Stone Transport Pipe
|
item.PipeItemsStone.name=Stone Transport Pipe
|
||||||
|
|
|
@ -67,6 +67,7 @@ import buildcraft.builders.filler.pattern.PatternHorizon;
|
||||||
import buildcraft.builders.filler.pattern.PatternPyramid;
|
import buildcraft.builders.filler.pattern.PatternPyramid;
|
||||||
import buildcraft.builders.filler.pattern.PatternStairs;
|
import buildcraft.builders.filler.pattern.PatternStairs;
|
||||||
import buildcraft.builders.schematics.SchematicBed;
|
import buildcraft.builders.schematics.SchematicBed;
|
||||||
|
import buildcraft.builders.schematics.SchematicBlockCreative;
|
||||||
import buildcraft.builders.schematics.SchematicCactus;
|
import buildcraft.builders.schematics.SchematicCactus;
|
||||||
import buildcraft.builders.schematics.SchematicCustomStack;
|
import buildcraft.builders.schematics.SchematicCustomStack;
|
||||||
import buildcraft.builders.schematics.SchematicDirt;
|
import buildcraft.builders.schematics.SchematicDirt;
|
||||||
|
@ -93,6 +94,7 @@ import buildcraft.builders.schematics.SchematicSign;
|
||||||
import buildcraft.builders.schematics.SchematicSkull;
|
import buildcraft.builders.schematics.SchematicSkull;
|
||||||
import buildcraft.builders.schematics.SchematicStairs;
|
import buildcraft.builders.schematics.SchematicStairs;
|
||||||
import buildcraft.builders.schematics.SchematicStone;
|
import buildcraft.builders.schematics.SchematicStone;
|
||||||
|
import buildcraft.builders.schematics.SchematicTileCreative;
|
||||||
import buildcraft.builders.schematics.SchematicTripWireHook;
|
import buildcraft.builders.schematics.SchematicTripWireHook;
|
||||||
import buildcraft.builders.schematics.SchematicWallSide;
|
import buildcraft.builders.schematics.SchematicWallSide;
|
||||||
import buildcraft.builders.triggers.ActionFiller;
|
import buildcraft.builders.triggers.ActionFiller;
|
||||||
|
@ -279,6 +281,10 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
||||||
|
|
||||||
SchematicRegistry.registerSchematicBlock(Blocks.fire, SchematicFire.class);
|
SchematicRegistry.registerSchematicBlock(Blocks.fire, SchematicFire.class);
|
||||||
|
|
||||||
|
SchematicRegistry.registerSchematicBlock(Blocks.bedrock, SchematicBlockCreative.class);
|
||||||
|
|
||||||
|
SchematicRegistry.registerSchematicBlock(Blocks.mob_spawner, SchematicTileCreative.class);
|
||||||
|
|
||||||
// Standard entities
|
// Standard entities
|
||||||
|
|
||||||
SchematicRegistry.registerSchematicEntity(EntityMinecartEmpty.class, SchematicMinecart.class, Items.minecart);
|
SchematicRegistry.registerSchematicEntity(EntityMinecartEmpty.class, SchematicMinecart.class, Items.minecart);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
|
import buildcraft.api.blueprints.BuildingPermission;
|
||||||
import buildcraft.builders.blueprints.BlueprintId;
|
import buildcraft.builders.blueprints.BlueprintId;
|
||||||
import buildcraft.core.CreativeTabBuildCraft;
|
import buildcraft.core.CreativeTabBuildCraft;
|
||||||
import buildcraft.core.ItemBuildCraft;
|
import buildcraft.core.ItemBuildCraft;
|
||||||
|
@ -46,6 +47,19 @@ public abstract class ItemBlueprint extends ItemBuildCraft {
|
||||||
} else {
|
} else {
|
||||||
list.add(StringUtils.localize("item.blueprint.blank"));
|
list.add(StringUtils.localize("item.blueprint.blank"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (NBTUtils.getItemData(stack).hasKey("permission")) {
|
||||||
|
BuildingPermission p = BuildingPermission.values()[NBTUtils
|
||||||
|
.getItemData(stack).getByte("permission")];
|
||||||
|
|
||||||
|
if (p == BuildingPermission.CREATIVE_ONLY) {
|
||||||
|
list.add(String.format(StringUtils
|
||||||
|
.localize("item.blueprint.creative_only")));
|
||||||
|
} else if (p == BuildingPermission.NONE) {
|
||||||
|
list.add(String.format(StringUtils
|
||||||
|
.localize("item.blueprint.no_build")));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlueprintId getId (ItemStack stack) {
|
public static BlueprintId getId (ItemStack stack) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraft.world.WorldSettings.GameType;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
|
import buildcraft.api.blueprints.BuildingPermission;
|
||||||
import buildcraft.api.blueprints.Translation;
|
import buildcraft.api.blueprints.Translation;
|
||||||
import buildcraft.api.core.NetworkData;
|
import buildcraft.api.core.NetworkData;
|
||||||
import buildcraft.api.core.Position;
|
import buildcraft.api.core.Position;
|
||||||
|
@ -287,6 +288,12 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bpt.buildingPermission == BuildingPermission.NONE
|
||||||
|
|| (bpt.buildingPermission == BuildingPermission.CREATIVE_ONLY && worldObj
|
||||||
|
.getWorldInfo().getGameType() != GameType.CREATIVE)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
BptContext context = bpt.getContext(worldObj, bpt.getBoxForPos(x, y, z));
|
BptContext context = bpt.getContext(worldObj, bpt.getBoxForPos(x, y, z));
|
||||||
|
|
||||||
if (bpt.rotate) {
|
if (bpt.rotate) {
|
||||||
|
|
21
common/buildcraft/builders/schematics/SchematicBlockCreative.java
Executable file
21
common/buildcraft/builders/schematics/SchematicBlockCreative.java
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
package buildcraft.builders.schematics;
|
||||||
|
|
||||||
|
import buildcraft.api.blueprints.BuildingPermission;
|
||||||
|
import buildcraft.api.blueprints.SchematicBlock;
|
||||||
|
|
||||||
|
public class SchematicBlockCreative extends SchematicBlock {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BuildingPermission getBuildingPermission () {
|
||||||
|
return BuildingPermission.CREATIVE_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
common/buildcraft/builders/schematics/SchematicTileCreative.java
Executable file
21
common/buildcraft/builders/schematics/SchematicTileCreative.java
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
package buildcraft.builders.schematics;
|
||||||
|
|
||||||
|
import buildcraft.api.blueprints.BuildingPermission;
|
||||||
|
import buildcraft.api.blueprints.SchematicTile;
|
||||||
|
|
||||||
|
public class SchematicTileCreative extends SchematicTile {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BuildingPermission getBuildingPermission () {
|
||||||
|
return BuildingPermission.CREATIVE_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
|
import buildcraft.api.blueprints.BuildingPermission;
|
||||||
import buildcraft.api.blueprints.IBuilderContext;
|
import buildcraft.api.blueprints.IBuilderContext;
|
||||||
import buildcraft.api.blueprints.SchematicBlock;
|
import buildcraft.api.blueprints.SchematicBlock;
|
||||||
import buildcraft.api.blueprints.SchematicEntity;
|
import buildcraft.api.blueprints.SchematicEntity;
|
||||||
|
@ -99,6 +100,19 @@ public class Blueprint extends BlueprintBase {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
BCLog.logger.throwing("BptBlueprint", "readFromWorld", t);
|
BCLog.logger.throwing("BptBlueprint", "readFromWorld", t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (slot.getBuildingPermission()) {
|
||||||
|
case ALL:
|
||||||
|
break;
|
||||||
|
case CREATIVE_ONLY:
|
||||||
|
if (buildingPermission == BuildingPermission.ALL) {
|
||||||
|
buildingPermission = BuildingPermission.CREATIVE_ONLY;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NONE:
|
||||||
|
buildingPermission = BuildingPermission.NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -179,6 +193,19 @@ public class Blueprint extends BlueprintBase {
|
||||||
|
|
||||||
contents[x][y][z] = SchematicRegistry.newSchematicBlock(mapping.getBlockForId(blockId));
|
contents[x][y][z] = SchematicRegistry.newSchematicBlock(mapping.getBlockForId(blockId));
|
||||||
contents[x][y][z].readFromNBT(cpt, mapping);
|
contents[x][y][z].readFromNBT(cpt, mapping);
|
||||||
|
|
||||||
|
switch (contents[x][y][z].getBuildingPermission()) {
|
||||||
|
case ALL:
|
||||||
|
break;
|
||||||
|
case CREATIVE_ONLY:
|
||||||
|
if (buildingPermission == BuildingPermission.ALL) {
|
||||||
|
buildingPermission = BuildingPermission.CREATIVE_ONLY;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NONE:
|
||||||
|
buildingPermission = BuildingPermission.NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contents[x][y][z] = null;
|
contents[x][y][z] = null;
|
||||||
}
|
}
|
||||||
|
@ -208,6 +235,7 @@ public class Blueprint extends BlueprintBase {
|
||||||
id.write (nbt);
|
id.write (nbt);
|
||||||
nbt.setString("author", author);
|
nbt.setString("author", author);
|
||||||
nbt.setString("name", id.name);
|
nbt.setString("name", id.name);
|
||||||
|
nbt.setByte ("permission", (byte) buildingPermission.ordinal());
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.nbt.CompressedStreamTools;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import buildcraft.api.blueprints.BuildingPermission;
|
||||||
import buildcraft.api.blueprints.IBuilderContext;
|
import buildcraft.api.blueprints.IBuilderContext;
|
||||||
import buildcraft.api.blueprints.MappingRegistry;
|
import buildcraft.api.blueprints.MappingRegistry;
|
||||||
import buildcraft.api.blueprints.SchematicBlockBase;
|
import buildcraft.api.blueprints.SchematicBlockBase;
|
||||||
|
@ -35,6 +36,7 @@ public abstract class BlueprintBase {
|
||||||
protected MappingRegistry mapping = new MappingRegistry();
|
protected MappingRegistry mapping = new MappingRegistry();
|
||||||
public boolean rotate = true;
|
public boolean rotate = true;
|
||||||
public boolean excavate = true;
|
public boolean excavate = true;
|
||||||
|
public BuildingPermission buildingPermission = BuildingPermission.ALL;
|
||||||
|
|
||||||
private byte [] data;
|
private byte [] data;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue