use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class SubCommandHand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
Entity e = sender.getCommandSenderEntity();
if (e instanceof EntityPlayer) {
ItemStack stack = ((EntityPlayer) e).getHeldItemMainhand();
if (stack.isEmpty()) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Empty hand!"));
return;
}
if (args.length > 0 && "ore".equalsIgnoreCase(args[0])) {
Collection<String> names = new ArrayList<>();
for (int id : OreDictionary.getOreIDs(stack)) {
String name = OreDictionary.getOreName(id);
names.add(name);
}
sender.sendMessage(new TextComponentString("Ores: [" + CommandCharset.COMMAS.join(names) + "]"));
} else if (args.length > 0 && "material".equalsIgnoreCase(args[0])) {
ItemMaterial material = ItemMaterialRegistry.INSTANCE.getMaterialIfPresent(stack);
if (material == null) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Not a material!"));
} else {
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + material.getId()));
sender.sendMessage(new TextComponentString("[" + CommandCharset.COMMAS.join(material.getTypes()) + "]"));
for (Map.Entry<String, ItemMaterial> entry : material.getRelations().entrySet()) {
sender.sendMessage(new TextComponentString("-> " + entry.getKey() + ": " + entry.getValue().getId()));
}
}
} else {
sender.sendMessage(new TextComponentString(TextFormatting.YELLOW + stack.toString() + " " + TextFormatting.GRAY + "(" + stack.getItem().getRegistryName() + ")"));
if (stack.hasTagCompound()) {
sender.sendMessage(new TextComponentString(stack.getTagCompound().toString()));
}
}
}
}
use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class ItemBlockAxle method canPlaceBlockOnSide.
@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
Block block = worldIn.getBlockState(pos).getBlock();
if (block == Blocks.SNOW_LAYER && block.isReplaceable(worldIn, pos)) {
side = EnumFacing.UP;
} else if (!block.isReplaceable(worldIn, pos)) {
pos = pos.offset(side);
}
TileEntity tile = worldIn.getTileEntity(pos.offset(side.getOpposite()));
if (tile instanceof TileAxle) {
IBlockState state = worldIn.getBlockState(pos.offset(side.getOpposite()));
if (state.getBlock() instanceof BlockAxle) {
EnumFacing.Axis axis = state.getValue(Properties.AXIS);
ItemMaterial other = ((TileAxle) tile).getMaterial();
if (axis == side.getAxis() && other == ItemMaterialRegistry.INSTANCE.getMaterial(stack.getTagCompound(), "material", "plank")) {
// pass
} else {
return false;
}
}
} else if (tile != null) {
if (tile.hasCapability(CharsetPowerMechanical.POWER_PRODUCER, side)) {
// pass
} else if (tile.hasCapability(CharsetPowerMechanical.POWER_CONSUMER, side)) {
// pass
} else {
return false;
}
} else {
return false;
}
return worldIn.mayPlace(this.block, pos, false, side, (Entity) null);
}
use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class BlockStacks method getDrops.
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, @Nullable TileEntity te, int fortune, boolean silkTouch) {
if (te instanceof TileEntityStacks) {
TObjectIntMap<ItemMaterial> materials = new TObjectIntHashMap<>();
for (ItemMaterial material : ((TileEntityStacks) te).stacks) {
materials.adjustOrPutValue(material, 1, 1);
}
for (ItemMaterial material : materials.keySet()) {
ItemStack stack = material.getStack();
if (!stack.isEmpty()) {
int count = materials.get(material);
for (int i = 0; i < count; i += stack.getMaxStackSize()) {
stack = stack.copy();
stack.setCount(Math.min(count - i, stack.getMaxStackSize()));
drops.add(stack);
}
}
}
}
}
use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class RenderTileEntityStacks method getParticleTexture.
@Override
public TextureAtlasSprite getParticleTexture(IBlockState state, @Nullable EnumFacing facing) {
TextureAtlasSprite sprite = null;
TileEntityStacks stacks = ((IExtendedBlockState) state).getValue(BlockStacks.PROPERTY_TILE);
if (stacks != null && !stacks.stacks.isEmpty()) {
ItemMaterial material = stacks.stacks.get(stacks.stacks.size() - 1);
sprite = RenderUtils.getItemSprite(material.getStack());
}
return sprite != null ? sprite : getParticleTexture();
}
use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class MaterialRegistry method registerTypes.
@ZenMethod
public static boolean registerTypes(IItemStack stack, String... tags) {
ItemStack mcStack = CraftTweakerMC.getItemStack(stack);
if (mcStack.isEmpty()) {
return false;
}
CraftTweakerAPI.apply(new IAction() {
@Override
public void apply() {
ItemMaterial material = ItemMaterialRegistry.INSTANCE.getOrCreateMaterial(mcStack);
ItemMaterialRegistry.INSTANCE.registerTypes(material, tags);
}
@Override
public String describe() {
return "Registering stack " + stack + " as material with types " + JOINER.join(tags);
}
});
return true;
}
Aggregations