public static Property<?> adaptProperty(IProperty<?> property) { if (property instanceof PropertyBool) { return new BooleanProperty(property.getName(), ImmutableList.copyOf(((PropertyBool) property).getAllowedValues())); } if (property instanceof PropertyInteger) { return new IntegerProperty(property.getName(), ImmutableList.copyOf(((PropertyInteger) property).getAllowedValues())); } if (property instanceof PropertyDirection) { return new DirectionalProperty(property.getName(), ((PropertyDirection) property).getAllowedValues().stream() .map(ForgeAdapter::adaptEnumFacing) .collect(Collectors.toList())); } if (property instanceof PropertyEnum) { return new EnumProperty(property.getName(), ((PropertyEnum<?>) property).getAllowedValues().stream() .map(e -> e.getName()) .collect(Collectors.toList())); } return new IPropertyAdapter<>(property); }
@Override public boolean canPlaceBlockAt(World worldIn, BlockPos pos){ for(EnumFacing enumfacing : BlockTorch.FACING.getAllowedValues()){ if(this.canPlaceAt(worldIn, pos, enumfacing)){ return true; } } return false; }
@Nonnull @Override public Map<IBlockState, ModelResourceLocation> getStateModelLocations() { Map<IBlockState, ModelResourceLocation> locationMap = new HashMap<>(); for (EnumFacing facing : FACING.getAllowedValues()) { locationMap.put(getDefaultState().withProperty(FACING, facing), new ModelResourceLocation(getRegistryName(), "facing=" + facing.getName())); } return locationMap; } }
@SideOnly(Side.CLIENT) @SubscribeEvent public void onModelBakeEvent(ModelBakeEvent event) { for (EnumFacing facing : DisplayStand.FACING.getAllowedValues()) { for (Boolean axisX : DisplayStand.AXIS_X.getAllowedValues()) { String blockVariant = String.format("%s=%s,%s=%s", DisplayStand.AXIS_X.getName(), DisplayStand.AXIS_X.getName(axisX), DisplayStand.FACING.getName(), DisplayStand.FACING.getName(facing)); bakeVariantModel(event, blockVariant, !axisX); } } bakeVariantModel(event, "inventory", false); }
@Override public void neighborChanged(final IBlockState state, final World worldIn, final BlockPos pos, final Block blockIn, final BlockPos fromPos) { if (state.getBlock() instanceof BlockMinecoloniesRack) { final TileEntity rack = worldIn.getTileEntity(pos); for (final EnumFacing offsetFacing : BlockHorizontal.FACING.getAllowedValues()) { final BlockPos neighbor = pos.offset(offsetFacing); final Block block = worldIn.getBlockState(neighbor).getBlock(); if (rack instanceof TileEntityRack && pos.getY() == neighbor.getY() && !pos.equals(neighbor) && !pos.equals(BlockPos.ORIGIN) && (block instanceof BlockMinecoloniesRack || blockIn instanceof BlockMinecoloniesRack)) { ((TileEntityRack) rack).neighborChanged(neighbor); } } } super.neighborChanged(state, worldIn, pos, blockIn, fromPos); }
@Override protected void processImpact(RayTraceResult mop) { if (mop.entityHit != null) { //zero damage means just knockback mop.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0); } EnumFacing sideHit = mop.sideHit; BlockPos pos = mop.getBlockPos(); BlockPos offset = mop.getBlockPos(); if (sideHit != null) { offset = pos.offset(sideHit); } if (offset == null) { return; } World world = this.getEntityWorld(); boolean isSideSolid = world.isSideSolid(mop.getBlockPos(), sideHit); boolean isValidBlockstate = BlockTorch.FACING.getAllowedValues().contains(sideHit); boolean isValidLocation = world.isAirBlock(offset) || world.getBlockState(offset) == null || world.getBlockState(offset).getBlock() == null || world.getBlockState(offset).getBlock().isReplaceable(world, offset); if (isValidLocation && isValidBlockstate && isSideSolid && world.isRemote == false) { world.setBlockState(offset, Blocks.TORCH.getDefaultState().withProperty(BlockTorch.FACING, sideHit)); } else { UtilItemStack.dropItemStackInWorld(world, this.getPosition(), this.fromLauncher ? Item.getItemFromBlock(Blocks.TORCH) : item); } this.setDead(); }
EnumFacing facing = state.getValue(propDir); EnumFacing newFacing = transform(facing, frontVec, topVec, perpVec); if (propDir.getAllowedValues().contains(newFacing)) { state = state.withProperty(propDir, newFacing);