use of net.minecraft.block.properties.IProperty in project SecurityCraft by Geforce132.
the class ItemBlockReinforcedSlabs method canPlaceBlockOnSide.
@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
BlockPos blockpos1 = pos;
IProperty iproperty = singleSlab.getVariantProperty();
Object object = singleSlab.getVariant(stack);
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == singleSlab) {
boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty))
return true;
}
pos = pos.offset(side);
IBlockState iblockstate1 = worldIn.getBlockState(pos);
return iblockstate1.getBlock() == singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack);
}
use of net.minecraft.block.properties.IProperty in project SecurityCraft by Geforce132.
the class ItemBlockReinforcedWoodSlabs method canPlaceBlockOnSide.
@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
BlockPos blockpos1 = pos;
IProperty iproperty = singleSlab.getVariantProperty();
Object object = singleSlab.getVariant(stack);
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == singleSlab) {
boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty))
return true;
}
pos = pos.offset(side);
IBlockState iblockstate1 = worldIn.getBlockState(pos);
return iblockstate1.getBlock() == singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack);
}
use of net.minecraft.block.properties.IProperty in project SpongeCommon by SpongePowered.
the class MixinStateImplementation method generateId.
@Override
public void generateId(Block block) {
StringBuilder builder = new StringBuilder();
builder.append(((BlockType) block).getId());
if (!this.properties.isEmpty()) {
builder.append('[');
Joiner joiner = Joiner.on(',');
List<String> propertyValues = new ArrayList<>();
for (Map.Entry<IProperty<?>, Comparable<?>> entry : this.properties.entrySet()) {
propertyValues.add(entry.getKey().getName() + "=" + entry.getValue());
}
builder.append(joiner.join(propertyValues));
builder.append(']');
}
this.id = builder.toString();
}
use of net.minecraft.block.properties.IProperty in project SpongeCommon by SpongePowered.
the class BlockPropertyIdProvider method getIdAndTryRegistration.
public static String getIdAndTryRegistration(IProperty<?> property, Block block, String blockId) {
BlockPropertyIdProvider instance = getInstance();
checkNotNull(property, "Property is null! Cannot retrieve a registration for a null property!");
checkNotNull(block, "Block cannot be null!");
checkNotNull(blockId, "Block id cannot be null!");
checkArgument(!blockId.isEmpty(), "Block id cannot be empty!");
if (instance.isRegistered(property)) {
return instance.propertyIdMap.get(property);
}
final String lowerCasedBlockId = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, blockId);
final String modId = lowerCasedBlockId.split(":")[0];
final String propertyName = property.getName();
final String lastAttemptId = lowerCasedBlockId + "_" + property.getName();
try {
// Seriously, don't look past this try state. just continue on with your day...
// I warned you...
final String originalClass = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, block.getClass().getSimpleName());
Class<?> blockClass = block.getClass();
while (true) {
if (blockClass == Object.class) {
final String propertyId = modId + ":" + originalClass + "_" + property.getName();
LogManager.getLogger("Sponge").warn("Could not find {} owning class, assigning fallback id: {}", property.getName(), propertyId);
instance.register(property, propertyId);
return propertyId;
}
// Had enough?
for (Field field : blockClass.getDeclaredFields()) {
field.setAccessible(true);
final boolean isStatic = Modifier.isStatic(field.getModifiers());
final Object o = isStatic ? field.get(null) : field.get(block);
if (property != o) {
continue;
}
final String className = field.getDeclaringClass().getSimpleName().replace("Block", "").replace("block", "");
final String classNameId = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, className);
final String propertyClassName = isStatic ? classNameId : originalClass;
final String combinedId = modId + ":" + propertyClassName + "_" + propertyName.toLowerCase(Locale.ENGLISH);
if (instance.idPropertyMap.containsKey(combinedId)) {
// in this case, we really do have to fall back on the full block id...
if (instance.idPropertyMap.containsKey(lastAttemptId)) {
// we really are screwed...
throw new IllegalArgumentException("Sorry! Someone is trying to re-register a block with the same property instances of" + "block: " + blockId + " , with property: " + propertyName);
}
instance.register((IProperty<?>) o, lastAttemptId);
return lastAttemptId;
}
instance.register(((IProperty<?>) o), combinedId);
return combinedId;
}
blockClass = blockClass.getSuperclass();
}
} catch (Exception e) {
LogManager.getLogger("Sponge").warn("An exception was thrown while trying to resolve the property " + property.getName() + "'s owning class, assigning " + "fallback id: " + lastAttemptId, e);
instance.register(property, lastAttemptId);
return lastAttemptId;
}
}
use of net.minecraft.block.properties.IProperty in project MorePlanets by SteveKunG.
the class ItemBlockSlabMP method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack itemStack = player.getHeldItem(hand);
if (this.block instanceof ISlabBlock) {
ISlabBlock singleSlab = (ISlabBlock) this.block;
if (itemStack.getCount() != 0 && player.canPlayerEdit(pos.offset(facing), facing, itemStack)) {
Object object = singleSlab.getHalf().getTypeForItem(itemStack);
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == singleSlab.getHalf()) {
IProperty iproperty = singleSlab.getHalf().getVariantProperty();
Comparable comparable = state.getValue(iproperty);
EnumBlockHalf enumblockhalf = state.getValue(BlockSlab.HALF);
if ((facing == EnumFacing.UP && enumblockhalf == EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && enumblockhalf == BlockSlab.EnumBlockHalf.TOP) && comparable == object) {
IBlockState state1 = singleSlab.getDouble().getDefaultState().withProperty(iproperty, comparable);
AxisAlignedBB axisalignedbb = state1.getCollisionBoundingBox(world, pos);
if (axisalignedbb != Block.NULL_AABB && world.checkNoEntityCollision(axisalignedbb.offset(pos)) && world.setBlockState(pos, state1, 11)) {
SoundType sound = singleSlab.getDouble().getSoundType(state1, world, pos, player);
world.playSound(player, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1.0F) / 2.0F, sound.getPitch() * 0.8F);
itemStack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
}
return this.tryPlace(player, itemStack, world, pos.offset(facing), object, singleSlab.getHalf(), singleSlab.getDouble()) ? EnumActionResult.SUCCESS : super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
} else {
return EnumActionResult.FAIL;
}
return EnumActionResult.FAIL;
}
Aggregations