Reimplement stencil as meta-item

master
Bartek Bok 2016-01-17 15:36:16 +01:00
parent 8bbe9b97fc
commit 9ae744188b
7 changed files with 35 additions and 35 deletions

View File

@ -592,6 +592,9 @@ public class Config {
}
if (OpenBlocks.Items.stencil != null) {
for (Stencil stencil : Stencil.VALUES)
OpenBlocks.Items.stencil.registerItem(stencil.ordinal(), new MetaStencil(stencil));
if (stencilLoot) {
for (Stencil stencil : Stencil.values()) {
WeightedRandomChestContent drop = new WeightedRandomChestContent(new ItemStack(OpenBlocks.Items.stencil, 1, stencil.ordinal()), 1, 1, 2);

View File

@ -252,7 +252,7 @@ public class OpenBlocks {
public static ItemPaintBrush paintBrush;
@RegisterItem(name = "stencil", registerDefaultModel = false)
public static ItemStencil stencil;
public static ItemOBGeneric stencil;
@RegisterItem(name = "squeegee")
public static ItemSqueegee squeegee;

View File

@ -21,14 +21,14 @@ public enum Stencil {
MUSIC("music"),
BALLOON("balloon");
public final String iconName;
public final String name;
public final ResourceLocation blockIcon;
public final ResourceLocation coverBlockIcon;
private Stencil(String iconName) {
this.iconName = iconName;
this.blockIcon = OpenBlocks.location("stencil_" + iconName);
this.coverBlockIcon = OpenBlocks.location("openblocks:stencilcover_" + iconName);
private Stencil(String name) {
this.name = name;
this.blockIcon = OpenBlocks.location("stencil_" + name);
this.coverBlockIcon = OpenBlocks.location("openblocks:stencilcover_" + name);
}
public static final Stencil[] VALUES = values();

View File

@ -110,12 +110,10 @@ public class ItemImaginationGlasses extends ItemArmor {
}
};
public final String textureName;
private Type(String name) {
this.textureName = "openblocks:textures/models/glasses_" + name
+ ".png";
this.textureName = "openblocks:textures/models/glasses_" + name + ".png";
}
protected abstract boolean checkBlock(Property property, ItemStack stack, TileEntityImaginary te);

View File

@ -1,10 +1,6 @@
package openblocks.common.item;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
@ -15,43 +11,29 @@ import openblocks.common.block.BlockCanvas;
import openblocks.common.tileentity.TileEntityCanvas;
import openmods.utils.render.PaintUtils;
public class ItemStencil extends Item {
public class MetaStencil extends MetaGeneric {
public ItemStencil() {
setHasSubtypes(true);
}
private final Stencil stencil;
@Override
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list) {
for (Stencil stencil : Stencil.values()) {
list.add(new ItemStack(item, 1, stencil.ordinal()));
}
public MetaStencil(Stencil stencil) {
super(stencil.name);
this.stencil = stencil;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
if (PaintUtils.instance.isAllowedToReplace(world, pos)) {
BlockCanvas.replaceBlock(world, pos);
}
TileEntity te = world.getTileEntity(pos);
final TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityCanvas) {
TileEntityCanvas canvas = (TileEntityCanvas)te;
int stencilId = stack.getItemDamage();
Stencil stencil;
try {
stencil = Stencil.VALUES[stencilId];
} catch (ArrayIndexOutOfBoundsException e) {
return false;
}
if (canvas.useStencil(side, stencil)) stack.stackSize--;
return true;
}
return false;
}
}

View File

@ -16,7 +16,6 @@ import openblocks.OpenBlocks;
import openblocks.common.Stencil;
import openblocks.common.item.ItemPaintBrush;
import openblocks.common.item.ItemSqueegee;
import openblocks.common.item.ItemStencil;
import openblocks.common.sync.SyncableBlockLayers;
import openblocks.common.sync.SyncableBlockLayers.Layer;
import openmods.api.IActivateAwareTile;
@ -216,7 +215,7 @@ public class TileEntityCanvas extends SyncedTileEntity implements IActivateAware
ItemStack held = player.getHeldItem();
if (held != null) {
Item heldItem = held.getItem();
if (heldItem instanceof ItemSqueegee || heldItem instanceof ItemPaintBrush || heldItem instanceof ItemStencil) return false;
if (heldItem instanceof ItemSqueegee || heldItem instanceof ItemPaintBrush || heldItem == OpenBlocks.Items.stencil) return false;
}
SyncableBlockLayers layer = getLayersForSide(side);

View File

@ -0,0 +1,18 @@
{
"parent" : "builtin/generated",
"textures" : {
"layer0" : "openblocks:blocks/stencilcover_music"
},
"display" : {
"thirdperson" : {
"rotation" : [ -90, 0, 0 ],
"translation" : [ 0, 1, -3 ],
"scale" : [ 0.55, 0.55, 0.55 ]
},
"firstperson" : {
"rotation" : [ 0, -135, 25 ],
"translation" : [ 0, 4, 2 ],
"scale" : [ 1.7, 1.7, 1.7 ]
}
}
}